serverless-http icon indicating copy to clipboard operation
serverless-http copied to clipboard

Feature request: Support for AWS API Gateway payload version 2

Open danyfedorov opened this issue 5 years ago • 15 comments

Link with info about version 1 vs version 2.

https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html

danyfedorov avatar Mar 24 '20 09:03 danyfedorov

If useful to others: until payload version 2 is supported we can get this to work by specifying version 1 like this:

  ApiFunction:
    Type: AWS::Serverless::Function
    Properties:
      # ...
      Events:
        Http:
          Type: HttpApi
          Properties:
            PayloadFormatVersion: '1.0'

mpvosseller avatar Mar 25 '20 16:03 mpvosseller

This is the file that needs changes, ya? https://github.com/dougmoscrop/serverless-http/blob/master/lib/provider/aws/create-request.js

If someone can confirm, I can take a stab at this.

tehnrd avatar Apr 03 '20 05:04 tehnrd

I believe the example from @mpvosseller above is for SAM.

If using the serverless framework, the following is a workaround:

resources:
  Resources:
    Overrides:
      Type: AWS::ApiGatewayV2::ApiGatewayManagedOverrides
      Properties: 
        ApiId: 
          Ref: "HttpApi"
        Integration: 
          PayloadFormatVersion: '1.0'

tehnrd avatar Apr 04 '20 00:04 tehnrd

@TehNrd

With your workaround, I got an error: The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [HttpApi] in the Resources block of the template

Do you have any guess how this could be solved?

Frans-L avatar Apr 05 '20 13:04 Frans-L

@Frans-L What does the rest of your serverless.yml file look like?

tehnrd avatar Apr 05 '20 20:04 tehnrd

@TehNrd

Thanks for helping out. Here is the whole serverless.yml

service:
  name: test

app: something-test
org: something

custom:
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true

plugins:
  - serverless-webpack
  - serverless-offline

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-west-3
  apiGateway:
    minimumCompressionSize: 1024
  environment:
    AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1

functions:
  app:
    handler: src/app.handler
    events:
      - http: ANY /
      - http: "ANY /{proxy+}"

Frans-L avatar Apr 06 '20 12:04 Frans-L

@Frans-L You aren't using the new httpApi event. What you have there will create a normal REST API. need to change http to httpApi Once you do this you might also need to change the paths as I'm not sure those are valid for httpApi. I think you only need httpApi: '*'

And if you have an Custom Domain sitting in front of this it also needs to be a Regional domain name.

https://serverless.com/framework/docs/providers/aws/events/http-api/

tehnrd avatar Apr 06 '20 14:04 tehnrd

Hmm, so my workaround above isn't working anymore and I am now receiving the following error on deployment.

An error occurred: Overrides - ApiGatewayManagedOverrides can only be associated to APIs created via quick create (Service: null; Status Code: 0; Error Code: null; Request ID: null) (Service: null; Status Code: 404; Error Code: BadRequestException; Request ID: null).

Not sure what changed, maybe something internal to the way serverless framework does deploy.

I started on a PR fix but stopped after finding the workaround, I'll get PR submitted soon.

tehnrd avatar Apr 14 '20 20:04 tehnrd

Hmm, maybe I'm going crazy. Looks like Serverless Framework is setting 1.0 payload and has been for a while.

https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/events/httpApi/index.js#L434

Not sure how mine got set to 2.0 for my deployment but would still be great it if both were supported so I'll continue on the PR.

tehnrd avatar Apr 15 '20 01:04 tehnrd

PR Submitted! https://github.com/dougmoscrop/serverless-http/pull/150

Definitely open to feedback. :-)

tehnrd avatar Apr 19 '20 04:04 tehnrd

@TehNrd Could this be also due different payload version support. Also how can i check which setting mine api gateway is using

https://github.com/dougmoscrop/serverless-http/issues/151

niteshgrg avatar Apr 19 '20 06:04 niteshgrg

@niteshgrg Not sure if that is related, but here is where you check payload version.

Screen Shot 2020-04-19 at 10 52 29 AM

There are also some CORS specific settings you may need to edit as well for your particular issue.

tehnrd avatar Apr 19 '20 14:04 tehnrd

this issue can be closed now ?

AshUK avatar Feb 16 '21 21:02 AshUK

I have discovered another scenario for the error ApiGatewayManagedOverrides can only be associated to APIs created via quick create. This can happen whenTarget is missed AWS::ApiGatewayV2::Api, the result is ApiGatewayManagedOverrides no knowing what to do and throws the above error

MarcoLeongDev avatar Nov 04 '21 04:11 MarcoLeongDev

curious why no serverless-http in `plugins' section?

ciekawy avatar May 16 '23 19:05 ciekawy