AWS CLI

, , Leave a comment

Find Old Snapshots

aws ec2 describe-snapshots --region us-east-1 --profile 272 --query 'Snapshots[?StartTime<=`2019-03-01`]'

Find Network Interfaces

aws ec2 describe-instances --filters "Name=vpc-id,Values=vpc-5ef0b731" --query 'Reservations[*].Instances[*].NetworkInterfaces[*].NetworkInterfaceId'  --output text

List Name of EC2 Instance and Related Network Interface

aws ec2 describe-instances --region us-east-1  --query 'Reservations[*].Instances[].[Tags[?Key==`Name`].Value,  NetworkInterfaces[*].NetworkInterfaceId]' --output text 

List Name of EC2 Instances

aws ec2 describe-instances --region us-east-1 --profile 133 --query 'Reservations[*].Instances[].Tags[?Key==`Name`].Value' --output text 

Show Name of Running Instances

aws ec2 describe-instances --profile 133 --region us-east-1 --filters "Name=instance-state-code, Values=16" --query 'Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddresses[].PrivateIpAddress' --output text

Show EC2 Instance Name and IP Address

aws ec2 describe-instances  --query 'Reservations[*].Instances[].[ Tags[?Key==`Name`].Value  |  join(`, `, @), NetworkInterfaces[].PrivateIpAddress[] |  join(`, `, to_array(to_string(@))) ]' --profile famc-legacy --region us-east-1 --output table

Encrypt Bucket with AES256

aws s3api put-bucket-encryption -bucket athena-history-bucket-famc$i '{"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}]}'

Find Name of EC2 Instances Associated with Network Interface

aws ec2 describe-instances --output text --query 'Reservations[*].Instances[].Tags[?Key==`Name`].Value' --filters "Name=instance-state-name,Values=running,Name=network-interface.network-interface-id , Values=eni-8c20e1a0" --profile famc-legacy --region us-east-1

List Snapshots 

aws ec2 describe-snapshots --query Snapshots[].SnapshotId  --filters Name=owner-id,Values=858737304353 --profile famc-legacy --region us-east-1 

Delete Available Volumes

for each in `aws  ec2 describe-volumes --filter "Name=status, Values=available" --profile famc-prod --region us-east-1 --query Volumes[].VolumeId --output text`; do echo $each; aws ec2 delete-volume --volume-id $each  --profile famc-prod --region us-east-1; done

Allocate Elastic IP

ip2=`aws ec2 allocate-address --profile famc-legacy --region us-east-1 | jq .PublicIp | sed 's/\"//g' `
 

Leave a Reply