AWS CLI

AWS CLI

Task Description

1) Create a key pair 

2)Create a security group 

3)Create an EBS volume of 1 GB.

4)Launch an instance using the above created key pair and security group.

5)The final step is to attach the above created EBS volume to the instance you created in the previous steps.

What is AWS CLI?

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

Create User

We create a user for authentication purposes.

  • Steps to create a user using web UI.

Go to all services.

Click to IAM.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Configure CLI

aws configure
No alt text provided for this image

Step 1: Create Key pair

If you do not know, how to use any services of aws use help

aws ec2 create-key-pair help


aws ec2 create-key-pair --key-name mykey
No alt text provided for this image

Step 2: Create a security group.

aws ec2 create-security-group help

Options or arguments are available for the security group.

  create-security-group

  --description <value>

  --group-name <value>

  [--vpc-id <value>]

  [--dry-run | --no-dry-run]

  [--cli-input-json | --cli-input-yaml]

  [--generate-cli-skeleton <value>]

  [--cli-auto-prompt <value>]

aws ec2 create-security-group –group-name MySecurityGroup –description “My Security group” –vpc-id vpc-02ef6e98dabb3242d

Here is the output

No alt text provided for this image
No alt text provided for this image

Here, there is no inbound rules

To create inbound rules

aws ec2 authorize-security-group-ingress help

aws ec2 authorize-security-group-ingress --group-id
sg-0c076eec4a046d493 --group-name MySecurityGroup --port 22 --protocol tcp --cidr 0.0.0.0/0

Here is the Output

No alt text provided for this image
No alt text provided for this image

Step 3: Create EBS volume

aws ec2 create-volume help

Available options to create EBS volume are

 create-volume

  --availability-zone <value>

  [--encrypted | --no-encrypted]

  [--iops <value>]

  [--kms-key-id <value>]

  [--outpost-arn <value>]

  [--size <value>]

  [--snapshot-id <value>]

  [--volume-type <value>]

  [--dry-run | --no-dry-run]

  [--tag-specifications <value>]

  [--multi-attach-enabled | --no-multi-attach-enabled]

  [--cli-input-json | --cli-input-yaml]

  [--generate-cli-skeleton <value>]

  [--cli-auto-prompt <value>]

Note: EBS is the Zonal Service

 
aws ec2 create-volume --size 1 --availability-zone ap-south-1a --volume-type gp2

Here is the output

No alt text provided for this image
No alt text provided for this image

Step 4: Launch an instance using the above created key pair and security group.

aws ec2 run-instances help

Available options are

 run-instances

  [--block-device-mappings <value>]

  [--image-id <value>]

  [--instance-type <value>]

  [--ipv6-address-count <value>]

  [--ipv6-addresses <value>]

  [--kernel-id <value>]

  [--key-name <value>]

  [--monitoring <value>]

  [--placement <value>]

  [--ramdisk-id <value>]

  [--security-group-ids <value>]

  [--security-groups <value>]

  [--subnet-id <value>]

  [--user-data <value>]

  [--additional-info <value>]

  [--client-token <value>]

  [--disable-api-termination | --enable-api-termination]

  [--dry-run | --no-dry-run]

  [--ebs-optimized | --no-ebs-optimized]

  [--iam-instance-profile <value>]

  [--instance-initiated-shutdown-behavior <value>]

  [--network-interfaces <value>]

  [--private-ip-address <value>]

  [--elastic-gpu-specification <value>]

  [--elastic-inference-accelerators <value>]

  [--tag-specifications <value>]

  [--launch-template <value>]

  [--instance-market-options <value>]

  [--credit-specification <value>]

aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --key-name mykey --security-group-ids sg-0c076eec4a046d493 --subnet-id subnet-0ecad70c1783cb8f6 --count 1

Here is the output

No alt text provided for this image
No alt text provided for this image

Step 5: Attach the volume to the instance

aws ec2 attach-volume help

Available Options are:

 attach-volume

  --device <value>

  --instance-id <value>

  --volume-id <value>

  [--dry-run | --no-dry-run]

  [--cli-input-json | --cli-input-yaml]

  [--generate-cli-skeleton <value>]

  [--cli-auto-prompt <value>]

aws ec2 attach-volume  --volume-id vol-0c15a73fc3da5d3a5 --instance-id i-021d1e324b0291c8a --device /dev/sdf

Here is the output

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Create Partition

fdisk /dev/xvdf
No alt text provided for this image
No alt text provided for this image

Format the file system

mkfs.ext4 /dev/xvdf1
No alt text provided for this image

Make a Directory

mkdir /my

Mount the partition

mount /dev/xvdf1 /myd
No alt text provided for this image

Thank you...

要查看或添加评论,请登录

Anudeep Nalla的更多文章

社区洞察

其他会员也浏览了