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

Using Vandium with AWS SAM CLI #35

Open
skylerrichter opened this issue Jul 20, 2018 · 3 comments
Open

Using Vandium with AWS SAM CLI #35

skylerrichter opened this issue Jul 20, 2018 · 3 comments
Assignees

Comments

@skylerrichter
Copy link

What are the best practices for using Vandium with AWS SAM CLI?

Everything works great when I am using CLI events and Postman to test my endpoints, however when I try to consume endpoints via my client application CORS does not seem to be enabled.

I have added this to my handler:

.cors({
  allowOrigin: 'http://localhost:8080',
  allowCredentials: true
})

And I have this in my SAM template:

Api:
  Cors:
    AllowMethods: "'*'"
    AllowHeaders: "'*'"
    AllowOrigin: "'*'"

However Vandium does not respond to the pre flight OPTION request, and does not seem to have a method for defining OPTION routes.

I had to make a vanilla lambda to respond to OPTION requests:

exports.handler = function (event, context, callback) {
  callback(null, {
    'statusCode': 200,
    'headers': {
      'Access-Control-Allow-Origin': 'http://localhost:8080',
      'Access-Control-Allow-Headers': 'Content-Type',
    },
  });
}

What is the right way of dealing with this?

@richardhyatt
Copy link
Contributor

There's an issue that has been raised with the SAM project - not sure if that might help. I would caution against having the lambda code handle the OPTIONS request. Typically it's handled with an API Gateway Mock request

@lolJS
Copy link

lolJS commented May 7, 2019

@richardhyatt it seems the doc has been updated to state that if using lambda proxy you must handle your own options request:
For a Lambda proxy integration or HTTP proxy integration, you can still set up the required OPTIONS response headers in API Gateway. However, your backend is responsible for returning the Access-Control-Allow-Origin and Access-Control-Allow-Headers headers, because a proxy integration doesn't return an integration response.

@richardhyatt richardhyatt self-assigned this Nov 23, 2019
@richardhyatt richardhyatt modified the milestone: 5.1.0 Nov 23, 2019
@richardhyatt
Copy link
Contributor

The 5.x and 6.0 versions changed how response headers are handled. Is this issue still valid?

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

3 participants