AWS CLI
Anudeep Nalla
Opensource Contributer | Platform Engineer | EX-NPCI | RHCA Level III | OpenShift | CEPH | CK{S,A,AD} | 3x Microsoft Certified | AWS CSA | Rancher | Nirmata | DevOps | Ansible | Jenkins | DevSecOps | Kyverno | Rook-Ceph
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.
Configure CLI
aws configure
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
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
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
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
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
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
Create Partition
fdisk /dev/xvdf
Format the file system
mkfs.ext4 /dev/xvdf1
Make a Directory
mkdir /my
Mount the partition
mount /dev/xvdf1 /myd
Thank you...