CodeGenieApp / serverless-express

Run Express and other Node.js frameworks on AWS Serverless technologies such as Lambda, API Gateway, Lambda@Edge, and more.
https://codegenie.codes
Apache License 2.0
5.13k stars 668 forks source link

Api Gateway Proxy integration 404 #362

Closed tniemann closed 3 years ago

tniemann commented 3 years ago

Hi,

I tried to move from "aws-serverless-express 3.4.0".

So far everything works except my proxy integration at the API gateway. Every request ends in a 404.

This is how I defined my path:

/api/{proxy+}:
    x-amazon-apigateway-any-method:
      produces:
        - application/json
      responses: {}
      x-amazon-apigateway-integration:
        uri: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${stageVariables.ServerlessExpressLambdaFunctionName}/invocations
        httpMethod: POST
        type: aws_proxy
      x-amazon-apigateway-auth:
        type: none

The logs shows that the proxy path change to the one before:

aws-serverless-express 3.4.0: Endpoint request body after transformations: {"resource":"/api/{proxy+}","path":"/api/coupon","httpMethod":"POST"

vendia/serverless-express 4.1.2: Endpoint request body after transformations: {"resource":"/{proxy+}","path":"/coupon","httpMethod":"POST"

The request URL is:

POST /api/coupon

my lambda.js looks like this:

'use strict'

import serverlessExpress from '@vendia/serverless-express'
import app from './app'

// global variable server to keep hot in lambda
// server is set at the first call and reused then
let server

exports.handler = (event, context) => {
  if (server) {
    return server(event, context)
  }

  server = serverlessExpress({app}).handler

  return server(event, context)
}

Any idea why the path is not correct?

Best Thomas

tniemann commented 3 years ago

I solved this by changing the integration to this:

/{proxy+}:
    x-amazon-apigateway-any-method:
      produces:
        - application/json
      responses: {}
      x-amazon-apigateway-integration:
        uri: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${stageVariables.ServerlessExpressLambdaFunctionName}/invocations
        httpMethod: POST
        type: aws_proxy
      x-amazon-apigateway-auth:
        type: none
thetumper commented 3 years ago

Seeing the same. Modifying my path is not a workable solution - I need the path to remain as-is.