Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP API requires 'integration' to conform with V2 payload syntax #1097

Closed
lmmattr opened this issue Sep 11, 2020 · 8 comments
Closed

HTTP API requires 'integration' to conform with V2 payload syntax #1097

lmmattr opened this issue Sep 11, 2020 · 8 comments

Comments

@lmmattr
Copy link

lmmattr commented Sep 11, 2020

Bug Report

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

The docs for the v2 payload say i can return an object from a function but that doesn't work by default. I have to specify integration: lambda in the serverless config file for it to work.

Sample Code

Does not work

  • file: serverless.yml
service: my-service

plugins:
  - serverless-offline

provider:
  runtime: nodejs12.x
  stage: dev

functions:
  hello:
    events:
      - httpApi:
          method: GET
          path: /hello
    handler: handler.hello
  • file: handler.js
module.exports.hello = async (event, context) => {
  return { message: 'SUCCESS' }
}

Output:
nothing

Works 1

  • file: serverless.yml
service: my-service

plugins:
  - serverless-offline

provider:
  runtime: nodejs12.x
  stage: dev

functions:
  hello:
    events:
      - httpApi:
          method: GET
          path: /hello
    handler: handler.hello
  • file: handler.js
module.exports.hello = async (event, context) => {
  return 'SUCCESS'
}

Output:

"SUCCESS"

Works 2

  • file: serverless.yml
service: my-service

plugins:
  - serverless-offline

provider:
  runtime: nodejs12.x
  stage: dev

functions:
  hello:
    events:
      - httpApi:
          method: GET
          path: /hello
          integration: lambda
    handler: handler.hello
  • file: handler.js
module.exports.hello = async (event, context) => {
  return { message: 'SUCCESS' }
}

Output:

{
  "message": "SUCCESS"
}

You also get a warning in the log output of serverless:

Serverless:   at 'functions.hello.events[0].httpApi': unrecognized property 'integration'

Expected behavior/code
You should be able to return an object without having to specify the integration key.

@revmischa
Copy link

I noticed if I return an object from a httpApi with v2 event format, serverless-offline returns an empty response but if I deploy the same code to lambda the object appears in the response. Maybe related.

@bryantbiggs
Copy link
Contributor

@lmmattr / @revmischa you might try v6.8.0 which just added AP gateway v2 paylod support with #1092

@Myroslav341
Copy link

@bryantbiggs hey just tried installing v.6.8.0. The issue still persists

@revmischa
Copy link

endpoint doesn't seem to have these fields. Using latest serverless with httpApi and payload 2.0

image

@revmischa
Copy link

adding integration: lambda as mentioned above does cause this to work

@ljwagerfield
Copy link

@lmmattr your Does not work and Works 1 are identical.

@lmmattr
Copy link
Author

lmmattr commented Dec 16, 2020

@ljwagerfield its the handler output that's different between those two.

@vlechemin
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants