AWS with CLI

AWS Logo

Amazon Web Services(AWS) is a cloud service from Amazon, which provides services in the form of building blocks, these building blocks can be used to create and deploy any type of application in the cloud.

AWS CLI

AWS Command Line Interface(AWS CLI) is an open source tool that enables you to interact with AWS services using commands in your command-line shell. With minimal configuration, the AWS CLI enables you to start running commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from the command prompt in your terminal program.

Task- Description

  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.

Environment setup for task

Step 1: Download and install AWS-CLI

For download AWS-CLI software please refer to this website. After installing we can check it using following command

aws --version
Verifying Installation

Step 2: Configure AWS-CLI

Now, after successfully installing, we have to configure AWS-CLI with AWS IAM user credentials.

aws configure
Configuring AWS-cli

Now, moving forward to implement task.

Step 1: Create a key pair

A key pair, consisting, is a set of security credentials that you use to prove your identity when connecting to an EC2 instance. Command to create key-pair is as follows.

aws ec2 create-key-pair --key-name <KeyName>
Creating key pair
Verifying using AWS web-console

Step 2: Create a security group

A security group acts as a virtual firewall for your EC2 instances to control incoming and outgoing traffic. Inbound and outbound rules control the incoming(to instance) and outgoing(from instance) traffic respectively.

Command to create security group.

aws ec2 create-security-group --description <GroupDescription> --group-name <GroupName>
Creating security group
Verifying using AWS web-console

Step 3: Launch an ec2-instance using the above created key pair and security group.

An Amazon EC2 instance is a virtual server in Amazon’s Elastic Compute Cloud (EC2) for running applications on the Amazon Web Services (AWS) infrastructure.

Command to launch instance.

aws ec2 run-instances --image-id <Image-id> --instance-type <InstanceType> --security-group-ids <SecurityGroup-id> --key-name <Key-pairName>
Creating ec2-instance
Verifying using AWS web-console

Step 4: Create an EBS volume of 1 GB.

An Amazon EBS volume is a durable, block-level storage device that you can attach to your instances.

aws ec2 create-volume --availablity-zone <ZoneName>  --size <SizeNumber>
Creating EBS volume
Verifying using AWS web-console

Step 5: Attaching the above created EBS volume to the instance you created in the previous steps.

This is final step of task. Command for attaching EBS volume to instance is:

aws ec2 attach-volume --device /<directory> --instance-id <instanceid> --volume-id <volumeid>
Attaching EBS volume to instance
Verifying using AWS web-console

Here, we have completed task using AWS-CLI. Thanks for reading.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store