Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

259
Vistas
Invoking second async function in lambda not invoking

I am using serverless to deploy aws lambdas. Currently my set up is that api gateway triggers one lambda then I async invoke another lambda.

serverless.yml

service: scraper
useDotenv: true #added this because deprecation notice
frameworkVersion: '2'

provider:
  name: aws
  runtime: nodejs14.x
  lambdaHashingVersion: 20201021
  stage: prod
  region: us-east-2

functions:
  scraperRunner:
    handler: handler.scraperRunner
    provisionedConcurrency: 0
    timeout: 90
    events:
      - http:
          path: process/run
          method: post
          async: true
  runTargetSite:
    handler: handler.runTargetSite

plugins:
 - serverless-offline

then I have a handler.js file where I define both handler functions:

'use strict';

const startScraper = require('./crawler/runner');
const AWS = require('aws-sdk');
AWS.config.region = 'us-east-2';
const lambda = new AWS.Lambda();

function processResponse(msg, statusCode, event) {
    return {
        statusCode: statusCode,
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Headers': 'Content-Type',
            "Access-Control-Allow-Methods": "OPTIONS,POST,GET"
        },
        body: JSON.stringify({
            message: msg,
            input: event
        })
    }
}


module.exports.scraperRunner = async (event) => {
    if (event) {
        const data = event;
        if (data.hasOwnProperty('target_id')) {

            const prov = [<array of objects>]

            for (const p of prov) {
                data['target'] = p.name
                const params = {
                    FunctionName: 'provider-scraper-prod-runTargetSite',
                    InvocationType: 'Event',
                    // LogType: 'Tail',
                    Payload: JSON.stringify(data)
                };

                await lambda.invoke(params).promise()
            }
            return processResponse(
                'Event successfully received',
                200, event)

        }
    }

    return processResponse(
        'Invalid body payload',
        402, event)
};

module.exports.runTargetSite = async function(event, context) {
    await startScraper(event)
    return processResponse(
        'Event successfully received for runTargetSite',
        200, event)
}

enter image description here

I've also added the necessary roles (I think):

  • AWSLambdaExecute
  • AWSLambdaBasicExecutionRole
  • AWSLambdaRole
  • InvokeFunction
  • InvokeAsync

Using the command line, I'm able to call the first lambda which then calls the second:

serverless invoke local --function scraperRunner --data '{"target": "_tpp_"}'

However when submitting a post request to the API Gateway endpoint, the first lambda (scraperRunner) triggers but the second one is not invoked.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda