Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
Change value of environment variable while invoking Lambda function

I am learning lambda and currently trying to understand the environment variables. Below is a very simple code to show my question. (A nodejs function that will simply print the value of name constant).

exports.handler =  async function(event, context) {
   
   const name = process.env.NAME;
    return name;
  
};

I have already defined a environment variable on lambda as following

enter image description here

Now this lambda will surely print "xyz" after completion. But how we can overwrite/change the value of the "Name" variable while running the Lambda. so while invoking it will show the new value? For example something like --NAME = "abc" or --NAME abc

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

From AWS Knowledge Center: Can I change the environment variables in a published version of my Lambda function?:

You can't change the configuration (including environment variables) or function code in a published Lambda function version. You can only change the current, unpublished function version ($LATEST).

So, short of having your Lambda connect to the AWS API and publish a completely new version of itself, you can't.

You seem to be trying to use environment variables as a local storage space which, fundamentally, they aren't. You'd probably be better off with a database. I'd look to use DynamoDB for this.

about 4 years ago · Juan Pablo Isaza Report

0

From the original question and the comments I gathered the following requirements for your Lambda:

  1. You want to talk to the Route53 API.
  2. You want to parameterise the Lambda to allow passing a domain name to the Lambda on every invocation.

The easiest and probably most fitting way to achieve this is to pass the domain as "event" data on every invocation.

exports.handler = async (event) => {
    const domain = event["domain"];
    console.log("Domain: %s", domain);

    // your Route53 code goes here...
};

To run the Lambda and pass the "domain" you have a lot of options.

Option 1: AWS Console

You can go to the AWS console, open the Lambda, switch to the "Test" tab and just use the following input JSON:

{
  "domain": "www.google.com"
}

Invoke Lambda in AWS Console

Option 2: AWS CLI v2

From the command line you could invoke that Lambda using the AWS CLI.

aws \
    lambda \
    invoke \
    --cli-binary-format raw-in-base64-out \
    --function-name <function-name> \
    --payload '{"domain":"www.google.com"}' \
    outfile.txt

Option 3: AWS SDK

You can also write some code in a other Lambda, in a script on your local machine or any other way that can use the AWS Lambda and invoke the Lambda like this.

The following is an example of simple NodeJS CLI "code" using the v3 of the AWS SDK.

import { LambdaClient, InvokeCommand } from "@aws-sdk/client-lambda";

async function main() {
    const client = new LambdaClient({ region: "<your-region>" });

    const payload = JSON.stringify({
        "domain": "www.google.com"
    });

    const input = {
        "FunctionName": "<function-name>",
        "Payload": payload
    };
    
    const command = new InvokeCommand(input);
    const response = await client.send(command);
    
    console.log(response);
}

main()

If you run node index.js you will invoke the Lambda with the given payload.

To setup node:

npm init
npm install @aws-sdk/client-lambda

Remember to set type to module in the package.json.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!