Difference between revisions of "AWS/CLI"
From Christoph's Personal Wiki
Line 29: | Line 29: | ||
resourceType = 'AWS::EC2::Instance' | resourceType = 'AWS::EC2::Instance' | ||
AND tags.key NOT LIKE 'owner' | AND tags.key NOT LIKE 'owner' | ||
+ | </pre> | ||
+ | |||
+ | * Tag: | ||
+ | <pre> | ||
+ | $ aws ec2 run-instances \ | ||
+ | --image-id ami-abc12345 \ | ||
+ | --count 1 \ | ||
+ | --instance-type t2.micro \ | ||
+ | --key-name my-ssh-key \ | ||
+ | --subnet-id subnet-aaaaaaaa \ | ||
+ | --tag-specifications 'ResourceType=instance,Tags=[{Key=webserver,Value=production}]' 'ResourceType=volume,Tags=[{Key=cost-center,Value=cc123}]' | ||
</pre> | </pre> | ||
Revision as of 16:54, 3 March 2021
This article will contain a (random) collection of Amazon Web Services - Command Line Interface (AWS CLI) tips-and-tricks. It will also have examples using boto
and other miscellaneous tips-and-tricks.
- Find all AWS resources that do not have a tag with a key of "
project
" assigned to them:
$ aws resourcegroupstaggingapi get-resources --tags-per-page 100 --output json |\ jq '.ResourceTagMappingList[] | select(contains({Tags: [{Key: "project"} ]}) | not)' { "ResourceARN": "arn:aws:ec2:us-west-2:0000000:security-group/sg-1aaaaaaa", "Tags": [ { "Value": "xtof-aws-dev-sg", "Key": "Name" } ] }
- If you have AWS Config setup, you can do advanced SQL-like queries:
SELECT resourceId, resourceType, configuration.instanceType, configuration.placement.tenancy, configuration.imageId, tags, availabilityZone WHERE resourceType = 'AWS::EC2::Instance' AND tags.key NOT LIKE 'owner'
- Tag:
$ aws ec2 run-instances \ --image-id ami-abc12345 \ --count 1 \ --instance-type t2.micro \ --key-name my-ssh-key \ --subnet-id subnet-aaaaaaaa \ --tag-specifications 'ResourceType=instance,Tags=[{Key=webserver,Value=production}]' 'ResourceType=volume,Tags=[{Key=cost-center,Value=cc123}]'