Created
August 26, 2022 22:26
-
-
Save cnunciato/d3039393307e15e45a587fa5c0a7733d to your computer and use it in GitHub Desktop.
Create an S3 website with Pulumi and CloudFlare DNS (with HTTPS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as aws from "@pulumi/aws"; | |
import * as cloudflare from "@pulumi/cloudflare"; | |
const domain = "pulumibook.info"; | |
const subdomain = "my-awesome-website"; | |
// Make a bucket. | |
const bucket = new aws.s3.Bucket("my-bucket", { | |
bucket: `${subdomain}.${domain}`, | |
acl: aws.s3.CannedAcl.PublicRead, | |
website: { | |
indexDocument: "index.html", | |
}, | |
}); | |
// Put a homepage into it. | |
const index = new aws.s3.BucketObject("index.html", { | |
bucket: bucket.bucket, | |
acl: aws.s3.CannedAcl.PublicRead, | |
content: `<html>Hi, world!</html>`, | |
contentType: "text/html", | |
}); | |
// Create a CloudFlare DNS entry to point to it. | |
const cname = new cloudflare.Record("foobar", { | |
name: subdomain, | |
zoneId: cloudflare.getZoneOutput({ name: domain }).zoneId, | |
type: "CNAME", | |
value: bucket.websiteDomain, | |
proxied: true, | |
}); | |
export const originURL = bucket.websiteEndpoint; | |
export const cdnURL = `https://${subdomain}.${domain}`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment