Skip to content

Instantly share code, notes, and snippets.

@SteveHoggNZ
Last active June 24, 2020 21:44
Show Gist options
  • Save SteveHoggNZ/4654aebce4b63450cb91afcaf2f591a3 to your computer and use it in GitHub Desktop.
Save SteveHoggNZ/4654aebce4b63450cb91afcaf2f591a3 to your computer and use it in GitHub Desktop.
Examples of AWS CLI using JQ
# jq reference: https://stedolan.github.io/jq/manual
# Get a list of each Lambda function that starts with ^test and output that as an array
# i.e. take the contents of the .Functions[] list, select the ones that have a .FunctionName property that
# starts with test, and record the .FunctionName value
aws lambda list-functions | jq '[ .Functions[] | select(.FunctionName | test("^test")) | .FunctionName ]'
# Create an array of new maps for Lambda functions
aws lambda list-functions | jq '[ .Functions[] | select(.FunctionName | test("^test")) | {name: .FunctionName, memory: .MemorySize} ]'
# Same as above, but with the function name as the key
aws lambda list-functions | jq '[ .Functions[] | select(.FunctionName | test("^test")) | {(.FunctionName): .MemorySize} ]'
# Sort the array by memory size. group_by(.memory) will give you a list of lists grouped by the memory value
aws lambda list-functions | jq '[ .Functions[] | select(.FunctionName | test("^test")) | {name: .FunctionName, memory: .MemorySize} ] | sort_by(.memory)'
# Maybe useful? Append a suffix to a value
aws lambda list-functions | jq '.Functions[] | select(.FunctionName | test("^test")) | .FunctionName |= . + "-mysuffix" | .FunctionName'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment