A CDN represents an Amazon CloudFront distribution. Amazon CloudFront is a service that uses AWS Edge Locations to speed up distribution of your web content. An edge location is a data center located in a major city, that caches your data. The edge location that provides the best performance for your end user retrieves, stores, and serves your web content to your user.
Key Features of Amazon CloudFront include:
- Highly available and secure edge locations
- Pay as you go, no upfront costs
- Ability to add, remove, or replace specific content to distribute
A CDN can be connected to an Object Store to access your static or dynamic web content. The CDN is granted read access to all objects in the Object Store, regardless of the Object Store's Public Permissions property.
Event subscription wires (solid line) visualize and configure event subscription integrations between two resources.
The following resources can be subscribed to a CDN:
- Object Store
- Edge Function
Human readable name for this resource that is displayed on the Stackery Dashboard and Stackery CLI output.
The unique identifier used to reference this resource in the stack template. Defining a custom Logical ID is recommended, as it allows you to quickly identify a resource and any associated sub-resources when working with your stack in AWS, or anywhere outside of the Stackery Dashboard. As a project grows, it becomes useful in quickly spotting this resource in
template.yaml or while viewing a stack in Template View mode.
The Logical ID of all sub-resources associated with this CDN will be prefixed with this value.
The identifier you provide must only contain alphanumeric characters (A-Za-z0-9) and be unique within the stack.
Default Logical ID Example:
IMPORTANT : AWS uses the Logical ID of each resource to coordinate and apply updates to the stack when deployed. On any update of a resource's logical ID (or any modification that results in one), CloudFormation will delete the currently deployed resource and create a new one in it's place when the updated stack is deployed.
Use Custom Domain
Enable this option to provide your own custom domain for the CDN.
By default, Stackery uses the default domain provided by AWS CloudFront
The domain name that will be used for the CDN. AWS Certificate Manager will provision an SSL certificate for this domain. In order to provision the certificate, AWS will send an email to the domain's registration contacts and certain well-known domain administration email addresses:
When deploying be sure to check these email addresses to approve the certificate. If the domain is not verified within one hour of the start of the deployment the deployment will fail and be rolled back automatically.
The CDN domain name must be globally unique - specifically across AWS CloudFront Distributions and AWS API Gateway Custom Domains.
After deployment a CNAME DNS record will need to be created for the domain. Select the current deployment of your stack, then select your CDN resource on the Stackery Dashboard. Find and copy the DNS Name value in the properties panel on the right. Create a CNAME record to map the custom domain to this DNS name. Check with your DNS provider for instructions on how to create the record.
CDN Components & Implementation
A CDN's origin is the main source of content; where objects or files are stored to be accessed by the CDN.
Connect this origin component to an Object Store using an event subscription wire to deliver content being hosted in that Object Store.
The following components represent the events that occur during a CDN's request cycle. These components only require your attention if your application uses Edge Functions, which can be subscribed to these CDN events and invoked when they occur.
Read more about their use cases and the CDN request cycle in our Edge Function reference.
This event occurs before the CDN checks if the requested data is in an edge location's cache.
If the requested data is already in the edge location's cache, the Origin Request and Origin Response events are skipped, and the Viewer Response event occurs
This event occurs only if requested data is not in an edge location's cache and a request must be made to the CDN's origin to retrieve it.
This event occurs when the CDN receives a response and the requested data from its origin and before it caches the response data.
This event occurs when the CDN returns requested data to the client.
CDN events are essential to implementing Edge Functions in your applications. Visit our Edge Function reference or the related AWS documentation listed at the end of this reference for more details.
When connected by a service discovery wire (dashed wire), a Function or Docker Task will add the following IAM policy to its role and gain permission to access this resource.
No Permissions Added
When connected by a service discovery wire (dashed wire), a Function or Docker Task will automatically populate and reference the following environment variables in order to interact with this resource.
No Environment Variables Added
Related AWS Documentation
AWS Documentation: AWS::CloudFront::Distribution
Using CDN Events with Edge FunctionsCustomizing CloudFront with Lambda@Edge