Cross Origin Resource Sharing

For security purposes, the browser will block the flow if the external requests don't match the exact host, protocol, and port of your website. In our example, we have different domain names (localhost and API Gateway URL).

This mechanism is known as the Same-origin policy. To solve this problem, you can either use a CORS header, proxy server, or JSON workaround. In this section, I will demonstrate how we can use a CORS header in the response returned by the Lambda function to resolve this issue:

  1. Modify the findAllMovie function's code to add Access-Control-Allow-Origin:*to enable cross-origin requests from anywhere (or specify a domain instead of *):
    return events.APIGatewayProxyResponse{    StatusCode: 200,

Get Hands-On Serverless Applications with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.