dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.74k stars 167 forks source link

Serverless Integration Option Support #23

Closed ricxsar closed 7 months ago

ricxsar commented 7 years ago

Hi. Do you have any plans on supporting lambda integration? I would like to use the User Pool as my authentication of the API and I need to specify the integration type as lambda to use the User Pool claims.

Here is my partial serverless.yml definition.

functions:

  # Test API
  test:
    handler: handler.main
    events:
      - http:
          path: / # this matches the base path
          method: ANY
          integration: lambda
          authorizer:
            arn: ${self:custom.userPoolARN}
            claims:
              - custom:organization
              - cognito:groups
      - http:
          path: /{any+} # this matches any path, the token 'any' doesn't mean anything special
          method: ANY
          integration: lambda
          authorizer:
            arn: ${self:custom.userPoolARN}
            claims:
              - custom:organization
              - cognito:groups

Here is my handler file.

'use strict';

import serverless from 'serverless-http';
import express from 'express';

const app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

module.exports.main = serverless(app);

When I try to deploy it using the above configuration, the following output is return on the API Gateway.

{"statusCode":404,"headers":{"x-powered-by":"Express","content-security-policy":"default-src 'self'","x-content-type-options":"nosniff","content-type":"text/html; charset=utf-8","content-length":155},"body":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot GET [object%20Object]</pre>\n</body>\n</html>\n"}
dougmoscrop commented 7 years ago

I would be open to PRs that help support this (provided they don't create a lot of complexity/maintainability issues), but I can't see myself having time to work on it, sorry!

dougmoscrop commented 5 years ago

Just FYI I've been poking around and the Lambda integration style is substantially different from Lambda-Proxy. To be honest, I'm not even sure what you would expect/want the behaviour to be.

To anyone interested in working on this, I think you'd need to take the path argument (which is an object rather than a string when using Lambda integration) and then back-fill in the values in to the requestPath.

Note for offline users, this would fail, unless this is fixed: https://github.com/dherault/serverless-offline/issues/780

Just to be clear: I don't intend to work on this, since I have no use case for non-proxy itegrations, but if someone does come to use it, I hope this information saves you some time.