Skip to content

Instantly share code, notes, and snippets.

@tappoz
Created December 9, 2016 17:41
Show Gist options
  • Save tappoz/847229167d9c031ab6815fd72c0cb509 to your computer and use it in GitHub Desktop.
Save tappoz/847229167d9c031ab6815fd72c0cb509 to your computer and use it in GitHub Desktop.
AWS CLI cheatsheet

EC2

Generate ssh key

To be used for a user in an EC2 instance:

$ ssh-keygen -b 4096 -t rsa -f ~/.ssh/$(whoami)-<suffix-for-ec2-environment>
$ ssh-keygen -t rsa -b 4096 -C "<your_email>"
$ aws ec2 describe-instances --instance-ids i-2a85b2c0 i-2cb27669  --profile <PROFILE_NAME>

Describe AMIs

$ aws ec2 describe-images --image-ids ami-7923a66e --profile <PROFILE_NAME>

AWS Kinesis

$ aws --profile <PROFILE_NAME> kinesis list-streams
$ aws --profile <PROFILE_NAME> kinesis describe-stream --stream-name <YOUR_STREAM_NAME>
$ aws kinesis get-shard-iterator --shard-id shardId-000000000000 --shard-iterator-type TRIM_HORIZON --stream-name <YOUR_STREAM_NAME> --profile <PROFILE_NAME>
$ KINESIS_SHARD_ITERATOR=$(aws kinesis get-shard-iterator --shard-id shardId-000000000000 --shard-iterator-type TRIM_HORIZON --stream-name <YOUR_STREAM_NAME> --query 'ShardIterator' --profile <PROFILE_NAME>)
$ echo $KINESIS_SHARD_ITERATOR
$ aws kinesis get-records --shard-iterator $KINESIS_SHARD_ITERATOR --profile <PROFILE_NAME>
$ aws kinesis get-records --shard-iterator $KINESIS_SHARD_ITERATOR --profile <PROFILE_NAME> --limit 2

AWS S3

List S3 buckets

$ aws s3 ls --profile <PROFILE_NAME>

Download a file from a bucket

$ aws s3 --profile <PROFILE_NAME> cp s3://<HOST_NAME>/<PATH>/foo.gz ~/foo.gz

Upload a file to a bucket

$ aws s3 --profile <PROFILE_NAME> cp s3://<HOST_NAME>/<PATH>/foo.gz . # copy from a remote bucket to here
$ aws --profile <PROFILE_NAME> s3 cp <LOCAL_FILE>.gz s3://<BUCKET_NAME>/ # copy from a local file to another remote bucket

Security groups

$ aws ec2 describe-security-groups --group-names <SECURITY_GROUP_NAME> --profile <PROFILE_NAME>

Load balancers

$ aws elb describe-load-balancers --load-balancer-name <SECURITY_GROUP_NAME> --profile <PROFILE_NAME>

SNS

$ aws sns list-topics --profile <PROFILE_NAME>
$ aws sns get-topic-attributes --topic-arn "arn:aws:sns:us-east-1:945109781822:<custom_suffix>" --profile <PROFILE_NAME>
$ aws sns list-subscriptions --profile <PROFILE_NAME>
$ aws sns get-subscription-attributes --subscription-arn "arn:aws:sns:us-east-1:945109781822:<custom_part>:6d92f5d3-f299-485d-b6fb-1aca6d9a497c" --profile <PROFILE_NAME>

CloudWatch

$ aws cloudwatch describe-alarms --alarm-names <CUSTOM_NAME> --profile <PROFILE_NAME>

Logs

$ aws logs get-log-events --log-group-name '/aws/lambda/<CUSTOM_SUFFIX>' --log-stream-name '2016/06/16/[$LATEST]283ba30f8dcb44268f7090c2b7f38b5b' --output text --profile <PROFILE_NAME> > a.log 

AWS Lambda

$ aws lambda get-function-configuration --function-name <CUSTOM_FUNCTION_NAME> --profile <PROFILE_NAME>

IAM Roles

Describe a role

$ aws iam get-role --role-name <ROLE_NAME> --profile <PROFILE_NAME>

Describe a policy associated with that role

$ aws iam get-role-policy --role-name <ROLE_NAME> --policy-name <POLICY_NAME> --profile <PROFILE_NAME>

Autoscaling

Describe launch configurations

$ aws autoscaling describe-launch-configurations --launch-configuration-names <CUSTOM_CONFIGURATION_NAME> --profile <PROFILE_NAME>

Describe autoscaling groups

$ aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name <CUSTOM_AG_NAME> --profile <PROFILE_NAME>

Describe autoscaling policies

$ aws autoscaling describe-policies --auto-scaling-group-name <CUSTOM_AG_NAME> --profile <PROFILE_NAME>

RDS

RDS is the MySQL version on Amazon.

$ aws rds describe-db-security-groups --db-security-group-name <DB_SG_NAME> --profile <PROFILE_NAME>
$ aws rds describe-db-instances --db-instance-identifier <DB_INSTANCE_ID> --profile <PROFILE_NAME>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment