Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ["/*"]
});
}
}