Commands tagged awscli (6)

  • You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials Show Sample Output

    head -n1 | xargs -I {} aws sts get-session-token --serial-number $MFA_ID --duration-seconds 900 --token-code {} --output text --query [Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]
    keymon · 2016-04-12 10:57:00 0
  • Frustrated with the manual domain migration process AWS has, I unsuccessfully tried to install cli53, route53-transfer. I instead wrote this oneliner to ease the export (which is not supported via the AWS console ATM). The output can be easily pasted into the "Import Hosted Zone" dialog in Route53. SOA/NS records are excluded since they cannot be automatically imported. Show Sample Output

    echo -e "\$ORIGIN\\n\$TTL\t1h\n" && aws route53 list-resource-record-sets --hosted-zone-id Z1EEXAMPLE9SF3 | jq -r '.ResourceRecordSets[] | [.Name, .Type, .ResourceRecords[0].Value] | join("\t")' - | grep -vE "NS|SOA"
    brainstorm · 2018-06-15 01:19:21 0
  • Following in the steps of a few other scripts on here, I thought I'd mix in the ability to add in an instance tag output into this. This can be super useful if you are using the "Name" tag as a hostname tag and feeding that into, say Route53 for DNS to reach the machine. Helps for scripting against later. Show Sample Output

    aws ec2 describe-instances --filters "Name=vpc-id,Values=<replace_with_id>" --query 'Reservations[].Instances[].[ [Tags[?Key==`Name`].Value][0][0],PrivateIpAddress,InstanceId,State.Name,Placement.AvailabilityZone ]' --output table
    fydgit · 2015-08-27 21:52:58 0
  • Looking up the id of a CF domain can be painful. Not anymore with this tip. Show Sample Output

    aws cloudfront list-distributions | jq -r '.DistributionList | .Items | .[] | .Id + " " + .Aliases.Items[]'
    hendry · 2016-09-19 06:36:59 0
  • This allows you to get all instance profiles (roles) for a given set of tags. Lists it in CSV Show Sample Output

    aws ec2 describe-instances --region us-east-1 --filters "Name=tag:YourTag,Values=YourValue" | jq '.["Reservations"]|.[]|.Instances|.[]|.IamInstanceProfile.Arn + "," +.InstanceId'
    symgryph · 2019-04-15 16:33:41 1
  • AWS provides a method to audit for obsolete AWS security groups. From their documentation: "Describes the stale security group rules for security groups in a specified VPC. Rules are stale when they reference a deleted security group in a peer VPC, or a security group in a peer VPC for which the VPC peering connection has been deleted." Show Sample Output

    aws ec2 describe-vpcs --query 'Vpcs[*].VpcId' --output text |xargs -t -n1 aws ec2 describe-stale-security-groups --vpc-id
    vocatan · 2019-09-09 18:54:08 2

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Debug your makefile
Say your dependencies specified in your Makefile (or dates on your source files) is causing 'make' to skip some source-files (that it should not) or on the other other end, if it is causing make to always build some source-files regardless of dates of target, then above command is handy to find out what 'make' thinks of your date v/s target date-wise or what dependencies are in make's view-point. The egrep part removes the extra noise, that you might want to avoid.

Remove last line from files recursively
Used this command recently to remove the trailing ?> from all the files in a php project, which has having some unnecessary whitespace issues. Obviously, change *.php to whatever you'd like.

Find the package that installed a command

Shows what processes need to be restarted after system upgrade
This command can be installed in debian by the package debian-goodies. It also outputs the /etc/init.d/ commands that you need to do.

grep -v with multiple patterns.
Use multiple patterns with grep -v. So you can print all lines in a file except those containing the multiple patterns you specify.

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

check open ports without netstat or lsof

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Search some text from all files inside a directory

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: