Enhance API Client Experience by Deploying a CloudFront Distribution to Serve APIs from Amazon API Gateway

Just like you speed-up delivery of your static assets from S3 buckets using CloudFront CDN, you can do the same for your APIs as well. In most cases, it’s enough to make your API “edge-optimized”:

If you do this, API Gateway creates & manages a CloudFront distribution for you behind the scenes, but if you need more control over CloudFront, leave the Endpoint Type of the API as Regional & create a CloudFront distribution as shown below:

The Origin Domain Name is the API endpoint you get when you deploy the API to a stage & the Origin Path is the stage name:

Wait 15-20 minutes for the CloudFront distribution to be deployed. You can then hit your API using the distribution endpoint:

The above test is using an API backed by a Lambda function which simply returns the Event object it gets from API Gateway. Since Authorization & query parameters are required by most APIs, it shows that both of these worked as expected!

Also see β€” How do I set up API Gateway with my own CloudFront distribution?.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.