Subdomain Setup for Model Deployment Services
Introduction
This guide will walk you through the process of setting up subdomains for model deployment services using Pulumi with AWS. We will create an S3 bucket to host the static content, configure a CloudFront distribution for content delivery, and set up Route 53 for DNS management.
Step-by-Step Explanation
Step 1: Create an S3 Bucket
First, we need to create an S3 bucket to host the static content for our model deployment services.
import * as aws from "@pulumi/aws";
const bucket = new aws.s3.Bucket("model-deployment-bucket", {
website: {
indexDocument: "index.html",
},
});
Step 2: Configure CloudFront Distribution
Next, we will set up a CloudFront distribution to deliver the content from the S3 bucket.
const cdn = new aws.cloudfront.Distribution("cdn", {
origins: [{
domainName: bucket.websiteEndpoint,
originId: bucket.arn,
}],
enabled: true,
isIpv6Enabled: true,
defaultRootObject: "index.html",
defaultCacheBehavior: {
allowedMethods: ["GET", "HEAD"],
cachedMethods: ["GET", "HEAD"],
targetOriginId: bucket.arn,
viewerProtocolPolicy: "redirect-to-https",
forwardedValues: {
queryString: false,
cookies: { forward: "none" },
},
},
priceClass: "PriceClass_100",
restrictions: {
geoRestriction: {
restrictionType: "none",
},
},
viewerCertificate: {
cloudfrontDefaultCertificate: true,
},
});
Step 3: Set Up Route 53
Finally, we will configure Route 53 to manage the DNS records for our subdomain.
const zone = new aws.route53.Zone("model-deployment-zone", {
name: "example.com",
});
const record = new aws.route53.Record("model-deployment-record", {
zoneId: zone.id,
name: "models.example.com",
type: "A",
aliases: [{
name: cdn.domainName,
zoneId: cdn.hostedZoneId,
evaluateTargetHealth: false,
}],
});
Summary
In this guide, we created an S3 bucket to host static content, set up a CloudFront distribution for content delivery, and configured Route 53 to manage DNS records for our subdomain. This setup ensures that our model deployment services are accessible via a custom subdomain with high availability and performance.
Full Code Example
import * as aws from "@pulumi/aws";
// Step 1: Create an S3 Bucket
const bucket = new aws.s3.Bucket("model-deployment-bucket", {
website: {
indexDocument: "index.html",
},
});
// Step 2: Configure CloudFront Distribution
const cdn = new aws.cloudfront.Distribution("cdn", {
origins: [{
domainName: bucket.websiteEndpoint,
originId: bucket.arn,
}],
enabled: true,
isIpv6Enabled: true,
defaultRootObject: "index.html",
defaultCacheBehavior: {
allowedMethods: ["GET", "HEAD"],
cachedMethods: ["GET", "HEAD"],
targetOriginId: bucket.arn,
viewerProtocolPolicy: "redirect-to-https",
forwardedValues: {
queryString: false,
cookies: { forward: "none" },
},
},
priceClass: "PriceClass_100",
restrictions: {
geoRestriction: {
restrictionType: "none",
},
},
viewerCertificate: {
cloudfrontDefaultCertificate: true,
},
});
// Step 3: Set Up Route 53
const zone = new aws.route53.Zone("model-deployment-zone", {
name: "example.com",
});
const record = new aws.route53.Record("model-deployment-record", {
zoneId: zone.id,
name: "models.example.com",
type: "A",
aliases: [{
name: cdn.domainName,
zoneId: cdn.hostedZoneId,
evaluateTargetHealth: false,
}],
});
// Export relevant URLs
export const bucketEndpoint = bucket.websiteEndpoint;
export const cdnDomainName = cdn.domainName;
export const zoneName = zone.name;
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.