

If you're a Pythonista, Daniel Schep has made a nice lambda-decorators library with the same goals as Middy-replacing Lambda boilerplate. Perfect-automatic CORS headers! Check out the whole Middy library for lots of other nice utilities. To handle preflight requests, add the cors: true flag to each HTTP endpoint in your serverless.yml: # serverless.yml service: products-service provider: name: aws runtime: nodejs6.10 functions: getProduct: handler: handler.getProduct events: - http: path: product/ If you want the quick and dirty way to solve CORS in your Serverless application, do this. If you don't care about the specifics, hit the TL DR section below. In this post, we'll cover all you need to know about Serverless + CORS. No 'Access-Control-Allow-Origin' header is present on the requested resource There are several values specified in the settings for the header 'Access-Control-Allow-Origin'. If you've ever found yourself with the following error: Below we see that Access-Control-Allow-Headers includes the headers that were requested. If your web page makes an HTTP request to a different domain than you're currently on, it needs to be CORS-friendly. Response If the CORS request indicated by the preflight request is authorized, the server will respond to the preflight request with a message that indicates the allowed origin, methods, and headers. However, if you have a web page that's making calls to a backend API, you'll have to deal with the dreaded Cross-Origin Resource Sharing, or CORS. You get the benefit of a simple, scalable backend without the operations overhead.

Building web API backends is one of the most popular use cases for Serverless applications.
