-
Notifications
You must be signed in to change notification settings - Fork 0
/
envProps.ts
71 lines (65 loc) · 3.27 KB
/
envProps.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
65
66
67
68
69
70
71
import {App, Fn, StackProps} from "aws-cdk-lib";
import {BehaviorOptions, CachePolicy} from "aws-cdk-lib/aws-cloudfront";
import {WebsiteCustomDomain} from "@symphoniacloud/cdk-website";
import {createStackProps} from "./initSupport";
export interface CoffeeStoreWebFullStackProps extends StackProps {
customDomain: WebsiteCustomDomain
performCacheInvalidation?: boolean
additionalDefaultBehaviorOptions?: Omit<BehaviorOptions, 'origin'>;
}
// This example uses 3 'application environments' - prod, test, and development
// Each app environment is keyed BY AWS ACCOUNT ID. In other words, this code decides which
// properties to use according to the AWS Account active when the code is run.
// For your own version you should feel free to have fewer environments, key by something else (e.g. stack name), etc.
const CoffeeStoreWebFullStackPropsPerEnv: Record<string, CoffeeStoreWebFullStackProps> = {
// This is this demo's "prod" account
'073101298092': {
customDomain: {
// For this demo we want to serve in production on both the "apex" domain, and "www."
domains: [{
domainName: 'coffeestorewebdemo.symphonia.io',
hostedZone: {fromDomainName: 'coffeestorewebdemo.symphonia.io'},
}, {
domainName: 'www.coffeestorewebdemo.symphonia.io',
hostedZone: {fromDomainName: 'coffeestorewebdemo.symphonia.io'},
}],
// The certificate is deployed in a different stack, and the ARN is exported, which we import here
certificate: {fromArn: Fn.importValue('CoffeeStoreWebDemoCertificate')}
},
// In production we want to invalidate the CloudFront cache in this demo - you might not want the same
// behavior since for frequent deployments this may cost money
performCacheInvalidation: true
},
// Test
'443780941070': {
// For test and development we only serve on one domain name because of a shared DNS hosted zone
customDomain: {
domainName: 'coffeestorewebdemo.test.symphonia.io',
hostedZone: {fromDomainName: 'test.symphonia.io'},
certificate: {fromArn: Fn.importValue('StandardCertificate')}
},
// In test and dev we don't invalidate, but we also turn off all caching behavior
additionalDefaultBehaviorOptions: {
cachePolicy: CachePolicy.CACHING_DISABLED
}
},
// Mike's dev account - this models an "account per development" strategy
'397589511426': {
customDomain: {
domainName: 'coffeestorewebdemo.mike.symphonia.io',
hostedZone: {fromDomainName: 'mike.symphonia.io'},
certificate: {fromArn: Fn.importValue('StandardCertificate')},
},
additionalDefaultBehaviorOptions: {
cachePolicy: CachePolicy.CACHING_DISABLED
}
},
}
export function createCoffeeStoreWebFullStackProps(app: App, defaultStackName: string): CoffeeStoreWebFullStackProps {
const baseStackProps = createStackProps(app, defaultStackName),
account = baseStackProps.env.account,
appProps = CoffeeStoreWebFullStackPropsPerEnv[account]
if (!appProps)
throw new Error(`No env props for account ${account}`)
return { ...baseStackProps, ...appProps }
}