Amazon CloudFront to Amazon S3 and Amazon API Gateway

CloudFront → Lambda@Edge → Lambda@Edge → S3 bucket → API Gateway → AWS Lambda

CloudFront to S3 and API Gateway backed by TypeScript Lambda functions

This pattern deploys a CloudFront distribution and routes HTTP traffic to two backend services based on the URL. Any URLs that have a path beginning with /api/ are routed to an API Gateway which integrates with Lambda Functions which are written in TypeScript. All other traffic is routed to an S3 bucket.
The pattern also includes examples of using Lambda@Edge integrated with CloudFront to implement redirects, and to add CORS headers to API requests.

< 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/cdk-cloudfront-to-s3-and-lambda

Deploy

npm inpx cdk deploy --all


Testing

You can test the solution by accessing the CloudFront distribution domain using a web browser.

Cleanup

1. In the source folder, from the command line enter:
npx cdk destroy --all
2. See additional notes in the repo.

Additional resources

Created by:

Adrian Hesketh

Adrian Hesketh

Adrian Hesketh works at Infinity Works in the UK, helping organisations with digital transformation and service delivery.