Amazon CloudFront Distribution and Function with URI Rewrite to Amazon S3

Amazon CloudFront → CloudFront Functions → Amazon S3 bucket

Create a Static Website fronted by CloudFront with CloudFront Functions routing visitors to localized content using CloudFront's Geo Location Headers.

This pattern shows how to create a CloudFront Distribution with a CloudFront Function for routing to different geo-localized content in an S3 statically hosted website. Implemented in AWS CDK .NET.
CloudFront Distributions can be configured to forward the 'CloudFront-Viewer-Country' header. CloudFront Functions allow for Javascript code to execute at CloudFront edge locations, and allow you to create URL routing and rewrite rules based on request headers. In this pattern we use the 'CloudFront-Viewer-Country' header to determine the location of the request and rewrite the URI to point to different content based on the location of the request. Specifically in this example that means pointing to an index.html in a prefix that is applied based on the location.
This pattern deploys one CloudFront Distribution with a CloudFront Function and an S3 Static Website.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/cloudfront-cff-s3-geo-uri-rewrite-cdk-dotnet

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: cdk destroy.

Created by:

Patrick Gryczka

Patrick Gryczka

Patrick Gryczka is a Senior Solutions Architect at AWS specializing in Serverless technologies and the Sports industry.

Follow on LinkedIn