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

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

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 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