URL path mismatch in response between serverless-offline & AWS Lambda

Using this awesome framework I wrote a very simple cloud function which fetches info from Belgium’s public radio and then maps that response out to something nicer to work with for dev stuff like apps / IoT / etc.

This was all working fine until I decided to try and use path parameters to dynamically get the broadcasting information for multiple channels. I simply tried to add a /{channelCode} URL path param to fetch the correct channel info.

All this is working fine when I used serverless-offline to mimic the AWS API gateway but when I ran sls deploy -f vrt_api_mapper it seems that the live URL does not recognize this valid path and replies with: "message": "Missing Authentication Token"

I’m using the following serverless.yml conf:

  name: aws-nodejs-ecma-script

  - serverless-offline
  - serverless-webpack

  name: aws
  runtime: nodejs8.10

    handler: mapper.handler
      - http:
          method: get
          cors: true
          path: '/{channelCode}'
                channelCode: true

The Node.js code that runs for the function is here: https://github.com/thibmaek/vrt-api-mapper/blob/master/mapper.js

Can anybody help me understand why this works fine in a local env but would not work once deployed to AWS Lambda? I also noticed AWS Lambda transforms the URL to: https://….amazonaws.com/dev/stubru

The default base URL for the API Gateway is https://{api-id}.execute-api.{region}.amazonaws.com/{stage}. You’re getting /dev at the start of the path because you’re deploying to the dev stage. If you were deploying to a stage like prod it would be /prod instead. To the best of my knowledge the only way around this is to attach a custom domain name to the API gateway.

If you’re requesting https://{api-id}.execute-api.{region}.amazonaws.com/{channelCode} instead of https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/{channelCode} then it’s going to fail because the URL doesn’t map to anything.

Also, the path in your serverless.yml is generally written relative {channelCode} rather than absolute /{channelCode} but I don’t think it makes an actual difference.

Make sure serverless-offline is the last plugin via serverless-offline - npm

  - serverless-webpack
  - serverless-offline