AWS CLI cheatsheet

Install amazon lambda tools and templates

dotnet tool install --global Amazon.Lambda.Tools
dotnet new --install Amazon.Lambda.Templates

Authenticate to AWS with SSO

Check profiles already available locally

aws configure list-profiles

#or
cat ~/.aws/config

Authenticate a profile, in this case aws-profile to connect to corresponding account

aws sso login --profile aws-profile
# test by listing s3 buckets
aws s3 ls --profile aws-profile
#or
dotnet lambda list-functions

Lambda function - download package

Get the url to download the zip package

aws lambda get-function --profile AWS_PROFILE --function-name FUNCTION_NAME --query 'Code.Location' --output text

Invoke lambda function

aws lambda invoke --profile AWS_PROFILE --function-name FUNCTION_NAME output-file --log-type Tail  --query 'LogResult' --output text |  base64 -d

login docker to private aws registry ECR

aws sso login --profile PROFILE
aws ecr get-login-password --region REGION --profile PROFILE | docker login --username AWS --password-stdin ECR

# e.g:
aws sso login --profile
aws ecr get-login-password --region eu-central-1 --profile aws-infrastructure | docker login --username AWS --password-stdin 258781458051.dkr.ecr.eu-central-1.amazonaws.com