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

139
Views
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 answers
Answer question

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