Skip to content

Commit

Permalink
fix: fix create distribution not working
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinTW committed Jan 14, 2022
1 parent 091390f commit 18d2bfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions aws-ts-netlify-cms-and-oauth/cms/infrastructure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ const distributionArgs: aws.cloudfront.DistributionArgs = {
enabled: true,
// Alternate aliases the CloudFront distribution can be reached at, in addition to https://xxxx.cloudfront.net.
// Required if you want to access the distribution via config.targetDomain as well.
aliases: [ config.targetDomain ],
aliases: [config.targetDomain],

// We only specify one origin for this distribution, the S3 content bucket.
origins: [
{
originId: contentBucket.arn,
domainName: contentBucket.websiteEndpoint,
domainName: contentBucket.bucketDomainName,
customOriginConfig: {
// Amazon S3 doesn't support HTTPS connections when using an S3 bucket configured as a website endpoint.
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesOriginProtocolPolicy
Expand Down Expand Up @@ -251,7 +251,7 @@ const aRecord = createAliasRecord(config.targetDomain, cdn);

// Export properties from this stack. This prints them at the end of `pulumi up` and
// makes them easier to access from the pulumi.com.
export const contentBucketUri = pulumi.interpolate `s3://${contentBucket.bucket}`;
export const contentBucketUri = pulumi.interpolate`s3://${contentBucket.bucket}`;
export const contentBucketWebsiteEndpoint = contentBucket.websiteEndpoint;
export const cloudFrontDomain = cdn.domainName;
export const targetDomainEndpoint = `https://${config.targetDomain}/`;
20 changes: 10 additions & 10 deletions aws-ts-static-website/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ if (config.certificateArn === undefined) {

// Generate Origin Access Identity to access the private s3 bucket.
const originAccessIdentity = new aws.cloudfront.OriginAccessIdentity("originAccessIdentity", {
comment: "this is needed to setup s3 polices and make s3 not public.",
comment: "this is needed to setup s3 polices and make s3 not public.",
});

// if config.includeWWW include an alias for the www subdomain
Expand All @@ -174,7 +174,7 @@ const distributionArgs: aws.cloudfront.DistributionArgs = {
origins: [
{
originId: contentBucket.arn,
domainName: contentBucket.websiteEndpoint,
domainName: contentBucket.bucketDomainName,
s3OriginConfig: {
originAccessIdentity: originAccessIdentity.cloudfrontAccessIdentityPath,
},
Expand Down Expand Up @@ -296,17 +296,17 @@ function createWWWAliasRecord(targetDomain: string, distribution: aws.cloudfront
}

const bucketPolicy = new aws.s3.BucketPolicy("bucketPolicy", {
bucket: siteBucket.id, // refer to the bucket created earlier
policy: pulumi.all([originAccessIdentity.iamArn, contentBucket.arn]).apply(([oaiArn, bucketArn]) =>JSON.stringify({
bucket: contentBucket.id, // refer to the bucket created earlier
policy: pulumi.all([originAccessIdentity.iamArn, contentBucket.arn]).apply(([oaiArn, bucketArn]) => JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Principal: {
AWS: oaiArn,
}, // Only allow Cloudfront read access.
Action: ["s3:GetObject"],
Resource: [`${bucketArn}/*`], // Give Cloudfront access to the entire bucket.
Effect: "Allow",
Principal: {
AWS: oaiArn,
}, // Only allow Cloudfront read access.
Action: ["s3:GetObject"],
Resource: [`${bucketArn}/*`], // Give Cloudfront access to the entire bucket.
},
],
})),
Expand Down

0 comments on commit 18d2bfc

Please sign in to comment.