Skip to content

Instantly share code, notes, and snippets.

@monkut
Created January 11, 2020 05:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save monkut/bb8a01738bf109e9f186129df2e6688b to your computer and use it in GitHub Desktop.
Save monkut/bb8a01738bf109e9f186129df2e6688b to your computer and use it in GitHub Desktop.
update aws lambda environment variables via awscli and jq
# 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