Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task2 #2

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# nodejs-aws-cdk-starter
# nodejs-aws-cdk-starter

Task 2.1 Manual Deployment
### [S3-website](https://nodejs-aws-shop-react1.s3.eu-west-1.amazonaws.com/index.html) and [CloudFront URL](https://d82d3iyhzejev.cloudfront.net)

Task 2.2 Automated Deployment
###[Domain name](https://d1qg6ersmgr5de.cloudfront.net/)
###[CloudFront](https://js-cc-cloudfront-s33.s3.eu-west-1.amazonaws.com/)
Task 2.3 Automated Deployment
Here done
45 changes: 45 additions & 0 deletions static-site.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions static-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@ export class StaticSite extends Construct {
constructor(parent: Stack, name: string) {
super(parent, name);


}
const cloudfrontOAI = new cloudfront.OriginAccessIdentity(this, "JSCC-OAI");
const siteBucket = new s3.Bucket(this, "JSCCStaticBucket", {
bucketName: "js-cc-cloudfront-s33",
websiteIndexDocument: 'index.html',
publicReadAccess: false,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL
});
siteBucket.addToResourcePolicy(new iam.PolicyStatement({
actions: ["s3:GetObject"],
resources: [siteBucket.arnForObjects("*")],
principals: [new iam.CanonicalUserPrincipal(cloudfrontOAI.cloudFrontOriginAccessIdentityS3CanonicalUserId)]
}));
const distribution = new cloudfront.CloudFrontWebDistribution(this, 'JSCCStaticDistribution', {
originConfigs: [{
s3OriginSource: {
s3BucketSource: siteBucket,
originAccessIdentity: cloudfrontOAI
},
behaviors: [{
isDefaultBehavior: true
}]
}]
});
new s3deploy.BucketDeployment(this, "JSCC-Bucket-Deployment", {
sources: [s3deploy.Source.asset("./website")],
destinationBucket: siteBucket,
distribution,
distributionPaths: ["/*"]
});
}
}