AWS

CLI

CLI

Connection setting

1 - Create Access Key at the IAM console

2 - Download key and use the content on credential file in <user_folder>\.aws\

[default]
aws_access_key_id=xxxxx
aws_secret_access_key=yyyyyyyy

3 - Update file <user_folder>\.aws\config

[default]
region = us-west-2
output = json
source_profile = rribeiro
mfa_serial = arn:aws:iam::721933253214:mfa/rribeiro

Finally, to test the connection, run:

$ aws ec2 describe-instances

If MFA is required, the following command can be used to authenticate:

$ aws sts get-session-token --serial-number arn:aws:iam::721933253214:mfa/rribeiro --token-code <TOKEN>

 

CLI

EC2 Snapshots

Find Snapshots older than an specific date. Won't work if AWS CLI is running on Windows:

$ aws ec2 describe-snapshots --region us-west-2 --query 'Snapshots[?StartTime <= `2017-08-30`].{id:SnapshotId}' --owner-ids 721933253214

Find Snapshots older than an specific date and that does not contain words on SnapshotId and Description:

$ aws ec2 describe-snapshots --region us-west-2 --query 'Snapshots[?StartTime <= `2015-08-30`]|[?contains(SnapshotId, `DND`) == `false`]|[?contains(Description, `DND`) == `false`].[SnapshotId,Description]' --output text

 

More at: https://opensourceconnections.com/blog/2015/07/27/advanced-aws-cli-jmespath-query/