Skip to content

Instantly share code, notes, and snippets.

@dfang
Last active August 14, 2020 03:04
Show Gist options
  • Save dfang/30e868e4b9bb14209a649bac624c2480 to your computer and use it in GitHub Desktop.
Save dfang/30e868e4b9bb14209a649bac624c2480 to your computer and use it in GitHub Desktop.
aws cli tips
aws ec2 describe-regions --output table

for region in `aws ec2 describe-regions --output text | cut -f4`
do
     echo -e "\nListing Instances in region:'$region'..."
     aws ec2 describe-instances --region $region | jq '.Reservations[] | ( .Instances[] | {state: .State.Name, name: .KeyName, type: .InstanceType, key: .KeyName})'
done


aws ec2 describe-instances --query 'Reservations[].Instances[].[State.Name,InstanceType]'
aws ec2 describe-images \
 --filters Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64* \
 --query 'Images[*].[ImageId,CreationDate]' --output text \
 | sort -k2 -r \
 | head -n1


aws ec2 describe-images \
 --owners self amazon \
 --query 'Images[*].[ImageId,Architecture,PlatformDetails,ImageOwnerAlias,RootDeviceType,CreationDate]' --output text
 --filters Name=name,Values=ubuntu*-amd64* \


aws ec2 describe-images --owner amazon --filter "Name=description,Values=*Ubuntu*" "Name=owner-alias,Values=amazon" "Name=architecture,Values=x86_64" "Name=virtualization-type,Values=hvm"

aws ec2 run-instances --image-id --instance-type t2.micro

aws ec2 run-instances --image-id ami-xxxxxxxx --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-903004f8 --subnet-id subnet-6e7f829e
aws ec2 run-instances --image-id ami-067f5c3d5a99edc80 --key-name aws --instance-type t2.micro --region us-east-1 --subnet-id your-subnet-id --count 1

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html#finding-quick-start-ami

invoke lambda in aws cli 2

AWS_REGION=us-east-1 aws lambda invoke \
                      --function-name goad \
                      --invocation-type Event \
                      --payload file://payload.json \
                      --cli-binary-format raw-in-base64-out \
                      out.txt

if payload is long enough, just put it in payload.json, and use --cli-binary-format raw-in-base64-out 如果payload的内容很长,可以将其存储在payload.json里,然后用--cli-binary-format raw-in-base64-out

AWS V2 defaults to base 64 input. For your case to work, simply add a --cli-binary-format raw-in-base64-out parameter to your command.

aws/aws-cli#4389 (comment)

Understanding the Different Ways to Invoke Lambda Functions

in aws cli 2, just use

AWS_REGION=us-east-1 aws logs describe-log-groups
aws logs tail <YOUR-LOG-GROUP-NAME>

no need to install awslogs anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment