Launching Instance & attaching Volume using 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. Using CLI, we have more control.
For understanding the project, you need some prior knowledge.
Before starting with the project, you should have following things
- AWS account
- IAM user created
- AWS CLI tool installed
AWS Configure
aws configure
AWS Access Key ID [****************L4P7]:
AWS Secret Access Key [****************4PEs]:
Default region name [ap-south-1]:
Default output format [None]:
- Creating Key
aws ec2 create-key-pair --key-name task3
This key will be used to login to the instance.
As we can see we have successfully created keypair for the instance.
2. Creating Security Group
aws ec2 create-security-group --group-name Task3 --description "Arth Task 3"
We also have to provide ingress rule so that we can login to the instance
- Port 22 for remote login i.e. SSH
>aws ec2 authorize-security-group-ingress --group-id sg-060b5a6362811e65e --protocol tcp --port 22 --cidr 0.0.0.0/24
This will be security group for the instance.
As we can see we have successfully created security group for the instance.
3. Creating Instance
aws ec2 run-instances --image-id ami-0e306788ff2473ccb --count 1 --instance-type t2.micro --key-name task3 --security-group-ids sg-060b5a6362811e65e
The instance is launched successfully, we can confirm from either WebUI or CLI
4. Creating EBS
aws ec2 create-volume --availability-zone ap-south-1b --volume-type gp2 --size 1
5. Attaching Volume
We have to attach the volume to our instance, so it can be used.
aws ec2 attach-volume --instance-id i-00ad3765790d64a40 --volume-id vol-0c42b6e4d90a7e323 --device /dev/sdf
We have successfully launched ec2 instance and attach volume to it using cli.
In case of any queries or suggestions, DM me or comment below.
Thank You for your valuable time