2

I want to create an endpoint where others can post the data and then I can use it for further operations. I am using lambda and serverless framework for deployment. It is working fine in my local but each time I deploy it gives a 404 not foundError.(There are no issues in deployment).I get the following message in insomnia when testing the API- Cannot POST /test/update (test is my basePath) I have cross-verified the domains and they are exactly the same as the ones present in serverless.yml file. Currently, I have the following code for the post request-

const express = require('express')
const eApp = express()
eApp.post('/update', async (req, res) => {
    try {
        // console.log('post req is:', req)
        console.log('body', JSON.stringify(req.body))
        res.sendStatus(200)
    }
    catch (e) {
        console.log('error in post request is:',e)
        res.sendStatus(200)
    }
})
exports.eApp = eApp
const handler = serverless(eApp)
module.exports.handler = async (event, context) => {
  context.callbackWaitsForEmptyEventLoop = false
  const result = await handler(event, context)
  return result
}

(The above code is present in index.js in routes folder). The lambda function present in serverless.yml file is as following-

  updateEndPoint:
    handler: routes/index.handler
    events:
      - http:
          path: /update
          method: post
          cors: true

I am also not getting any error in cloudwatch logs and can't find the root cause of the issue. Any help would be appreciated. Thanks in advance!!

EDIT- It is working with the domain address mentioned in lambda in aws (the one automatically assigned by aws) but not working with the domain address I have given in the serverless.yml file. Any fixes for this??

skeletor
  • 41
  • 4

1 Answers1

0

Try adding

functions:
  api:
    handler: index.handler
    events:
      - httpApi: '*'

Default serverless it gets like this which allows only "/" path

functions:
  api:
    handler: index.handler
    events:
      - httpApi:
          path: /
          method: get

I know this is late but keeping it for future users.

vimuth
  • 5,064
  • 33
  • 79
  • 116