12
votes

The documentation on the AWS cil lambda states that

...You provide only the parameters you want to change...

Which I assume means that the rest of the settings would still remain the same. However, say my lambda function has environment variables :

var1=old_val1
var2=old_val2
var3=old_val3

and then when I try doing something like this :

aws lambda update-function-configuration --function-name dummy_fun --environment '{"Variables":{"var1":"new_val1","var2":"new_val2"}}'

with the intention of updating the variables : var1 and var2 with the new values new_val1 and new_val2 respectively, although these 2 variables DO get updated, but the third one, var3, gets deleted !

Am I doing something wrong ? Or is there a way to make sure this doesn't happen?

I can definitely handle it using a workaround wherein I can fetch the current config and then update the env variables locally and then push the entire updated config, all of this through a python code etc. But, is that the only way to do it ? Or can there be a simpler way of doing it?

3

3 Answers

9
votes

You are misinterpreting the intention of the documentation.

You provide only the parameters you want to change.

--environment is the (singular) "parameter" that you are specifying should be changed -- not the individual variables.

The environment variables are configured en bloc so there is no concept of specifying only certain environment variables that you want to be different.

5
votes
aws lambda update-function-configuration --function-name my-function-name --environment Variables="{VAR1=variable_value, VAR2=variable_value}" 

Description:Above Command will update the environment variables for the lambda function in aws.

1
votes

I had the same problem where I wanted to update only one env variable of a function and not touch the rest.

I ended up writing a script in node and publishing it:

https://www.npmjs.com/package/aws-lambda-update-env

It is pretty simple to use:

update-lambda-env KEY "My New Test Value" --stack-name myApplicationStack

This will only change the variable KEY in the functions located in the stack myApplicationStack

A better solution might be to use AWS Parameter Store if your variable is going to change often.

https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html