0

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
  • 2
    This 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). Commented Apr 9, 2018 at 10:59
  • 2
    Why don't you want to simply invoke the second lambda from the first? Commented Apr 9, 2018 at 10:59

1 Answer 1

5

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
});
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.