How to Add Description to AWS CloudFront?
Adding Description to AWS CloudFront Distribution
In this guide, we will walk through the steps to add a description to an AWS CloudFront distribution using Pulumi. AWS CloudFront is a content delivery network (CDN) service that allows you to distribute content to users with low latency and high transfer speeds. Adding a description to your CloudFront distribution can help you manage and identify your distributions more easily.
Step-by-Step Explanation
- Set Up Your Pulumi Project: Ensure you have a Pulumi project set up. If not, you can create one using
pulumi new
command. - Install AWS Pulumi Package: Make sure you have the AWS Pulumi package installed. You can install it using npm:
npm install @pulumi/aws
- Create or Update CloudFront Distribution: In your Pulumi program, you can create or update a CloudFront distribution and add a description to it. Below is an example code snippet to achieve this.
Example Code
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create an S3 bucket to serve content
const bucket = new aws.s3.Bucket("my-bucket");
// Create a CloudFront distribution
const distribution = new aws.cloudfront.Distribution("my-distribution", {
origins: [{
domainName: bucket.bucketRegionalDomainName,
originId: bucket.id,
}],
enabled: true,
defaultRootObject: "index.html",
defaultCacheBehavior: {
targetOriginId: bucket.id,
viewerProtocolPolicy: "allow-all",
allowedMethods: ["GET", "HEAD"],
cachedMethods: ["GET", "HEAD"],
forwardedValues: {
queryString: false,
cookies: {
forward: "none",
},
},
minTtl: 0,
defaultTtl: 3600,
maxTtl: 86400,
},
priceClass: "PriceClass_100",
restrictions: {
geoRestriction: {
restrictionType: "none",
},
},
viewerCertificate: {
cloudfrontDefaultCertificate: true,
},
comment: "This is my CloudFront distribution for serving content from S3 bucket.", // Adding description here
});
export const distributionId = distribution.id;
Summary
In this guide, we have shown how to add a description to an AWS CloudFront distribution using Pulumi. By following the steps outlined above, you can easily manage and identify your CloudFront distributions by adding meaningful descriptions. This helps in better organization and maintenance of your cloud infrastructure.
Full Code Example
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create an S3 bucket to serve content
const bucket = new aws.s3.Bucket("my-bucket");
// Create a CloudFront distribution
const distribution = new aws.cloudfront.Distribution("my-distribution", {
origins: [{
domainName: bucket.bucketRegionalDomainName,
originId: bucket.id,
}],
enabled: true,
defaultRootObject: "index.html",
defaultCacheBehavior: {
targetOriginId: bucket.id,
viewerProtocolPolicy: "allow-all",
allowedMethods: ["GET", "HEAD"],
cachedMethods: ["GET", "HEAD"],
forwardedValues: {
queryString: false,
cookies: {
forward: "none",
},
},
minTtl: 0,
defaultTtl: 3600,
maxTtl: 86400,
},
priceClass: "PriceClass_100",
restrictions: {
geoRestriction: {
restrictionType: "none",
},
},
viewerCertificate: {
cloudfrontDefaultCertificate: true,
},
comment: "This is my CloudFront distribution for serving content from S3 bucket.", // Adding description here
});
export const distributionId = distribution.id;
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.