Arth Task-3 (AWS with CLI )
It's just completed one month of arth training till now and I'm capable to do multiple things at a time because of core knowledge and right arth(meaning) of the concepts that are taught by @vimal daga sir, I'm very happy to being part of arth and always thankful to vimal sir for giving such big opportunity to all of us.
Here is the Task Description - AWS 👨🏻💻
🔅 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.
Before going to perform this task we need to create one user with Power User Access in this way we can provide the all access of root account excluding billing and IAM user creation to perform the all above mentioned task.
Screenshot oF user Creation
We need to provide Programmatic access by clicking on checkbox so we can enable the access ID and Access key for CLI and other development tool.
Here I Provide the POwer User Access to perform all task from CLI.
After this the first task that we want to performed is creating a security group in particular Region so we can attached that security group to the instances that are we going to create in future.
1.Creates a security group.
A security group acts as a virtual firewall for your instance to control inbound and outbound traffic.
When you create a security group, you specify a friendly name of your choice. You can have a security group for use in EC2-Classic with the same name as a security group for use in a VPC. However, you can't have two security groups for use in EC2-Classic with the same name or two security groups for use in a VPC with the same name.
You have a default security group for use in EC2-Classic and a default security group for use in your VPC. If you don't specify a security group when you launch an instance, the instance is launched into the appropriate default security group. A default security group includes a default rule that grants instances unrestricted network access to each other.
You can add or remove rules from your security groups using AuthorizeSecurityGroupIngress , AuthorizeSecurityGroupEgress , RevokeSecurityGroupIngress , and RevokeSecurityGroupEgress .
Synopsis
create-security-group --description <value> --group-name <value> [--vpc-id <value>] [--tag-specifications <value>] [--dry-run | --no-dry-run] [--cli-input-json <value>] [--generate-cli-skeleton <value>]
Examples
To create a security group for EC2-Classic
This example creates a security group named MySecurityGroup.
Command:
aws ec2 create-security-group --group-name MySecurityGroup --description "My security group"
2.Create-key-pair
Creates a 2048-bit RSA key pair with the specified name. Amazon EC2 stores the public key and displays the private key for you to save to a file. The private key is returned as an unencrypted PEM encoded PKCS#1 private key. If a key with the specified name already exists, Amazon EC2 returns an error.
You can have up to five thousand key pairs per Region.
The key pair returned to you is available only in the Region in which you create it. If you prefer, you can create your own key pair using a third-party tool and upload it to any Region using ImportKeyPair
Synopsis
create-key-pair --key-name <value> [--dry-run | --no-dry-run] [--tag-specifications <value>] [--cli-input-json <value>] [--generate-cli-skeleton <value>]
Examples
To create a key pair
This example creates a key pair named MyKeyPair.
Command:
aws ec2 create-key-pair --key-name MyKeyPair
3. Launch an instance using the above created key pair and security group.
Synopsis
create-instance --stack-id <value> --layer-ids <value> --instance-type <value> [--auto-scaling-type <value>] [--hostname <value>] [--os <value>] [--ami-id <value>] [--ssh-key-name <value>] [--availability-zone <value>] [--virtualization-type <value>] [--subnet-id <value>] [--architecture <value>] [--root-device-type <value>] [--block-device-mappings <value>] [--install-updates-on-boot | --no-install-updates-on-boot] [--ebs-optimized | --no-ebs-optimized] [--agent-version <value>] [--tenancy <value>] [--cli-input-json <value>] [--generate-cli-skeleton <value>]
Examples
Use this command to launch the instance with attaching above security group and key pair that are we previously.
aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --count 1 --subnet-id subnet-40ccc528 --security-group-ids sg-04b41e7a77baa3288 --key-name MyKeyPair
4.Create an EBS volume of 1 GB.
Creates an EBS volume that can be attached to an instance in the same Availability Zone.
You can create encrypted volumes. Encrypted volumes must be attached to instances that support Amazon EBS encryption. Volumes that are created from encrypted snapshots are also automatically encrypted.
Synopsis
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 <value>] [--generate-cli-skeleton <value>]
Examples
To create an empty General Purpose SSD (gp2) volume
The following create-volume example creates an 1 GiB General Purpose SSD (gp2) volume in the specified Availability Zone. Note that the current Region must be ap-south-1, or you can add the --region parameter to specify the Region for the command.
aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone ap-south-1a
5.The final step is to attach the above created EBS volume to the instance you created in the previous steps.
Attaches an EBS volume to a running or stopped instance and exposes it to the instance with the specified device name and encrypted EBS volumes must be attached to instances that support Amazon EBS encryption.
Synopsis
attach-volume --device <value> --instance-id <value> --volume-id <value> [--dry-run | --no-dry-run] [--cli-input-json <value>] [--generate-cli-skeleton <value>]
Examples
To attach a volume to an instance
This example command attaches a volume (vol-0fb1130bc8c2a2cd2) to an instance (i-01474ef662b89480) as /dev/sdf.
Command:
aws ec2 attach-volume --volume-id vol-0fb1130bc8c2a2cd2 --instance-id i-053c14def157f8cc1 --device /dev/sdf
And for getting all information of the instance to check whether EBS Volume, security group and key pair is attached or not we can use following command for CLI to see the all information regards instance that are we launched in particular region.
Examples
Command:
aws ec2 describe-instances
Thanks for reading this article i hope you get more relevant information from this article if you like it then do share with other if you found any mistake in this article please let me know through comment section.