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

318
Views
Can't POST item to my DynamoDB table with axios

I’m trying to POST an item in VS Code to my DynamoDB table via axios. I’m able to POST an item successfully via Postman, however when I try to POST an item with axios I get a 404 response error (below).

enter image description here

I’m wondering if I’m missing something when trying to POST an item via axios (below).

axios({
    'method': 'post',
    'url': 'https://na9blqj5y5.execute-api.us-east-1.amazonaws.com/test',
    'Content-Type': 'application/json',
    'data': {
      'body': eraseThis,
    }
  })
  .then((response) => {
    return console.log('axiosResp', response);
  })
  .catch((err) => console.error('axios', err))

One thought that I had is that I should be importing the AWS SDK and invoke my lambda function with my credentials from that (below)? Any help would be greatly appreciated!

enter image description here

This is a successful POST request in Postman.

enter image description here

Now I'm getting a CORS error I had a few weeks ago (even after enabling CORS on the API resource in the API Gateway interface).

enter image description here

Below is the updated code using the aws-sdk

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your examples are hard to follow because they don't match.

  • first screenshot url is a different api gateway endpoint address than the postman screenshot
  • first uses the /test stage and the 2nd uses a /prod/customer

So right off I'm wondering if you just have different code deployed to different stages? Assuming you've ruled that out though and that's not the case I think what you mean to say is that your axios call made via browser fails whereas postman works.

That's actually expected behavior because postman isn't a browser and bypasses the CORS restrictions that browsers implement. There are plenty of existing questions here that explain that so I'm not going into that further.

I believe the fix for this is to update your lambda handler (the actual lambda proxy that returns a response) to always return a Access-Control-Allow-Origin header as documented by AWS here. To allow all origins you can use a wildcard *. ex:

headers: {
        "Access-Control-Allow-Headers" : "Content-Type",
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "OPTIONS,POST,GET"
    }

Make sure you understand the implications of using *, which is a discussion for a different post.

about 4 years ago · Juan Pablo Isaza Report

0

Not sure what I did, but the call to dynamodb randomly started working. I think I had a syntax error, or something..

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!