Table of Contents

AWS basics Commands

EC2

Create keypair

snippet.bash
aws ec2 create-key-pair --key-name bofher_keypair --query 'KeyMaterial' --output text > AWS_bofher_keypair.pem
chmod 400 AWS_bofher_keypair.pem

Then show info:

snippet.bash
aws ec2 describe-vpcs

Result is a json, so you can filter it like:

snippet.bash
aws ec2 describe-vpcs | jq  ".Vpcs[].VpcId"

Create VPC

snippet.bash
aws ec2 create-vpc --cidr-block 10.0.0.0/24 --query Vpc.VpcId --output text

Then show info:

snippet.bash
aws ec2 describe-key-pairs --key-name bofher_keypair

security group

for firewall rules

Create security group

snippet.bash
aws ec2 create-security-group --group-name test_sg --description "test_security_group" --vpc-id vpc-04738d91cd27e3a68

To easy your live, export the security group id:

snippet.bash
export SG_ID="sg-07332f264769ee59c"

Check:

snippet.bash
aws ec2 describe-security-groups --group-ids  ${SG_ID}

Grant accesss to your public ip only

snippet.bash
aws ec2 authorize-security-group-ingress --group-id ${SG_ID} --protocol tcp --port 22 --cidr $(curl ifconfig.me)/32

You will see something like:

snippet.json
{
    "Return": true,
    "SecurityGroupRules": [
        {
            "SecurityGroupRuleId": "sgr-0a20e51c280054d45",
            "GroupId": "sg-07332f264769ee59c",
            "GroupOwnerId": "183631327649",
            "IsEgress": false,
            "IpProtocol": "tcp",
            "FromPort": 22,
            "ToPort": 22,
            "CidrIpv4": "149.102.236.197/32"
        }
    ]
}