Created
January 11, 2020 05:11
-
-
Save monkut/bb8a01738bf109e9f186129df2e6688b to your computer and use it in GitHub Desktop.
update aws lambda environment variables via awscli and jq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the `update-function-configuration` overwrites the existing set envars. | |
# In order to *ADD* variables we need to read the existing envars and add to that. | |
# This command uses `jq` to read and transform the json result to an envar then update the lambda configuration | |
# create the updated envar set | |
export YOUR_FUNCTION_NAME={populate this} | |
export UPDATED_ENVIRONMNET_VARIABLES=$(aws lambda get-function-configuration --function-name ${YOUR_FUNCTION_NAME} | \ | |
jq --compact-output ".Environment + {\"Variables\": (.Environment.Variables + {\"NEW_ENVAR_NAME\": \"NEW_ENVAR_VALUE\"})}") | |
# check | |
env | grep UPDATED_ENVIRONMNET_VARIABLES | |
# update current lambda configuration | |
aws lambda update-function-configuration --function-name ${YOUR_FUNCTION_NAME} \ | |
--environment ${UPDATED_ENVIRONMNET_VARIABLES} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment