Forked from monkut/update_awslambda_envars.bash
Last active
January 16, 2021 07:55
-
-
Save fizz/f455843d72afa0e661463ffe47106338 to your computer and use it in GitHub Desktop.
update aws lambda environment variables via awscli and jq
This file contains hidden or 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
#!/usr/bin/env bash | |
# 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 | |
FUNCTION_NAME=trip-analytics-prod-app | |
UPDATED=.env.prod | |
UPDATE=$(jq --raw-input --slurp 'split("\n")[:-1]|map(split("=") as [$key, $value] | {$key, $value}) | from_entries' $UPDATED) | |
export UPDATED_ENVIRONMENT_VARIABLES=$(aws --region us-west-2 lambda get-function-configuration --function-name ${FUNCTION_NAME} | \ | |
jq --compact-output ".Environment + {\"Variables\": (.Environment.Variables + ${UPDATE})}") | |
# check | |
env | grep UPDATED_ENVIRONMENT_VARIABLES | |
# update current lambda configuration | |
aws --region us-west-2 lambda update-function-configuration --function-name ${FUNCTION_NAME} \ | |
--environment ${UPDATED_ENVIRONMENT_VARIABLES} | jq .Environment.Variables |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment