On this weblog publish, I introduce a script that permits you to effectively handle the setting variables of an AWS Lambda operate.
This script gives the aptitude to:
- Register a brand new variable: Add a brand new setting variable to the Lambda operate.
- Replace an current variable: Modify the worth of an current setting variable.
- Delete a variable: Take away an setting variable from the Lambda operate.
Essential Be aware on Updating Setting Variables
When utilizing the aws lambda update-function-configuration
command to replace the prevailing setting variables, it’s essential to cross each the setting variable you wish to add or replace and all current setting variables. Failing to take action will consequence within the deletion of the prevailing setting variables. The script offered on this weblog publish takes this into consideration and ensures the right dealing with of setting variables throughout the replace course of.
Parameters
function_name
: The title of the Lambda operate.
area
: The AWS area the place the Lambda operate is deployed.
env_vars_upsert
: Key-value pairs of setting variables to be upserted (up to date or inserted).
-
Through the upsert course of, the setting variable shall be up to date if it exists; in any other case, a brand new one shall be registered.
-
You may embrace any variety of key-value pairs.
env_vars_upsert=(
"MY_ENV1" "value1"
"MY_ENV2" "value2"
)
env_vars_remove
: Keys of setting variables to be eliminated.
- If the required key doesn’t exist, nothing will occur.
env_vars_remove=("MY_ENV3" "MY_ENV4")
Output
The script will response in JSON format. The “Setting” part will show the up to date state of the setting variables.
{
"FunctionName": "xxxx",
...
"Setting": {
"Variables": {
"MY_ENV2": "value2",
"MY_ENV1": "value1"
}
},
...
}
Abstract
I launched a shell script for managing AWS Lambda environmental variables, enabling customers to register, replace, and delete variables with ease. This script additionally takes into consideration the prevention of unintentional deletions, making certain protected and environment friendly administration of your Lambda operate’s environmental variables.
Warning
Earlier than utilizing this script in a manufacturing setting, please create a check Lambda operate and check it completely to make sure it really works as anticipated.