-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsst.config.ts
64 lines (58 loc) · 1.84 KB
/
sst.config.ts
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { SSTConfig } from "sst";
import * as s3Deploy from "aws-cdk-lib/aws-s3-deployment";
import * as ssm from "aws-cdk-lib/aws-ssm";
import { Bucket } from "sst/constructs";
import { join } from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
import { BucketAccessControl, BucketPolicy } from "aws-cdk-lib/aws-s3";
import { StarPrincipal, PolicyStatement } from "aws-cdk-lib/aws-iam";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export default {
config(_input) {
return {
name: "docs",
region: "eu-west-1",
};
},
stacks(app) {
app.stack(function Site({ stack }) {
const bucket = new Bucket(stack, "docs-bucket", {
cdk: {
bucket: {
websiteIndexDocument: "index.html",
publicReadAccess: true,
enforceSSL: false
},
},
});
bucket.cdk.bucket.grantPublicAccess("*");
const policy = new PolicyStatement({
resources: [
bucket.cdk.bucket.arnForObjects("*"),
bucket.cdk.bucket.bucketArn,
],
actions: ["s3:GetObject"],
principals: [new StarPrincipal()],
});
bucket.cdk.bucket.addToResourcePolicy(policy)
new s3Deploy.BucketDeployment(stack, "deploy-docs", {
sources: [s3Deploy.Source.asset(join(__dirname, "dist"))],
destinationBucket: bucket.cdk.bucket,
destinationKeyPrefix: "docs",
accessControl: BucketAccessControl.PUBLIC_READ,
});
new ssm.StringParameter(this, "docsUrlParameter", {
parameterName: `/${stack.stage}/baselime/docs/s3/url`,
stringValue: bucket.cdk.bucket.bucketWebsiteDomainName,
description: "The url of the docs",
tier: ssm.ParameterTier.STANDARD,
allowedPattern: ".*",
});
stack.addOutputs({
url: `${bucket.cdk.bucket.bucketWebsiteUrl}/docs/` || "http://localhost:3000",
});
});
}
} satisfies SSTConfig;