-
Notifications
You must be signed in to change notification settings - Fork 0
/
static-site.js
45 lines (45 loc) · 5.65 KB
/
static-site.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StaticSite = void 0;
const s3 = require("@aws-cdk/aws-s3");
const s3deploy = require("@aws-cdk/aws-s3-deployment");
const cloudfront = require("@aws-cdk/aws-cloudfront");
const iam = require("@aws-cdk/aws-iam");
const core_1 = require("@aws-cdk/core");
class StaticSite extends core_1.Construct {
constructor(parent, name) {
super(parent, name);
const cloudfrontOAI = new cloudfront.OriginAccessIdentity(this, "JSCC-OAI");
const siteBucket = new s3.Bucket(this, "JSCCStaticBucket", {
bucketName: "js-cc-cloudfront-s3-v2",
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, "JSCC-distribution", {
originConfigs: [{
s3OriginSource: {
s3BucketSource: siteBucket,
originAccessIdentity: cloudfrontOAI
},
behaviors: [{
isDefaultBehavior: true
}]
}]
});
new s3deploy.BucketDeployment(this, "JSCC-Bucket-Distrubution", {
sources: [s3deploy.Source.asset("./website")],
destinationBucket: siteBucket,
distribution,
distributionPaths: ["/*"]
});
}
}
exports.StaticSite = StaticSite;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGljLXNpdGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJzdGF0aWMtc2l0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHB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