Skip to main content

Distribution

Provides a Cloud Front distribution.

CloudFront with a S3 bucket as origin#

const domainName = "your.domain.name.com";
const certificate = await providerUsEast.makeCertificate({
name: `certificate-${domainName}`,
properties: () => ({
DomainName: domainName,
}),
});
const websiteBucket = await provider.makeS3Bucket({
name: `${domainName}-bucket`,
properties: () => ({
ACL: "public-read",
WebsiteConfiguration: {
ErrorDocument: {
Key: "error.html",
},
IndexDocument: {
Suffix: "index.html",
},
},
}),
});
const distribution = await provider.makeCloudFrontDistribution({
name: `distribution-${domainName}`,
dependencies: { websiteBucket, certificate },
properties: ({ dependencies }) => {
return {
PriceClass: "PriceClass_100",
Comment: `${domainName}.s3.amazonaws.com`,
Aliases: { Quantity: 1, Items: [domainName] },
DefaultRootObject: "index.html",
DefaultCacheBehavior: {
TargetOriginId: `S3-${domainName}`,
ViewerProtocolPolicy: "redirect-to-https",
ForwardedValues: {
Cookies: {
Forward: "none",
},
QueryString: false,
},
MinTTL: 600,
TrustedSigners: {
Enabled: false,
Quantity: 0,
Items: [],
},
},
Origins: {
Items: [
{
DomainName: `${domainName}.s3.amazonaws.com`,
Id: `S3-${domainName}`,
S3OriginConfig: { OriginAccessIdentity: "" },
},
],
Quantity: 1,
},
};
},
});

Examples#

Properties#

Cache Invalidation#

When some S3 objects are updated during the gc apply command, a createInvalidation call is made to invalide the cache to make sure the new version is available to the node edges.

Dependencies#