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

226
Views
convert nodejs function to AWS Lambda compatible

I am pretty new to both nodejs and AWS Lambda. I have created a very small nodejs function that is working fine locally. Now I need to run it on AWS Lambda, but looks like there are some handlers requirement which I am not understanding completely.

Below is my nodejs function that I need to run it on Lambda. Any idea what changes do I need to make to execute it on AWS? Thanks

(async function () {
DOMAIN = "abc.xyz.com";
KEY = "***";
const mailchimpClient = require("@mailchimp/mailchimp_transactional")(KEY);
    const run = async () => {
          const response = await mailchimpClient.senders.addDomain({
            domain: DOMAIN,
          });
          console.log(response);
        };
        
        run();
})();
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Basically you just need to export a function with a specific name: handler

exports.handler =  async function(event, context) {
  console.log("EVENT: \n" + JSON.stringify(event, null, 2))
  return "foo.bar"
}

In this handler, you just need to return something to mark as success or throw an error to mark as failure.

In your case, this should work:

var DOMAIN = "abc.xyz.com";
var KEY = "***";
const mailchimpClient = require("@mailchimp/mailchimp_transactional")(KEY);

exports.handler =  async function(event, context) {
  const response = await mailchimpClient.senders.addDomain({
    domain: DOMAIN,
  });
  console.log(response);
  return "success"
}

Here more examples and advanced configurations:

  • https://docs.aws.amazon.com/lambda/latest/dg/lambda-samples.html
  • https://github.com/awsdocs/aws-lambda-developer-guide/blob/main/sample-apps/blank-nodejs/function/index.js
  • https://github.com/awsdocs/aws-lambda-developer-guide/blob/main/sample-apps/nodejs-apig/function/index.js
about 4 years ago · Juan Pablo Isaza Report

0

It depends if you are using any framework to create your aws serverless code.

However, your usual code would be somthing like this.

    exports.handler = function(event, context) {
      console.log('Lambda A Received event:', JSON.stringify(event, null, 2));
      context.succeed('Hello ' + event.name);
    };

If you want a easier way to work with AWS serverless code such as Lambdas look at arc.codes

Also, here is a link to the AWS docs https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html

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!