You are on page 1of 1

AWS CLI Commands

User PowerShell to run below command

1. Creating a security Group


aws ec2 create-security-group --group-name devenv-sg --description "security group for development environment in EC2"

2. AWS CLI command for creating rules for security group devenv-sg earlier
aws ec2 authorize-security-group-ingress --group-name devenv-sg --protocol tcp --port 22 --cidr 0.0.0.0/0

3. Next, create a key pair, which allows you to connect to the instance.
aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text | out-file -encoding ascii -filepath
MyKeyPair.pem
(Note:- MyKeyPair.pem will be saved into your current working directory)

4. To launch and connect to the instance


aws ec2 run-instances --image-id ami-d5c18eba --security-group-ids sg-b4a291dc --count 1 --instance-type t2.micro --key-name
MyKeyPair --query 'Instances[0].InstanceId'
Note:
sg-b4a291dc  This is security we created earlier using CLI command
image-id ami-d5c18eba  Image ID of Amazon Linux

5. The instance will take a few moments to launch. Once the instance is up and running, the following command will retrieve the
public IP address that you will use to connect to the instance.
aws ec2 describe-instances --instance-ids "i-044241315b800c7cd" --query 'Reservations[0].Instances[0].PublicIpAddress'

You might also like