I have a scenario where I need to set an environment variable of one lambda from another. The first lambda is an s3 trigger that will handle a csv uploaded to s3. It will then create a table in Dynamo by generating the table name with timestamp appended. I want to be able to make this lambda set an environment variable of another lambda that will be consuming the newly created table. Is it possible to do it and if so how do we do it in NodeJs?
2
-
2This is almost certainly the wrong approach: it's equivalent to using global variables within your code, and if you ever have concurrent uploads it will cause problems (ever: even if you don't now, you might later).kdgregory– kdgregory2018-04-09 10:59:36 +00:00Commented Apr 9, 2018 at 10:59
-
2Why don't you want to simply invoke the second lambda from the first?kdgregory– kdgregory2018-04-09 10:59:52 +00:00Commented Apr 9, 2018 at 10:59
Add a comment
|
1 Answer
Yep this is possible.
For reference https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#updateFunctionConfiguration-property
var params = {
FunctionName: 'Your-Function-Name', /* required */
Environment: {
Variables: {
'TABLE_NAME': 'Your-New-Dynamo-Table-Name'
}
}
};
lambda.updateFunctionConfiguration(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
2 Comments
SRi
Is it recommended approach (or possible) to modify environment variables for a lambda from the execution of same lambda (lambda to change it's own environment variable)? I don't want any in between caching servers or DB.
CortexCompiler
Note that this will not modify the published version of the Lambda. The UpdateFunctionConfiguration docs say: "These settings can vary between versions of a function and are locked when you publish a version. You can't modify the configuration of a published version, only the unpublished version."