In this blog, we will learn how to create below resources using AWS CLI
- Create a key pair
- Create a security group
- Launch an instance using the above created key pair and security group.
- Create an EBS volume of 1 GB.
- The final step is to attach the above created EBS volume to the instance you created in the previous steps.
First we have to create an IAM User.
So Amazon has IAM (Identity and Access Management) service where we can create user and can give limited access to that user.
Step 1: To give user name and here in AWS Access type give programmatic access so that it enables access key & secret key for AWS CLI.
Step 2: Give permissions to that user.
What are Permissions?
Permissions enable you to perform actions on AWS resources. When a new user or group is created, it has no permissions and a policy must be attached to allow actions to be taken on AWS resources.
You can assign permissions to all AWS identities (users, groups, and roles). Permissions are assigned in the following two ways:
Identity-based: Policies attached directly to users, groups, or roles
Resource-based: Policies attached to AWS resources, such as S3 Buckets, ECR Repositories, and more
Step 3: Now AWS, will generate Access Key & Secret Key for that user. We have to use this Access Key & Secret Key (save these) to login into our AWS CLI and then click create and here you can see IAM user is created.
Install AWS CLI: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
Now in Windows Command Prompt, there’s a command aws configure
to login with aws cli user created above.
🧩 Command syntax is :
aws <command> <subcommand> <options>
Now, firstly we have to create our own key pair for that we take help of AWS so here to take help we write :
aws ec2 help
: This gives all the commands available in ec2.
Now, here to create new key pair you can see subcommand:
Now, we can create new key pair by command:
aws ec2 create-key-pair — key-name TaskKeyPair
Now, we can create new security group by command:
aws ec2 create-security-group — group-name TaskSG — description “Task Security Group”
By using this newly created key pair & security group we have to launch new instance:
aws run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro — subnet-id subnet-37666f5f — count 1 — security-group-ids sg-082e7e59275801fcd — key-name TaskKeyPair
You can see the created instance using CLI OR GUI:
We have to create an EBS volume of 1 GB.
aws ec2 create-volume — volume-type gp2 — size 1 — availability-zone ap-south-1a
Now, finally we have attach the Volume to the instance that we created now. we can attach the volume by following command:
aws ec2 attach-volume — volume-id vol-0522f336c28172eb1 — instance-id i-07345102940d94e27 — device /dev/sdf
Device name can be “sdf or svdh”
You can see Volume of 1 GB is in use.
You can find me here:
Top comments (0)