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

149
Vistas
AWS Lambda - Only getting answer after the second test trigger

I'm developing an AWS Lambda in TypeScript that uses Axios to get data from an API and that data will be filtered and be put into a dynamoDb.

The code looks as follows:

export {};
const axios = require("axios");
const AWS = require('aws-sdk');

exports.handler = async (event: any) => {
    const shuttleDB = new AWS.DynamoDB.DocumentClient();
    const startDate = "2021-08-16";
    const endDate = "2021-08-16";
    const startTime = "16:00:00";
    const endTime = "17:00:00";

    const response = await axios.post('URL', {
        data:{
            "von": startDate+"T"+startTime,
            "bis": endDate+"T"+endTime
        }}, {
            headers: {
            'x-rs-api-key': KEY
            }
        }
    );
    const params = response.data.data;
    const putPromise = params.map(async(elem: object) => {
        
        delete elem.feat1;
        delete elem.feat2;
        delete elem.feat3;
        delete elem.feat4;
        delete elem.feat5;
        
        const paramsDynamoDB = {
            TableName: String(process.env.TABLE_NAME),
            Item: elem
        }
        shuttleDB.put(paramsDynamoDB).promise();
    });
    await Promise.all(putPromise);
};

This all works kind of fine. If the test button gets pushed the first time, everything seems fine and is working. E.g. I received all the console.logs during developing but the data is not put into the db.

With the second try it is the same output but the data is successfully put into the Db.

Any ideas regarding this issue? How can I solve this problem and have the data put into the Db after the first try?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you need to return the promise from the db call -

return shuttleDB.put(paramsDynamoDB).promise();

also, Promise.all will complete early if any call fails (compared to Promise.allSettled), so it may be worth logging out any errors that may be happening too.

Better still, take a look at transactWrite - https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#transactWrite-property to ensure all or nothing gets written

about 4 years ago · Juan Pablo Isaza Denunciar
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