AWS CLI 2 cheatsheet

AWS CLI 2: EC2, Lambda and logs

7 common AWS CLI 2 tasks.

List instances

Show instance IDs and states as a table.

aws ec2 describe-instances --query "Reservations[].Instances[].[InstanceId,State.Name]" --output table

Start an instance

Start a stopped instance.

aws ec2 start-instances --instance-ids i-0123456789abcdef0

Stop an instance

Stop a running EC2 instance.

aws ec2 stop-instances --instance-ids i-0123456789abcdef0

Invoke a Lambda function

Call a function and write the response to a file.

aws lambda invoke --function-name my-function out.json

List Lambda functions

Show the names of functions in the region.

aws lambda list-functions --query "Functions[].FunctionName"

Follow CloudWatch logs

Stream a CloudWatch log group live.

aws logs tail /aws/lambda/my-function --follow

Deploy a CloudFormation stack

Create or update a stack from a template.

aws cloudformation deploy --template-file template.yaml --stack-name my-stack --capabilities CAPABILITY_IAM

Was this page helpful?