AWS Certified Developer - Associate
API Gateway
CORS
Cross-Origin Resource Sharing (CORS) is a crucial web security feature that enables controlled interactions between resources hosted on different domains. This lesson explores how CORS works, why it is important, and how to configure it effectively for your applications.
Imagine a scenario where both the web browser (client) and the backend server are hosted on the same domain, for example, example.com. In this case, when the client sends a request to the server, the transaction proceeds smoothly because the request is confined to the same origin.
However, if the backend is hosted on a different domain, such as api.example.com, the browser will block the request by default due to cross-origin restrictions imposed for security reasons. This built-in security measure prevents unauthorized access across different domains.
To facilitate communication between a client on example.com and a backend on api.example.com, you must enable CORS on the backend. This configuration informs the browser that requests from the specified domain are permitted, effectively bypassing the default cross-origin limitations.
Note
When using an API Gateway as your backend, enabling CORS can be as simple as toggling a single configuration option. This approach allows you to explicitly permit requests from authorized domains while maintaining robust security.
By configuring CORS on the API Gateway, you ensure that your application can securely handle requests across different domains without compromising on security or performance.
Watch Video
Watch video content