This document provides instructions on:
1. Installing basic tools like unzip, jq, curl for working with AWS metadata and JSON data using the command line.
2. Using AWS CLI commands like aws s3 ls and aws ec2 describe-vpcs to list S3 buckets and get VPC details from the AWS API and filter the output using jq.
3. Creating a script that loops through each AWS region and outputs the VPC IDs in that region to get VPC details across all regions.
This document provides instructions on:
1. Installing basic tools like unzip, jq, curl for working with AWS metadata and JSON data using the command line.
2. Using AWS CLI commands like aws s3 ls and aws ec2 describe-vpcs to list S3 buckets and get VPC details from the AWS API and filter the output using jq.
3. Creating a script that loops through each AWS region and outputs the VPC IDs in that region to get VPC details across all regions.
Necessary Min. Tools unzip, jq, tree, curl, wget, net-tools, stress, awscli cat/etc/lsb-release For detail Informatiom To know Version of M/c uname -a For short details To update system apt update or yum update Install basic tools apt install -y unzip jq tree curl wget net-tools strees Variable Decelaration curl http://169.254.169.254/latest/meta-data/ AWS meta data See the difference curl -sL http://169.254.169.254/latest/meta-data/ Environment variable normally available in a particular section, where we can actual use export command or bashrc , Env Variable one of the best example is AWS CLI where we can declare environment variable and we use them echo Used in Linux Write-Output Used in Windows , same as 'echo' in Linux or 'print' in python
Json JSON stands for JavaScript Object Notation
Jq jq is a free open source CLI JSON processor Json, yaml, HCl These are decilarative but not programming language aws s3 ls To get list of buckets from command line aws ec2 describe-vpcs To get compleate details of VPC from command line The output of "aws ec2 describe-vpcs" command is given as aws ec2 describe-vpcs | jq input to jq To get all vpc id aws ec2 describe-vpcs | jq ".Vpcs[].VpcId" We will get all Vpcs id in Double Quotes " we can remove that double "" quotes aws ec2 describe-vpcs | jq ".Vpcs[].VpcId" | tr -d '"' The " in between ' Single quotes will be removed. To get vpc id in particular region aws ec2 describe-vpcs --region us-east-1| jq ".Vpcs[].VpcId" | tr -d '"' Now we get VPC Id of only us-east-1 region 1.First we have to get list of regions Solution 2.from that list we have to get Vpcids aws ec2 describe-regions | jq ".Region[].RegionName" | tr -d '"' We get list of regions for REGION in $(aws ec2 describe-regions | jq ".Region[].RegionName" | tr -d '"') Now get Vpcs id in all regions (i.e region wise) do echo "${REGION}" Now lets wright a scrip to do so aws ec2 describe-vpcs --region us-east-1| jq ".Vpcs[].VpcId" | tr -d '"' sleep 1 done #!/bin/bash To create region.sh file use "nano region.sh" for REGION in $(aws ec2 describe-regions | jq ".Region[].RegionName" | tr -d '"') To run script in file region.sh , we have use bash region.sh or do ./region.sh Now same scrip can be saved in file and run (say region.sh) echo "${REGION}" aws ec2 describe-vpcs --region us-east-1| jq ".Vpcs[].VpcId" | tr -d '"' Note: While using "./region.sh" command we may get sleep 1 permission issue , change it using "chmod 700 region.sh" done