Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws lambda list-functions filter out just function names?

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?

like image 310
red888 Avatar asked Jan 22 '18 16:01

red888


3 Answers

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.

like image 184
krishna_mee2004 Avatar answered Nov 07 '22 17:11

krishna_mee2004


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' ' '

like image 40
Adiii Avatar answered Nov 07 '22 18:11

Adiii


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
like image 23
bp4D Avatar answered Nov 07 '22 17:11

bp4D