AWS CLI [A Start-up Guide]
What is AWS CLI?
AWS CLI is a Command Line Interface program for working with Amazon Web Services cloud without using the Web UI. AWS CLI is a potent tool that helps in managing & automating multiple services provided by AWS. Below given the steps can be reproduced to set-up an EC2 instance and attach external storage to it.
Setting up an EC2 Instance:
Create a user and install the AWS CLI program: Before getting started with AWS CLI, we need to create an IAM user with administrator access. Once the creation of a new user is complete, note down the Access key ID and Secret access key.
Installation:
Now, we need to install the AWS CLI program for our OS from this link and verify the installation using the command.
aws - version
Let us start with the AWS CLI for setting up an EC2 Instance.
- Using the credentials of previously created IAM user, we will log-in to AWS from the CLI.
aws configure - profile <profile_name>
2. So now we are logged into the AWS cloud. Next, we will create a key-pair and save it in the file <key_name>.pem to use it with our EC2 Instance.
aws ec2 create-key-pair - key-name <key_name> query 'KeyMaterial' - output text - profile <profile_name>| out-file -encoding ascii -filepath aws.pem
We can use the below command to view the created key-pair.
aws ec2 describe-key-pairs - key-name <key_name> - profile <profile_name>
3. Next, we need to create security groups.
aws ec2 create-security-group - description <description> - group-name <group_name> - profile <profile_name>
Now, we need to set the inbound rules for newly created security groups.
aws ec2 authorize-security-group-ingress - group-name <group_name> - protocol <protocol> - port <port> - cidr <CIDR> - profile <profile_name>
We can verify the newly created security groups.
aws ec2 describe-security-groups - group-ids <group-id> - group-names <group_name> - profile <profile_name>
4. So, we are all set to launch a new EC2 Instance from the command line.
aws ec2 run-instances - image-id <AMI-id> - instance-type <instance_type> - count <count> - security-group-ids <security_group_id> - subnet-id <subnet_id> - key-name <key_name> - profile <profile_name>
We have successfully launched an EC2 Instance using the command line!
Thank you for reading my article! 😊