<file_sep>#!/bin/bash

# IMDSv2
# Get the Token
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/

# Get the AMI id of this instance
curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/ami-id

### Version 1
# Get public ip address
public_ip=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)

### Version 2
public_ip=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4)

# Get AMI Id

## Version 1
ami-id=$(curl http://169.254.169.254/latest/meta-data/ami-id)

### Version2 
ami-id=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/ami-id)

### Get VPC-id
### Version 1
vpc-id=$(curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/02:fa:6a:3b:76:e0/vpc-id)

### Version2
vpc-id=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/network/interfaces/macs/02:fa:6a:3b:76:e0/vpc-id)

### Get Subnet-id
### Version 1
subnet-id=$(curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/02:fa:6a:3b:76:e0/subnet-id)

### Version
subnet-id=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/network/interfaces/macs/02:fa:6a:3b:76:e0/subnet-id)<file_sep>#!/bin/bash

# Create a bucket in us-east-1
aws s3 mb --region us-west-2 s3://qts3fromcliorig

# Create a bucket in different region
aws s3 mb --region us-west-1 s3://qts3fromclicopy

# Lets enable versioning
aws s3api put-bucket-versioning --bucket qts3fromcliorig --versioning-configuration Status=Enabled
aws s3api put-bucket-versioning --bucket qts3fromclicopy --versioning-configuration Status=Enabled

# Create a  role to allow copy of the s3 bucket objects
# Attach the policy to role
# Enable put-bucket replication<file_sep>#!/bin/bash

remove_trails() {
    echo $(echo $1 | tr -d '"')
}

# create_subnet 192.168.0.0/24 $VPC_ID 'tag'
create_subnet() {
    ID=$(aws ec2 create-subnet --cidr-block "$1" --tag-specifications  "ResourceType=subnet,Tags=[{Key=Name, Value=$3}]" --vpc-id $2 --query "Subnet.SubnetId")
    ID=$(remove_trails $ID)
    echo $ID
}

# create_routetable $VPC_ID 'public'
create_routetable() {
    ROUTE_TABLE_ID=$(aws ec2 create-route-table --vpc-id "$1" --tag-specifications  "ResourceType=route-table,Tags=[{Key=Name, Value=$2}]" --query "RouteTable.RouteTableId")
    ROUTE_TABLE_ID=$(remove_trails $ROUTE_TABLE_ID)
    echo $ROUTE_TABLE_ID
}

VPC_ID=$(aws ec2 create-vpc --cidr-block '192.168.0.0/16' --tag-specifications  "ResourceType=vpc,Tags=[{Key=Name, Value=vpcfromcli}]" --query "Vpc.VpcId")
VPC_ID=$(remove_trails $VPC_ID)
echo "Created VPC with id: ${VPC_ID}"


# Create subnets
SUBNET1_ID=$(create_subnet '192.168.0.0/24' $VPC_ID 'subnet1')
echo "Created Subnet1 with Subnetid $SUBNET1_ID"
SUBNET2_ID=$(create_subnet '192.168.1.0/24' $VPC_ID 'subnet2')
echo "Created Subnet2 with Subnetid $SUBNET2_ID"
SUBNET3_ID=$(create_subnet '192.168.2.0/24' $VPC_ID 'subnet3')
echo "Created Subnet3 with Subnetid $SUBNET3_ID"
SUBNET4_ID=$(create_subnet '192.168.3.0/24' $VPC_ID 'subnet4')
echo "Created Subnet4 with Subnetid $SUBNET4_ID"

# CREATE Route tables
PUBLIC_RT=$(create_routetable $VPC_ID 'public')

echo "Created Routetable public with Id $PUBLIC_RT"
PRIVATE_RT=$(create_routetable $VPC_ID 'private')
echo "Created Routetable private with Id $PRIVATE_RT"

<file_sep>#!/bin/bash
# query using aws cli to fetch database instance identifiers
aws rds describe-db-instances --query "DBInstances[*].DBInstanceIdentifier"

#  to fetch database instance id and masterusername 
aws rds describe-db-instances --query "DBInstances[*].[DBInstanceIdentifier, MasterUsername]"

aws rds describe-db-instances --query "DBInstances[*].{ID: DBInstanceIdentifier, Username:MasterUsername}"

aws rds describe-db-instances --query "DBInstances[*].{ID: DBInstanceIdentifier, Username:MasterUsername}" --output table 

aws rds describe-db-instances --query "DBInstances[*].{ID: DBInstanceIdentifier, Username:MasterUsername}" --output text 

aws rds describe-db-instances --query "DBInstances[*].{ID: DBInstanceIdentifier, Username:MasterUsername}" --output yaml

# to fetch endpoint address for all mysql database instances
aws rds describe-db-instances --query "DBInstances[?Engine=='mysql'].Endpoint.Address"

#to fetch all the database snapshot identifiers and Status
aws rds describe-db-snapshots --query "DBSnapshots[*].{Id: DBSnapshotIdentifier, DBId: DBInstanceIdentifier, Status: Status}"
aws rds describe-db-snapshots --query "DBSnapshots[*].{Id: DBSnapshotIdentifier, DBId: DBInstanceIdentifier, Status: Status}" --output table

# to fetch all the database snapshot identifiers and Snapshot Creation time for mysql engine
aws rds describe-db-snapshots --query "DBSnapshots[?Engine=='mysql'].{Id: DBSnapshotIdentifier, DBId: DBInstanceIdentifier, CreationTime: SnapshotCreateTime}"


# to fetch all the db subnet group names other than default
aws rds describe-db-subnet-groups --query "DBSubnetGroups[?DBSubnetGroupName != 'default'].DBSubnetGroupName"



<file_sep>#!/bin/bash

# This file will contain simple commands that can be executed to create rds
# instances and configuring them
aws rds create-db-instance --db-instance-identifier 'qtrdsfromcli' --allocated-storage 20 --db-instance-class 'db.t2.micro' --engine 'mysql' --master-username 'admin' --master-user-password '<PASSWORD>' --vpc-security-group-ids "sg-075892da85bd09fc0" --backup-retention-period 7 --port 3306 --no-multi-az --no-auto-minor-version-upgrade

aws rds describe-db-instances

aws rds describe-db-instances --db-instance-identifier 'qtrdsfromcli'

# Create a db snapshot
aws rds create-db-snapshot --db-instance-identifier 'qtrdsfromcli' --db-snapshot-identifier 'snapshotfromcli'

aws rds describe-db-snapshots 

aws rds describe-db-snapshots --query "DBSnapshots[*].{Snapshot:DBSnapshotIdentifier,InstanceID:DBInstanceIdentifier,Status:Status}"

aws rds describe-db-snapshots --query "DBSnapshots[*].{Snapshot:DBSnapshotIdentifier,InstanceID:DBInstanceIdentifier,Status:Status}" --output yaml

aws rds describe-db-snapshots --query "DBSnapshots[*].{Snapshot:DBSnapshotIdentifier,InstanceID:DBInstanceIdentifier,Status:Status}" --output table

# Create read replica
aws rds create-db-instance-read-replica --db-instance-identifier 'qtrdsreplicafromcli' --source-db-instance-identifier 'qtrdsfromcli' --db-instance-class 'db.t2.micro' --publicly-accessible --no-multi-az --no-auto-minor-version-upgrade --vpc-security-group-ids "sg-075892da85bd09fc0"
aws rds describe-db-instances --query "DBInstances[*].{DBID: DBInstanceIdentifier, Status: DBInstanceStatus}" --output table

# promote read replica
aws rds promote-read-replica --db-instance-identifier 'qtrdsreplicafromcli'

aws rds delete-db-instance --db-instance-identifier 'qtrdsfromcli' --skip-final-snapshot <file_sep>#!/bin/bash

# basic info
aws s3 ls 

# human readable format
aws s3 ls --human-readable

aws s3 ls s3://qts3tbddocs --human-readable

# human readable format with summary
aws s3 ls s3://qts3tbddocs --human-readable --summarize

# remove buckets
aws s3 rb s3://qts3tbddocs

aws s3 rb s3://qts3tbddocs --force

# Create an s3 bucket with 3 folders
# images
# documents
# videos

aws s3 mb s3://qts3inclass

# Upload one object per folder from your local machine to s3 bucket
aws s3 cp ./contents/content.txt s3://qts3inclass/documents/content.txt

aws s3 cp ./contents/test.jpg s3://qts3inclass/images/test.jpg

aws s3 cp ./contents/one.mp4 s3://qts3inclass/videos/one.mp4

# Create a new bucket 
aws s3 mb s3://qts3inclasscopy

# syncronize the contents of one bucket to another
aws s3 sync s3://qts3inclass s3://qts3inclasscopy

# Summarize the contents 
aws s3 ls s3://qts3inclass --human-readable --summarize
aws s3 ls s3://qts3inclass --recursive --human-readable --summarize

aws s3 ls s3://qts3inclasscopy --human-readable --summarize
aws s3 ls s3://qts3inclasscopy --recursive --human-readable --summarize

# Delete the objects 
aws s3 rm --recursive s3://qts3inclasscopy

# Sync the contents from local machine to s3 bukcet
aws s3 sync ./contents s3://qts3inclass/contents

aws s3 ls s3://qts3inclass --recursive --human-readable








<file_sep>#!/bin/bash

# In this we will try to create ec2 instance
aws ec2 run-instances --image-id "ami-0a4a70bd98c6d6441" --instance-type "t2.micro" --key-name "climumbai" --security-group-ids "sg-09856719dfb1ab869"

# To Remove ec2 instance make a note of instance id
aws ec2 terminate-instances --instance-ids i-0bd538d74168d4e42<file_sep>#!/bin/bash
aws autoscaling create-launch-configuration \
    --launch-configuration-name 'lcfromcli' --image-id 'ami-03d5c68bab01f3496' \
    --key-name 'ansible' --security-groups 'sg-0eb0f3fca6c9a45a8' \
    --instance-type 't2.micro' --associate-public-ip-address

aws autoscaling describe-launch-configurations --query "LaunchConfigurations[*].LaunchConfigurationName"

aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name 'asgfromcli' --launch-configuration-name 'lcfromcli' \
    --min-size 1 --max-size 5 --desired-capacity 2 \
    --availability-zones "us-west-2a" "us-west-2b" "us-west-2c"

aws autoscaling describe-auto-scaling-groups


aws autoscaling put-scaling-policy \
    --auto-scaling-group-name 'asgfromcli' --policy-name 'mytargetrackingpolicy' \
    --policy-type 'TargetTrackingScaling' \
    --target-tracking-configuration 'file://config.json'
<file_sep>#!/bin/bash

# Creating a vpc with aws cli
aws ec2 create-vpc --cidr-block '10.100.0.0/16' --tag-specifications 'ResourceType=vpc,Tags=[{Key="Name",Value="ntier"}]'
 #vpc-id =vpc-0f229c2da7f5e512d

#vpcid=$(aws ec2 describe-vpcs --filter 'Name=cidr,Values=10.100.0.0/16' --query 'Vpcs[0].VpcId')


# Create web subnet
aws ec2 create-subnet --cidr-block '10.100.0.0/24'  --vpc-id $vpc_id --tag-specifications 'ResourceType=subnet,Tags=[{Key="Name",Value="web"}]' --availability-zone "us-west-2a"

# Create app subnet
aws ec2 create-subnet --cidr-block '10.100.1.0/24'  --vpc-id $vpc_id --tag-specifications 'ResourceType=subnet,Tags=[{Key="Name",Value="app"}]' --availability-zone "us-west-2b"

# Create db subnet
aws ec2 create-subnet --cidr-block '10.100.2.0/24'  --vpc-id $vpc_id --tag-specifications 'ResourceType=subnet,Tags=[{Key="Name",Value="db"}]' --availability-zone "us-west-2c"

# Create mgmt subnet
aws ec2 create-subnet --cidr-block '10.100.3.0/24'  --vpc-id $vpc_id --tag-specifications 'ResourceType=subnet,Tags=[{Key="Name",Value="mgmt"}]' --availability-zone "us-west-2a"

# Create internet gateway
aws ec2 create-internet-gateway --tag-specifications 'ResourceType=internet-gateway,Tags=[{Key="Name",Value="ntierigw"}]'

# attach interet-gateway with vpc
aws ec2 attach-internet-gateway --vpc-id $vpc_id --internet-gateway-id $igw_id

# Create public route table
aws ec2 create-route-table --vpc-id $vpc_id --tag-specifications 'ResourceType=route-table,Tags=[{Key="Name",Value="public"}]'

# Create private route table
aws ec2 create-route-table --vpc-id $vpc_id --tag-specifications 'ResourceType=route-table,Tags=[{Key="Name",Value="private"}]'

# Create a route to igw for public route table
aws ec2 create-route --destination-cidr-block 0.0.0.0/0 --gateway-id $igw_id --route-table-id $pub_rt_id

aws ec2 associate-route-table --route-table-id $pub_rt_id  --subnet-id 'subnet-0372a28adcf6a733b'
aws ec2 associate-route-table --route-table-id $pub_rt_id  --subnet-id 'subnet-0456e0afc23996728'
aws ec2 associate-route-table --route-table-id $pri_rt_id  --subnet-id 'subnet-085e842b0137a2308'
aws ec2 associate-route-table --route-table-id $pri_rt_id  --subnet-id 'subnet-0dbc628a0a5daa03f'

# web Security Group
aws ec2 create-security-group --description 'web sg' --group-name 'web' --vpc-id $vpc_id  --tag-specifications 'ResourceType=security-group,Tags=[{Key="Name",Value="web"}]'

aws ec2 authorize-security-group-ingress --group-id sg-0b16a13e9892355a1 --protocol tcp --port 80 --cidr 0.0.0.0/0

# network acl
aws ec2 create-network-acl --vpc $vpc_id  --tag-specifications 'ResourceType=network-acl,Tags=[{Key="Name",Value="web-acl"}]'
#nacl_id=acl-04d687ee59684f6ee

aws ec2 create-network-acl-entry --network-acl-id acl-04d687ee59684f6ee --ingress --port-range From=80,To=80 --cidr-block 0.0.0.0/0 --rule-action allow --rule-number 100 --protocol tcp<file_sep>#!/bin/bash

aws ec2 create-vpc --cidr-block '192.168.0.0/16' --tag-specifications "ResourceType=vpc,Tags=[{Key=Name,Value=ntier}]"
# "VpcId": "vpc-04acb61dbc8b814c7"

aws ec2 create-subnet --cidr-block '192.168.0.0/24' --tag-specifications "ResourceType=subnet,Tags=[{Key=Name,Value=web1}]" --vpc-id "vpc-04acb61dbc8b814c7" --availability-zone "us-west-2a"
# "SubnetId": "subnet-0b8b36e0ae7a2b040"


aws ec2 create-subnet --cidr-block '192.168.1.0/24' --tag-specifications "ResourceType=subnet,Tags=[{Key=Name,Value=web2}]" --vpc-id "vpc-04acb61dbc8b814c7" --availability-zone "us-west-2b"
#"SubnetId": "subnet-0157da4c7a92eb1d9"


aws ec2 create-subnet --cidr-block '192.168.2.0/24' --tag-specifications "ResourceType=subnet,Tags=[{Key=Name,Value=app1}]" --vpc-id "vpc-04acb61dbc8b814c7" --availability-zone "us-west-2a"
# "SubnetId": "subnet-063a24cd079bc5ff6"


aws ec2 create-subnet --cidr-block '192.168.3.0/24' --tag-specifications "ResourceType=subnet,Tags=[{Key=Name,Value=app2}]" --vpc-id "vpc-04acb61dbc8b814c7" --availability-zone "us-west-2b"
# "SubnetId": "subnet-0f50fceb36b1c4833"


aws ec2 create-subnet --cidr-block '192.168.4.0/24' --tag-specifications "ResourceType=subnet,Tags=[{Key=Name,Value=db1}]" --vpc-id "vpc-04acb61dbc8b814c7" --availability-zone "us-west-2a"
# "SubnetId": "subnet-014b090887965363c"


aws ec2 create-subnet --cidr-block '192.168.5.0/24' --tag-specifications "ResourceType=subnet,Tags=[{Key=Name,Value=db2}]" --vpc-id "vpc-04acb61dbc8b814c7" --availability-zone "us-west-2b"
# "SubnetId": "subnet-0ecd212a19a0427ae"

aws ec2 create-internet-gateway --tag-specifications "ResourceType=internet-gateway,Tags=[{Key=Name,Value=ntierigw}]"
# "InternetGatewayId": "igw-09baaac90b9e1aaf6"

aws ec2 attach-internet-gateway --internet-gateway-id "igw-09baaac90b9e1aaf6" --vpc-id "vpc-04acb61dbc8b814c7"




<file_sep>#!/bin/bash

### usage is get_access_key username
get_access_key() {
    access_key=$(aws iam list-access-keys --user-name $user --query "AccessKeyMetadata[0].AccessKeyId"|tr -d '"')
    echo $access_key

}

send_email() {
    echo "Sending email with json attached"
}

#users=$(aws iam list-users --query "Users[].UserName")
users=(testuser1 testuser2)
for user in ${users[@]}; do
  echo "rotating credentials for $user"
  current_access_key=$(get_access_key $user)
  aws iam create-access-key --user-name $user > $user.json
  send_email
  echo "deleting current access key $current_access_key"
  aws iam delete-access-key --access-key-id $current_access_key --user-name $user
  new_access_key=$(get_access_key $user)
  echo "New access key is $new_access_key"
done<file_sep>#!/bin/bash

current_region="ap-south-1"
ubuntu_20_amiid="ami-0a4a70bd98c6d6441"
windows_2019_amid="ami-0994975f92b8520bc"

echo "fetching the aws default vpc id"
# find default vpc id in your region
vpc_id=$(aws ec2 describe-vpcs --query "Vpcs[?IsDefault].VpcId" --output text)
echo "created the vpc with id ${vpc_id}"


# Create a security group
sgroupname='openforgol'
echo "Creating the security group with name ${sgroupname}"

aws ec2 create-security-group --description "open 22 80 and 8080 port" --group-name ${sgroupname} --vpc-id $vpc_id

# store security group id into some variable
sg_id=$(aws ec2 describe-security-groups --group-names ${sgroupname} --query "SecurityGroups[0].GroupId" --output text)
echo "Created security group with id ${sg_id}"
# openports
for port_number in 22 80 8080
do
    echo "Creating a security group ingress rule for ${port_number}"
    aws ec2 authorize-security-group-ingress --group-name ${sgroupname} --protocol tcp --port "$port_number" --cidr 0.0.0.0/0
done

key_name="my-key"
# if you dont have a key use ssh-keygen
echo "importing key pair"
aws ec2 import-key-pair --key-name $key_name --public-key-material fileb://~/.ssh/id_rsa.pub

az_a="${current_region}a"
az_b="${current_region}b"


#subnet id in az -a
subnet_a=$(aws ec2 describe-subnets --filters "Name=availability-zone,Values=${az_a}" "Name=vpc-id,Values=$vpc_id" --query "Subnets[0].SubnetId" --output text)
echo "subnet in ${az_a} is ${subnet_a}"
#subnet id in az-b
subnet_b=$(aws ec2 describe-subnets --filters "Name=availability-zone,Values=${az_b}" "Name=vpc-id,Values=$vpc_id" --query "Subnets[0].SubnetId" --output text)
echo "subnet in ${az_b} is ${subnet_b}"

default_instance_type='t2.micro'

aws ec2 run-instances --image-id $ubuntu_20_amiid --instance-type $default_instance_type --key-name $key_name --security-group-ids $sg_id --subnet-id $subnet_a --count 1

aws ec2 run-instances --image-id $windows_2019_amid --instance-type $default_instance_type --key-name $key_name --security-group-ids $sg_id --subnet-id $subnet_b --count 1

# fetch ubuntu instance ami id
ubuntu_20_instance_id=$(aws ec2 describe-instances --filter "Name=image-id,Values=${ubuntu_20_amiid}" --query "Reservations[].Instances[0].InstanceId" --output text)
# fetch ubuntu instance public ip address
ubuntu_20_public_ip=$(aws ec2 describe-instances --filter "Name=instance-id,Values=${ubuntu_20_instance_id}" --query "Reservations[].Instances[0].PublicIpAddress" --output text)

echo "preparing login command"
# login into ec2 instance
echo "ssh -i ~/.ssh/id_rsa ubuntu@${ubuntu_20_public_ip}"

# Lets get Windows instance id and windows public ip address
windows_2019_instance_id=$(aws ec2 describe-instances --filter "Name=image-id,Values=${windows_2019_amid}" --query "Reservations[].Instances[0].InstanceId" --output text)
windows_2019_public_ip=$(aws ec2 describe-instances --filter "Name=instance-id,Values=${windows_2019_instance_id}" --query "Reservations[].Instances[0].PublicIpAddress" --output text)

aws ec2 get-password-data --instance-id "${windows_2019_instance_id}" --priv-launch-key "~/.ssh/id_rsa" 

## Deleting ec2 instance
aws ec2 terminate-instances --instance-ids "${windows_2019_instance_id}" "${ubuntu_20_instance_id}"
aws ec2 delete-key-pair --key-name $key_name
aws ec2 delete-security-group --group-id $sg_id<file_sep>#!/bin/bash
aws s3api list-objects --bucket qts3apidemo<file_sep>#!/bin/bash
aws iam create-group --group-name 'avengers'
for name in Ironman Gamora BlackPanther CaptianAmerica Thor Hulk BlackWidow groot nebula spiderman
do
    aws iam create-user --user-name $name
    aws iam create-login-profile --user-name $name --password-reset-required --password '<PASSWORD>'
    aws iam add-user-to-group --group-name 'avengers' --user-name $name
done

<file_sep>#!/bin/bash
aws iam create-group --group-name 'justiceleague'
for name in superman batman aquaman wonderwomen
do
    aws iam create-user --user-name $name
    aws iam create-login-profile --user-name $name --password-reset-required --password '<PASSWORD>'
    aws iam add-user-to-group --group-name 'justiceleague' --user-name $name
done

<file_sep>#!/bin/bash

# Lets get all the security group names
groupnames=$(aws ec2 describe-security-groups --query "SecurityGroups[*].GroupName")

for group in ${groupnames}
do
    echo "${group}"
done

# Lets get all the security group ids
groupids=$(aws ec2 describe-security-groups --query "SecurityGroups[*].GroupId")

# find the ip address of the instances 
publicips=$(aws ec2 describe-instances --query "Reservations[*].Instances[*].PublicIpAddress" --text)

# find the ipaddress of specific instance
publicip=$(aws ec2 describe-instances --instance-ids i-0d97976949ae63a82 --query "Reservations[*].Instances[*].PublicIpAddress" --text)

# Write a aws cli query to print the key pair names
aws ec2 describe-key-pairs --query "KeyPairs[*].KeyName" --output text
<file_sep>aws rds create-db-instance --db-instance-identifier 'qtrdsfromcli' \
    --db-instance-class 'db.t2.micro' --engine 'mysql' \
    --master-username 'root' --master-user-password '<PASSWORD>' \
    --publicly-accessible --db-name 'qtecommerce'  \
    --db-subnet-group-name 'qtsubnetgroup' --allocated-storage 20

aws rds describe-db-instances --db-instance-identifier 'qtrdsfromcli' 

aws rds describe-db-instances --db-instance-identifier 'qtrdsfromcli'\
    --query 'DBInstances[0].DBInstanceStatus'

aws rds describe-db-instances --db-instance-identifier 'qtrdsfromcli' \
    --query 'DBInstances[0].Endpoint'

aws rds delete-db-instance --db-instance-identifier 'qtrdsfromcli'\
    --skip-final-snapshot --delete-automated-backups

aws rds create-db-instance --db-instance-identifier 'qtrdsfromclimulti' \
    --db-instance-class 'db.t2.micro' --engine 'mysql' \
    --master-username 'root' --master-user-password '<PASSWORD>' \
    --publicly-accessible --db-name 'qtecommerce'  \
    --db-subnet-group-name 'qtsubnetgroup' --allocated-storage 20 \
    --multi-az --vpc-security-group-ids 'sg-0c8eee8f2fbefd89e'


aws rds create-db-instance-read-replica --db-instance-identifier 'qtrdsreplica' \
    --source-db-instance-identifier 'qtrdsfromclimulti' --publicly-accessible \
    --source-region 'us-west-2'

# Create db snapshot
aws rds create-db-snapshot --db-instance-identifier 'qtrdsfromclimulti' \
    --db-snapshot-identifier 'snapshotfromcli'

# Delete db snapshot
aws rds delete-db-snapshot --db-snapshot-identifier 'snapshotfromcli'

# Promote read replica
aws rds promote-read-replica --db-instance-identifier 'qtrdsreplica'

# Delete the db-instance
aws rds delete-db-instance --db-instance-identifier 'qtrdsreplica'\
    --skip-final-snapshot --delete-automated-backups

# Create a read replica in different region 
# ARN: arn:aws:rds:<region>:<account number>:<resourcetype>:<name>
aws rds create-db-instance-read-replica --db-instance-identifier 'qtrdsreplica' \
    --source-db-instance-identifier 'arn:aws:rds:us-west-2:678879106782:db:qtrdsfromclimulti' \
    --publicly-accessible \
    --source-region 'us-west-2' --region 'ap-south-1'

aws rds delete-db-instance --db-instance-identifier 'qtrdsreplica'\
    --skip-final-snapshot --delete-automated-backups --region 'ap-south-1'

aws rds delete-db-instance --db-instance-identifier 'qtrdsfromclimulti'\
    --skip-final-snapshot --delete-automated-backups 






<file_sep>#!/bin/bash

# Create an AWS S3 Glacier vault
aws glacier create-vault --account-id - --vault-name 'docsvault'

#
# {
#    "location": "/678879106782/vaults/docsvault"
# }
#

# Prepare a large file 10 MB
dd if=/dev/urandom of=largefile bs=10485760 count=1

# Split the files into 1 MB 
split -b 1048576 --verbose largefile chunk

# lets upload file directly to the archive
aws glacier upload-archive --account-id - --vault-name 'docsvault' --body awscliv2.zip

# Generally we upload large files where we upload parts of the file

# Lets initiate multipart upload
aws glacier initiate-multipart-upload --account-id - --archive-description "multipart upload demo" --part-size 1048576 --vault-name 'docsvault'

# {
#     "location": "/678879106782/vaults/docsvault/multipart-uploads/<KEY>",
#     "uploadId": "<KEY>"
# }

UPLOADID='<KEY>'

aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkaa --range 'bytes 0-1048575/*'
# {
#     "checksum": "67793b16e2bb560d78b31a04ed25c543f40f23c9db2dc07f2bd8152b9281c41a"
# }

aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkab --range 'bytes 1048576-2097151/*'
# {
#     "checksum": "9157be17875e70f7c2172fc78ae52f82e27e3b921499ca76527de54e72122253"
# }

aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkac --range 'bytes 2097152-3145727/*'

# {
#     "checksum": "4b234d66bbafbe590e2d11f854937a9f2db1d3efc1e97d781bd4b650524fdb76"
# }


aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkad --range 'bytes 3145728-4194303/*'
# {
#     "checksum": "389bda6a3bf4e353d7bad29b42458212b5108504620ff4d7f67224c00196e533"
# }

aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkae --range 'bytes 4194304-5242879/*'

# {
#     "checksum": "43dc081cce7630950c0df124eb14576ca8c731549ad87bcbf729fa4d458e9927"
# }

aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkaf --range 'bytes 5242880-6291455/*'
# {
#     "checksum": "6adaec6095b75dfdbb4b01955e592f5751f8cf3900022dbfe917888456773983"
# }

aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkag --range 'bytes 6291456-7340031/*'

# {
#     "checksum": "6f741bf13f6571f14449a68ff9faf72e8d2ee15d38bb87f50674ebb9848dfd61"
# }

aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkah --range 'bytes 7340032-8388607/*'

# {
#     "checksum": "c32c2e938d6634fe9a494e1738b04db3c813f7498d9386e61433637223806b02"
# }

aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkai --range 'bytes 8388608-9437183/*'

# {
#     "checksum": "f28d377947e57d6e78595d50b1353f16f663832f210c00bf0f82f55dc2a2183d"
# }

aws glacier upload-multipart-part --upload-id $UPLOADID --account-id - --vault-name 'docsvault' --body chunkaj --range 'bytes 9437184-10485759/*'

# {
#     "checksum": "afeafaef8a5a7f15f4fd1a00b36d380a4a80680f4079f2341c851e14fba2cf69"
# }

# Calculate tree hash
openssl dgst -sha256 -binary chunkaa > hash1
openssl dgst -sha256 -binary chunkab > hash2
openssl dgst -sha256 -binary chunkac > hash3
openssl dgst -sha256 -binary chunkad > hash4
openssl dgst -sha256 -binary chunkae > hash5
openssl dgst -sha256 -binary chunkaf > hash6
openssl dgst -sha256 -binary chunkag > hash7
openssl dgst -sha256 -binary chunkah > hash8
openssl dgst -sha256 -binary chunkai > hash9
openssl dgst -sha256 -binary chunkaj > hash10




<file_sep>#!/bin/bash
aws ec2 run-instances --image-id 'ami-0cf6f5c8a62fa5da6' --instance-type 't2.micro' --key-name 'cheflearning' --security-groups 'openallports'  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=fromcli1}]'

# fetchin information about the ec2 instance created by us
aws ec2 describe-instances --filters 'Name=image-id,Values=ami-0cf6f5c8a62fa5da6' --query "Reservations[*].Instances[*].PublicIpAddress" --output text

aws ec2 run-instances --image-id 'ami-03d5c68bab01f3496' --instance-type 't2.micro' --key-name 'cheflearning' --security-groups 'openallports'  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=fromcli2}]'

# fetchin information about the ec2 instance created by us
aws ec2 describe-instances --filters 'Name=tag:Name,Values=fromcli2' --query "Reservations[*].Instances[*].PublicIpAddress" --output text

# Stop the ec2 instace with tag Name: fromcli2
instaceid=$(aws ec2 describe-instances --filters 'Name=tag:Name,Values=fromcli2' --query "Reservations[0].Instances[0].InstanceId" --output text)

aws ec2 stop-instances --instance-ids ${instaceid}

# Terminate the ec2 instance with tag Name: fromcli1
aws ec2 describe-instances --filters 'Name=tag:Name,Values=fromcli1' --query "Reservations[0].Instances[0].InstanceId" --output text



<file_sep>#!/bin/bash

aws s3api create-bucket --acl 'public-read' --bucket 'qts3apidemo' --region 'us-east-1'

aws s3api put-object --bucket 'qts3apidemo' --key 'videos/one.mp4' --body './contents/one.mp4'

# Create the similar structure like what we have done with basic s3 commands<file_sep>#!/bin/bash

# get default vpc
vpc_id=$(aws ec2 describe-vpcs --query 'Vpcs[?IsDefault].VpcId[]' --output text)

# Create a security group

aws ec2 create-security-group --description "open 22 80 and 8080 port" --group-name 'openfortomcat' --vpc-id $vpc_id

# store security group id into some variable
sg_id=$(aws ec2 describe-security-groups --group-names "openfortomcat" --query "SecurityGroups[0].GroupId" --output text)

# openports
for port_number in 22 80 8080
do
    aws ec2 authorize-security-group-ingress --group-name "openfortomcat" --protocol tcp --port "$port_number" --cidr 0.0.0.0/0
done

# get the first subnet
subnet_id=$(aws ec2 describe-subnets --filters "Name=vpc-id,Values=$vpc_id" --query "Subnets[0].SubnetId" --output text)

# Create a public key if required 
# ssh-keygen

aws ec2 import-key-pair --key-name "my-key" --public-key-material fileb://~/.ssh/id_rsa.pub

# Create an ec2 instance with the security group and key created over here
