AWS CLI CheatSheet
?
R
BashSome AWS CLI commands which I run frequently. This topic is continuously being updated.
1# Sign S3 files to share
2aws s3 ls s3://mybucket/1/2/ --page-size=30
3aws s3 presign s3://mybucket/1/2/file.txt --expires-in 604800
4
5# Update K8s
6aws eks --region eu-west-2 update-kubeconfig --name strike-fighter
7
8# AWS CLI
9aws --version
10
11# Show configuraton details
12aws sts get-caller-identity
13
14## AWS IAM
15aws configure
16aws iam list-users
17aws iam list-roles
18aws iam list-account-aliases
19aws iam delete-server-certificate --server-certificate-name xpto-io-2017
20aws iam list-server-certificates
21#### Upload SSL Certificates (to use on ELB Listeners)
22aws iam upload-server-certificate --server-certificate-name coderecipes2019 \
23 --certificate-body file://coderecipes.crt --private-key file://coderecipes.key
24#### Download
25aws iam get-server-certificate --server-certificate-name coderecipes2019
26
27## AWS S3
28## List all buckets
29aws ls
30## Creat a bucket
31aws s3api create-bucket --bucket coderecipes-mail-templates --create-bucket-configuration LocationConstraint=eu-west-1
32## Upload all files in a folder over to a bucket
33aws s3 cp . s3://my-folder-name --recursive
34
35## AWS Lambda
36Create a Lambda Function from a zip (without invocation triggers)
37
38```bash
39aws lambda create-function \
40--function-name coderecipes-mailer \
41--runtime python2.7 \
42--role arn:aws:iam::XXX:role/mailer \
43--handler index.handler \
44--zip-file fileb://./package.zip
45```
46
47Add a trigger
48
49```bash
50aws lambda add-permission \
51--function-name coderecipes-mailer \
52--statement-id 1 \
53--action 'lambda:InvokeFunction' \
54--principal events.amazonaws.com \
55--source-arn arn:aws:events:eu-west-1:XXX:rule/morning
56```
57
58Add a target to the event
59
60```bash
61aws events put-targets \
62--rule morning \
63--targets '{"Id" : "1", "Arn": "arn:aws:lambda:eu-west-1:XXX:function:coderecipes-mailer"}'
64```
65
66Set metadata on all S3 files
67```bash
68aws s3 cp s3://mybucket/ s3://mybucket/ --recursive --metadata-directive REPLACE \
69--expires 2034-01-01T00:00:00Z --acl public-read --cache-control max-age=0,public
70```Created on 11/1/2017