- Newest
- Most votes
- Most comments
Your approach of using CloudFront as a non-cached backend request proxy for your API management is a valid and effective solution to the cookie domain issue you're facing. This setup allows you to maintain your existing domain structure while solving the cookie security problem.
Here's a breakdown of your solution and its implications:
-
CloudFront Configuration: You're adding an ordered cache behavior that matches the backend URLs (starting with '/api') and directs these requests to your API management origin. This is a correct approach for routing specific paths to a different origin.
-
Caching Disabled: For this behavior, you're disabling caching. This is crucial for API requests that need to be fresh and not served from cache. You can achieve this by setting the cache policy to "CachingDisabled" for the API-related behavior.
-
Cookie Handling: By proxying the API requests through CloudFront on your app domain, you're allowing cookies to be set on the same domain as your application. This solves the issue with strict and lax cookie settings, making your setup compatible with Safari's current restrictions and future browser changes.
-
Cost Estimation: Your cost estimation seems reasonable. CloudFront's pricing model is indeed based on the number of requests and data transfer, so your calculations appear to be on the right track.
-
Performance Impact: The additional hop through CloudFront typically adds minimal latency, as you've observed. CloudFront's global network often compensates for this by reducing the distance to the origin for many users.
-
Security: This setup can provide additional security benefits. CloudFront can act as a shield for your API, offering features like DDoS protection and SSL/TLS termination.
-
Origin Request Policy: Ensure you've set up an appropriate origin request policy. For API requests, you typically want to forward all headers, cookies, and query strings to the origin.
-
HTTPS: Make sure you're using HTTPS for all communications, both between the client and CloudFront, and between CloudFront and your API origin.
Your solution is a common and recommended approach for solving cross-domain cookie issues while leveraging the benefits of a CDN. The only potential drawback is the slight increase in complexity in your infrastructure, but the benefits in terms of security and functionality outweigh this concern.
Remember to thoroughly test all API endpoints, especially those involving authentication and session management, to ensure everything works as expected in this new setup.
Sources
cloudfront distribution with several origins | AWS re:Post
Amazon CloudFront now accepts your applications’ gRPC calls | AWS News Blog
OriginRequestPolicyCookiesConfig - Amazon CloudFront
CachePolicyCookiesConfig - Amazon CloudFront
Hi,
To implement your solution, you may want to use Lambda@Edge and their local memory to store the cookie on the edge and avoid having to go back each time to central location (only when you have a local cache miss)
For a sample of Lambda@Edge memory, see "Cache your data in Lambda@Edge Memory" of https://aws.amazon.com/blogs/networking-and-content-delivery/leveraging-external-data-in-lambdaedge/
Also https://medium.com/uniplacesgeeks/cache-control-with-lambda-edge-95645b3aa4f0 may be useful
For Lambda@Edge (in you don't use it already): https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-at-the-edge.html
Best,
Didier
Your approach is sound and commonly used. Here's a quick validation of your solution:
Pros:
Solves the cookie domain issue
Maintains security with same-origin policy
Minimal latency impact
Reasonable cost estimation
Simple implementation
Key considerations:
Ensure proper cache settings:
{ "CachePolicyConfig": { "MinTTL": 0, "MaxTTL": 0, "DefaultTTL": 0, "ParametersInCacheKeyAndForwardedToOrigin": { "EnableAcceptEncodingGzip": true, "EnableAcceptEncodingBrotli": true, "HeadersConfig": { "HeaderBehavior": "whitelist", "Headers": ["Authorization", "Host"] } } } }
Security measures:
Use HTTPS only
Configure appropriate security headers
Consider implementing WAF rules
Set up proper origin request policies
The solution is architecturally sound and commonly implemented for similar use cases.
answered 2 years ago
Your approach is sound and commonly used. Here's a quick validation of your solution:
Pros:
Solves the cookie domain issue
Maintains security with same-origin policy
Minimal latency impact
Reasonable cost estimation
Simple implementation
Key considerations:
Ensure proper cache settings:
{ "CachePolicyConfig": { "MinTTL": 0, "MaxTTL": 0, "DefaultTTL": 0, "ParametersInCacheKeyAndForwardedToOrigin": { "EnableAcceptEncodingGzip": true, "EnableAcceptEncodingBrotli": true, "HeadersConfig": { "HeaderBehavior": "allowlist", "Headers": ["Authorization", "Host"] } } } }
Security measures:
Use HTTPS only
Configure appropriate security headers
Consider implementing WAF rules
Set up proper origin request policies
The solution is architecturally sound and commonly implemented for similar use cases
answered 2 years ago
Relevant content
asked a year ago
asked 2 years ago
asked 2 years ago
- AWS OFFICIALUpdated a year ago
