S.
No Details Command Notes
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 [Link]
AWS meta data See the difference
curl -sL [Link]
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
[Link] we have to get list of regions
Solution
[Link] 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 [Link] file use "nano [Link]"
for REGION in $(aws ec2 describe-regions | jq ".Region[].RegionName" | tr -d '"')
To run script in file [Link] , we have use bash [Link] or
do
./[Link]
Now same scrip can be saved in file and run (say [Link]) echo "${REGION}"
aws ec2 describe-vpcs --region us-east-1| jq ".Vpcs[].VpcId" | tr -d '"'
Note: While using "./[Link]" command we may get
sleep 1
permission issue , change it using "chmod 700 [Link]"
done