27

I just want to get back a list of function names. Ideally I want to get all functions (just their name) starting with "some-prefix*". Can I do this with the cli?

Really want this as a cli command if possible (I want to avoid python or another sdk). I see there is a --cli-input-json arg, can I use that for filtering?

3
  • What about piping the result through jq? Commented Jan 22, 2018 at 16:52
  • No, that function does not allow you to request only those Lambda function whose names begin with given prefix. You'll have to get them all and the filter out the ones you don't want. Commented Jan 22, 2018 at 16:57
  • In addtion my recomendation is to use aws-shell, the interactive productivity booster for the AWS CLI. The auto-completion and the history function make life very relaxed. ![example of list functions](i.sstatic.net/Ho7Qj.png) Commented Feb 14, 2020 at 8:18

5 Answers 5

59

You can do that. Use the --query option. The CLI would look like this:

aws lambda list-functions --region us-east-1 --query 'Functions[].FunctionName' --output text

To get the list of functions whose name begin with some-prefix:

aws lambda list-functions --region us-east-1 --query 'Functions[?starts_with(FunctionName, `some-prefix`) == `true`].FunctionName' --output text

To get the complete JSON, the CLI would be:

aws lambda list-functions --region us-east-1

Details about the query parameter can be found here.

Sign up to request clarification or add additional context in comments.

7 Comments

your my hero, but I have a question this command: aws lambda list-functions --region us-east-1 --query 'Functions[?starts_with(FunctionName, myfuncs) == true].FunctionName' --output text adds some whitespace between strings it returns. Can I choose the separator?
I am not sure if that's possible. What we do is: put this in a for loop so that we get the details line-by-line. If you print more than 1 item (in this case other than FunctionName, the CLI will return all the details for 1 function in 1 line.
@red888 aws lambda list-functions --region us-east-1 --query 'Functions[?starts_with(FunctionName, 'some-prefix-') == true].FunctionName' | jq '.[]' -r
or aws lambda list-functions --region us-east-1 --query 'Functions[?starts_with(FunctionName, 'some-prefix-') == true].FunctionName' | jq "join($SEPARATOR)"
In powerhsell, I used aws lambda list-functions --query "Functions[?starts_with(FunctionName, '$prefix')].FunctionArn" there was no need for == true
|
3

As the answer is already given by @krishna, but I was looking for a way to print all function name without specifying a prefix. So here you can get all lambda function name in particular region my default is us-west-2.

aws lambda list-functions  --query 'Functions[*].[FunctionName]' 

Or as I want them out in text format and space separated to use in my bash script so here you can get in text and single line space separated.

aws lambda list-functions --query 'Functions[*].[FunctionName]' --output text | tr '\r\n' ' '

Comments

1

I have come here for some help to clean up all lambda functions that I have created while following an AWS developer certification tutorial. If anyone is in the same boat, I have created a script to programmatically delete all lambda functions in my AWS account (NOT for production use)

#!/bin/bash
# STOP: DON'T USE/RUN THIS SCRIPT UNLESS YOU ARE 100% SURE WHAT YOU ARE DOING 
#       I am a learner and created 20+ lambda functions while following a tutorial 
#       I wrote this script to programatically cleanup functions at the end of course    
# precondition: your aws cli is configured 
# get all functions from aws account
functions=(`aws lambda list-functions --query 'Functions[*].[FunctionName]' --output text`)
for i in "${functions[@]}"
do
   #delete functions 1-by-1 
   aws lambda delete-function --function-name "$i"   
   echo "deleted $i"
done

Comments

0

You can easily get the list of all lambda functions in given region using below command:

aws lambda list-functions --region us-east-1 | jq -r .Functions[].FunctionName

Download the jq (Lightweight and flexible command-line JSON processor) from here: https://stedolan.github.io/jq/download/

Comments

0

Incase, someone is looking for a similar query with string present in the lambda function name as a substring, try below

aws lambda list-functions --region us-east-1 --query 'FunctionName[?contains(FunctionName, 'containing-string'] == 'true'].[FunctionName]' --output text

Note - the '[]' brackets around '.FunctionName' will provide with each fucntionName on a new line.

1 Comment

This answer cannot work. There are correct answers from 4 years earlier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.