Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda