DEV Community

Cover image for Let's work with AWS CLI
Vrukshali Torawane
Vrukshali Torawane

Posted on

Let's work with AWS CLI

In this blog, we will learn how to create below resources using AWS CLI

  1. Create a key pair
  2. Create a security group
  3. Launch an instance using the above created key pair and security group.
  4. Create an EBS volume of 1 GB.
  5. 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.

create user

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.

IAM User 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.

Here, provide the access key & secret key to login

🧩 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.

ec2 help command

Now, here to create new key pair you can see subcommand:

Create new key pair subcommand

Now, we can create new key pair by command:

aws ec2 create-key-pair — key-name TaskKeyPair
Enter fullscreen mode Exit fullscreen mode

create new key pair

Now, we can create new security group by command:

aws ec2 create-security-group — group-name TaskSG — description “Task Security Group”
Enter fullscreen mode Exit fullscreen mode

create new 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
Enter fullscreen mode Exit fullscreen mode

launch new instance

You can see the created instance using CLI OR GUI:

CLI

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
Enter fullscreen mode Exit fullscreen mode

EBS volume CLI

GUI

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
Enter fullscreen mode Exit fullscreen mode

Device name can be “sdf or svdh”

attach the volume CLI

attach the volume GUI

You can see Volume of 1 GB is in use.

You can find me here:

Vrukshali Torawane

☕️➡️👩🏻‍💻 • backend engineer • travel • calligraphy • aws community builder

favicon vrukshali.bio.link

Top comments (0)