I have AWS account with huge amount of AWS Lambda functions and I'd like to check all environment variables of all functions and try to find functions which use some specific values there. How can I to do that without manual checking of each function in AWS console? Does AWS CLI allow that?
Your function uses the name of the key to retrieve the value of environment variable. Open the Functions page of the Lambda console. Choose a function. Choose Configuration, then choose Environment variables.
You can use the AWS Command Line Interface to manage functions and other AWS Lambda resources. The AWS CLI uses the AWS SDK for Python (Boto) to interact with the Lambda API.
To set environment variables Sign in to the AWS Management Console and open the Amplify console . In the Amplify console, choose App Settings, and then choose Environment variables. In the Environment variables section, choose Manage variables. In the Manage variables section, under Variable, enter your key.
Yes the AWS CLI allows you to check your Lambda environment variables. To automate it end to end you'll need to chain some commands together. Also, I defaulted to using jq
for the heavy lifting. I'm sure there is a way to do this in JMESPath but I didn't have time to figure it out.
Here's the overview of how it works:
list-functions
and pipe that list as text to xargs
get-function-configuration
.jq
, ensure the Environment
field is not null and search for the Variable you want. In this case I'm searching for a variable called customer
which has a value of shared_services
.The code:
aws lambda list-functions --query 'Functions[*].[FunctionName]' --output text | xargs -I {} aws lambda get-function-configuration --function-name {} | jq -r 'select((.Environment) and select(.Environment.Variables.customer == "shared_services"))| .FunctionName'
Output
copy_snaps_shared_services
snapshot_by_customer
References
JQ Manual
JQ Presence of Key before Iterating
AWS CLI Usage Examples
AWS Lambda Get Function Configuration
AWS Lambda List Functions
You should be able to use the AWS CLI get-function to get the meta about the Lambda function. The returned meta-data includes a presigned URL for downloading the deployment package. You can donwload the deployment package, unpack it, and search the source code for references to the environment variables you are looking for.
Take a look at this script to see how it can easily be done: https://gist.github.com/nemaniarjun/defdde356b6678352bcd4af69b7fe529
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With