@gradientedge/cdk-utils 8.117.0 → 8.119.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/api-destined-function/package.json +1 -1
- package/dist/src/lib/common/construct.d.ts +32 -32
- package/dist/src/lib/common/construct.js +36 -59
- package/dist/src/lib/common/stack.d.ts +8 -7
- package/dist/src/lib/common/stack.js +17 -37
- package/dist/src/lib/common/types.d.ts +2 -2
- package/dist/src/lib/construct/api-to-eventbridge-target/api.d.ts +22 -22
- package/dist/src/lib/construct/api-to-eventbridge-target/event.d.ts +9 -9
- package/dist/src/lib/construct/api-to-eventbridge-target/main.d.ts +3 -3
- package/dist/src/lib/construct/api-to-eventbridge-target/main.js +37 -60
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.d.ts +9 -9
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.d.ts +3 -3
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.js +40 -63
- package/dist/src/lib/construct/api-to-lambda-target/api.d.ts +23 -23
- package/dist/src/lib/construct/api-to-lambda-target/main.d.ts +2 -2
- package/dist/src/lib/construct/api-to-lambda-target/main.js +15 -38
- package/dist/src/lib/construct/application-configuration/main.d.ts +7 -7
- package/dist/src/lib/construct/application-configuration/main.js +17 -41
- package/dist/src/lib/construct/graphql-api-lambda/main.d.ts +17 -17
- package/dist/src/lib/construct/graphql-api-lambda/main.js +6 -29
- package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.d.ts +5 -5
- package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.js +7 -7
- package/dist/src/lib/construct/lambda-with-iam-access/main.d.ts +16 -16
- package/dist/src/lib/construct/lambda-with-iam-access/main.js +8 -31
- package/dist/src/lib/construct/lambda-with-iam-access/types.d.ts +4 -4
- package/dist/src/lib/construct/rest-api-lambda/main.d.ts +16 -16
- package/dist/src/lib/construct/rest-api-lambda/main.js +5 -28
- package/dist/src/lib/construct/rest-api-lambda-with-cache/main.d.ts +5 -5
- package/dist/src/lib/construct/rest-api-lambda-with-cache/main.js +9 -32
- package/dist/src/lib/construct/site-with-ecs-backend/main.d.ts +38 -39
- package/dist/src/lib/construct/site-with-ecs-backend/main.js +33 -54
- package/dist/src/lib/construct/static-asset-deployment/main.d.ts +4 -4
- package/dist/src/lib/construct/static-asset-deployment/main.js +3 -26
- package/dist/src/lib/construct/static-site/main.d.ts +15 -15
- package/dist/src/lib/construct/static-site/main.js +4 -27
- package/dist/src/lib/services/aws/api-gateway/main.d.ts +10 -10
- package/dist/src/lib/services/aws/api-gateway/main.js +21 -44
- package/dist/src/lib/services/aws/api-gateway/types.d.ts +2 -2
- package/dist/src/lib/services/aws/appconfig/main.d.ts +7 -7
- package/dist/src/lib/services/aws/appconfig/main.js +14 -37
- package/dist/src/lib/services/aws/certificate-manager/main.d.ts +5 -5
- package/dist/src/lib/services/aws/certificate-manager/main.js +10 -33
- package/dist/src/lib/services/aws/certificate-manager/types.d.ts +2 -2
- package/dist/src/lib/services/aws/cloudfront/main.d.ts +18 -18
- package/dist/src/lib/services/aws/cloudfront/main.js +46 -45
- package/dist/src/lib/services/aws/cloudfront/types.d.ts +2 -3
- package/dist/src/lib/services/aws/cloudtrail/main.d.ts +5 -5
- package/dist/src/lib/services/aws/cloudtrail/main.js +5 -28
- package/dist/src/lib/services/aws/codebuild/main.d.ts +3 -3
- package/dist/src/lib/services/aws/codebuild/main.js +7 -30
- package/dist/src/lib/services/aws/dynamodb/main.d.ts +3 -3
- package/dist/src/lib/services/aws/dynamodb/main.js +8 -31
- package/dist/src/lib/services/aws/elastic-container-registry/main.d.ts +2 -2
- package/dist/src/lib/services/aws/elastic-container-registry/main.js +4 -27
- package/dist/src/lib/services/aws/elastic-container-service/main.d.ts +10 -10
- package/dist/src/lib/services/aws/elastic-container-service/main.js +27 -50
- package/dist/src/lib/services/aws/elastic-container-service/types.d.ts +4 -4
- package/dist/src/lib/services/aws/elastic-file-system/main.d.ts +3 -3
- package/dist/src/lib/services/aws/elastic-file-system/main.js +12 -35
- package/dist/src/lib/services/aws/elastic-kubernetes-service/main.d.ts +4 -4
- package/dist/src/lib/services/aws/elastic-kubernetes-service/main.js +8 -31
- package/dist/src/lib/services/aws/elasticache/main.d.ts +4 -4
- package/dist/src/lib/services/aws/elasticache/main.js +10 -33
- package/dist/src/lib/services/aws/eventbridge/main.d.ts +13 -13
- package/dist/src/lib/services/aws/eventbridge/main.js +26 -49
- package/dist/src/lib/services/aws/eventbridge/target.d.ts +10 -10
- package/dist/src/lib/services/aws/eventbridge/target.js +6 -29
- package/dist/src/lib/services/aws/evidently/main.d.ts +7 -7
- package/dist/src/lib/services/aws/evidently/main.js +18 -41
- package/dist/src/lib/services/aws/identity-access-management/main.d.ts +48 -49
- package/dist/src/lib/services/aws/identity-access-management/main.js +110 -133
- package/dist/src/lib/services/aws/key-management-service/main.d.ts +2 -2
- package/dist/src/lib/services/aws/key-management-service/main.js +5 -28
- package/dist/src/lib/services/aws/lambda/main.d.ts +11 -13
- package/dist/src/lib/services/aws/lambda/main.js +31 -58
- package/dist/src/lib/services/aws/route53/main.d.ts +9 -9
- package/dist/src/lib/services/aws/route53/main.js +21 -44
- package/dist/src/lib/services/aws/secrets-manager/main.d.ts +5 -6
- package/dist/src/lib/services/aws/secrets-manager/main.js +10 -33
- package/dist/src/lib/services/aws/simple-notification-service/main.d.ts +4 -4
- package/dist/src/lib/services/aws/simple-notification-service/main.js +11 -34
- package/dist/src/lib/services/aws/simple-queue-service/main.d.ts +6 -7
- package/dist/src/lib/services/aws/simple-queue-service/main.js +15 -38
- package/dist/src/lib/services/aws/simple-storage-service/main.d.ts +10 -11
- package/dist/src/lib/services/aws/simple-storage-service/main.js +31 -54
- package/dist/src/lib/services/aws/step-function/main.d.ts +31 -32
- package/dist/src/lib/services/aws/step-function/main.js +33 -57
- package/dist/src/lib/services/aws/systems-manager/main.d.ts +4 -4
- package/dist/src/lib/services/aws/systems-manager/main.js +10 -33
- package/dist/src/lib/services/aws/virtual-private-cloud/main.d.ts +5 -6
- package/dist/src/lib/services/aws/virtual-private-cloud/main.js +14 -37
- package/dist/src/lib/services/aws/web-application-firewall/main.d.ts +3 -3
- package/dist/src/lib/services/aws/web-application-firewall/main.js +8 -31
- package/dist/src/lib/utils/aws/index.d.ts +6 -3
- package/dist/src/lib/utils/aws/index.js +9 -26
- package/package.json +21 -21
- package/src/lib/common/construct.ts +97 -67
- package/src/lib/common/stack.ts +12 -12
- package/src/lib/common/types.ts +2 -2
- package/src/lib/construct/api-to-eventbridge-target/api.ts +31 -22
- package/src/lib/construct/api-to-eventbridge-target/event.ts +9 -9
- package/src/lib/construct/api-to-eventbridge-target/main.ts +56 -41
- package/src/lib/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.ts +9 -9
- package/src/lib/construct/api-to-eventbridge-target-with-sns/main.ts +62 -47
- package/src/lib/construct/api-to-lambda-target/api.ts +33 -23
- package/src/lib/construct/api-to-lambda-target/main.ts +24 -18
- package/src/lib/construct/application-configuration/main.ts +31 -24
- package/src/lib/construct/graphql-api-lambda/main.ts +22 -22
- package/src/lib/construct/graphql-api-lambda-with-cache/main.ts +13 -13
- package/src/lib/construct/lambda-with-iam-access/main.ts +25 -25
- package/src/lib/construct/lambda-with-iam-access/types.ts +4 -4
- package/src/lib/construct/rest-api-lambda/main.ts +21 -21
- package/src/lib/construct/rest-api-lambda-with-cache/main.ts +14 -14
- package/src/lib/construct/site-with-ecs-backend/main.ts +79 -60
- package/src/lib/construct/static-asset-deployment/main.ts +6 -6
- package/src/lib/construct/static-site/main.ts +23 -17
- package/src/lib/services/aws/api-gateway/main.ts +42 -36
- package/src/lib/services/aws/api-gateway/types.ts +2 -2
- package/src/lib/services/aws/appconfig/main.ts +19 -19
- package/src/lib/services/aws/certificate-manager/main.ts +14 -14
- package/src/lib/services/aws/certificate-manager/types.ts +2 -2
- package/src/lib/services/aws/cloudfront/main.ts +88 -74
- package/src/lib/services/aws/cloudfront/types.ts +6 -3
- package/src/lib/services/aws/cloudtrail/main.ts +11 -11
- package/src/lib/services/aws/codebuild/main.ts +7 -7
- package/src/lib/services/aws/dynamodb/main.ts +8 -8
- package/src/lib/services/aws/elastic-container-registry/main.ts +4 -4
- package/src/lib/services/aws/elastic-container-service/main.ts +48 -37
- package/src/lib/services/aws/elastic-container-service/types.ts +4 -4
- package/src/lib/services/aws/elastic-file-system/main.ts +16 -16
- package/src/lib/services/aws/elastic-kubernetes-service/main.ts +11 -11
- package/src/lib/services/aws/elasticache/main.ts +10 -10
- package/src/lib/services/aws/eventbridge/main.ts +37 -37
- package/src/lib/services/aws/eventbridge/target.ts +14 -14
- package/src/lib/services/aws/evidently/main.ts +18 -18
- package/src/lib/services/aws/identity-access-management/main.ts +142 -134
- package/src/lib/services/aws/key-management-service/main.ts +5 -5
- package/src/lib/services/aws/lambda/main.ts +65 -59
- package/src/lib/services/aws/route53/main.ts +31 -31
- package/src/lib/services/aws/secrets-manager/main.ts +11 -15
- package/src/lib/services/aws/simple-notification-service/main.ts +13 -13
- package/src/lib/services/aws/simple-queue-service/main.ts +18 -18
- package/src/lib/services/aws/simple-storage-service/main.ts +40 -40
- package/src/lib/services/aws/step-function/main.ts +77 -65
- package/src/lib/services/aws/systems-manager/main.ts +17 -12
- package/src/lib/services/aws/virtual-private-cloud/main.ts +16 -16
- package/src/lib/services/aws/web-application-firewall/main.ts +8 -8
- package/src/lib/utils/aws/index.ts +8 -5
|
@@ -1,20 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
import
|
|
1
|
+
import { Duration } from 'aws-cdk-lib'
|
|
2
|
+
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'
|
|
3
|
+
import {
|
|
4
|
+
CachePolicy,
|
|
5
|
+
Distribution,
|
|
6
|
+
FunctionAssociation,
|
|
7
|
+
FunctionEventType,
|
|
8
|
+
IFunction,
|
|
9
|
+
OriginProtocolPolicy,
|
|
10
|
+
OriginRequestPolicy,
|
|
11
|
+
ResponseHeadersPolicy,
|
|
12
|
+
} from 'aws-cdk-lib/aws-cloudfront'
|
|
13
|
+
import { HttpOrigin } from 'aws-cdk-lib/aws-cloudfront-origins'
|
|
14
|
+
import { IVpc } from 'aws-cdk-lib/aws-ec2'
|
|
15
|
+
import {
|
|
16
|
+
AssetImage,
|
|
17
|
+
Cluster,
|
|
18
|
+
ContainerImage,
|
|
19
|
+
FargateService,
|
|
20
|
+
FargateTaskDefinition,
|
|
21
|
+
LogDriver,
|
|
22
|
+
} from 'aws-cdk-lib/aws-ecs'
|
|
23
|
+
import { ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns'
|
|
24
|
+
import { FileSystem } from 'aws-cdk-lib/aws-efs'
|
|
25
|
+
import {
|
|
26
|
+
ApplicationListener,
|
|
27
|
+
ApplicationLoadBalancer,
|
|
28
|
+
ApplicationTargetGroup,
|
|
29
|
+
} from 'aws-cdk-lib/aws-elasticloadbalancingv2'
|
|
30
|
+
import { PolicyDocument, PolicyStatement, Role } from 'aws-cdk-lib/aws-iam'
|
|
31
|
+
import { LogGroup } from 'aws-cdk-lib/aws-logs'
|
|
32
|
+
import { IHostedZone } from 'aws-cdk-lib/aws-route53'
|
|
33
|
+
import { IBucket } from 'aws-cdk-lib/aws-s3'
|
|
15
34
|
import { Construct } from 'constructs'
|
|
35
|
+
import _ from 'lodash'
|
|
16
36
|
import { CommonConstruct } from '../../common'
|
|
17
|
-
import {
|
|
37
|
+
import { SiteCachePolicyProps, SiteResponseHeadersPolicyProps, SiteWithEcsBackendProps } from './types'
|
|
18
38
|
|
|
19
39
|
/**
|
|
20
40
|
* @classdesc Provides a construct to create and deploy a site hosted with an clustered ECS/ELB backend
|
|
@@ -37,35 +57,35 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
37
57
|
id: string
|
|
38
58
|
|
|
39
59
|
/* site resources */
|
|
40
|
-
siteHostedZone:
|
|
41
|
-
siteCertificate:
|
|
42
|
-
siteRegionalCertificate:
|
|
43
|
-
siteEcsPolicy:
|
|
44
|
-
siteEcsRole:
|
|
60
|
+
siteHostedZone: IHostedZone
|
|
61
|
+
siteCertificate: ICertificate
|
|
62
|
+
siteRegionalCertificate: ICertificate
|
|
63
|
+
siteEcsPolicy: PolicyDocument
|
|
64
|
+
siteEcsRole: Role
|
|
45
65
|
siteEcsEnvironment: { [key: string]: string }
|
|
46
|
-
siteVpc:
|
|
66
|
+
siteVpc: IVpc
|
|
47
67
|
siteSecrets: any
|
|
48
|
-
siteEcsCluster:
|
|
49
|
-
siteEcsLogGroup:
|
|
68
|
+
siteEcsCluster: Cluster
|
|
69
|
+
siteEcsLogGroup: LogGroup
|
|
50
70
|
siteEcsBuildArgs: any = {}
|
|
51
|
-
siteEcsContainerImage:
|
|
52
|
-
siteEcsService:
|
|
53
|
-
siteEcsTaskDefinition:
|
|
54
|
-
siteEcsListener:
|
|
55
|
-
siteEcsLoadBalancer:
|
|
56
|
-
siteEcsTargetGroup:
|
|
57
|
-
siteFileSystem:
|
|
58
|
-
siteLogBucket:
|
|
59
|
-
siteOrigin:
|
|
60
|
-
siteDistribution:
|
|
71
|
+
siteEcsContainerImage: AssetImage
|
|
72
|
+
siteEcsService: FargateService
|
|
73
|
+
siteEcsTaskDefinition: FargateTaskDefinition
|
|
74
|
+
siteEcsListener: ApplicationListener
|
|
75
|
+
siteEcsLoadBalancer: ApplicationLoadBalancer
|
|
76
|
+
siteEcsTargetGroup: ApplicationTargetGroup
|
|
77
|
+
siteFileSystem: FileSystem
|
|
78
|
+
siteLogBucket: IBucket
|
|
79
|
+
siteOrigin: HttpOrigin
|
|
80
|
+
siteDistribution: Distribution
|
|
61
81
|
siteInternalDomainName: string
|
|
62
82
|
siteExternalDomainName: string
|
|
63
83
|
siteDomainNames: string[]
|
|
64
|
-
siteCloudfrontFunction:
|
|
65
|
-
siteFunctionAssociations:
|
|
66
|
-
siteOriginRequestPolicy:
|
|
67
|
-
siteOriginResponseHeadersPolicy?:
|
|
68
|
-
siteCachePolicy:
|
|
84
|
+
siteCloudfrontFunction: IFunction
|
|
85
|
+
siteFunctionAssociations: FunctionAssociation[]
|
|
86
|
+
siteOriginRequestPolicy: OriginRequestPolicy
|
|
87
|
+
siteOriginResponseHeadersPolicy?: ResponseHeadersPolicy
|
|
88
|
+
siteCachePolicy: CachePolicy
|
|
69
89
|
|
|
70
90
|
constructor(parent: Construct, id: string, props: SiteWithEcsBackendProps) {
|
|
71
91
|
super(parent, id, props)
|
|
@@ -203,7 +223,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
203
223
|
* @summary Method to create iam policy for ECS Task
|
|
204
224
|
*/
|
|
205
225
|
protected createEcsPolicy() {
|
|
206
|
-
this.siteEcsPolicy = new
|
|
226
|
+
this.siteEcsPolicy = new PolicyDocument({
|
|
207
227
|
statements: [this.iamManager.statementForCreateAnyLogStream()],
|
|
208
228
|
})
|
|
209
229
|
}
|
|
@@ -256,16 +276,16 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
256
276
|
* Method to create container image for ECS task
|
|
257
277
|
*/
|
|
258
278
|
protected createEcsContainerImage() {
|
|
259
|
-
this.siteEcsContainerImage =
|
|
279
|
+
this.siteEcsContainerImage = ContainerImage.fromAsset(this.props.siteEcsContainerImagePath, {
|
|
260
280
|
buildArgs: this.siteEcsBuildArgs,
|
|
261
281
|
})
|
|
262
282
|
}
|
|
263
283
|
|
|
264
284
|
/**
|
|
265
|
-
* Method to create Application
|
|
285
|
+
* Method to create Application Load balanced ECS Fargate Service
|
|
266
286
|
*/
|
|
267
287
|
protected createEcsService() {
|
|
268
|
-
const fargateService = new
|
|
288
|
+
const fargateService = new ApplicationLoadBalancedFargateService(this, `${this.id}-ecs-service`, {
|
|
269
289
|
assignPublicIp: true,
|
|
270
290
|
certificate: this.siteRegionalCertificate,
|
|
271
291
|
cluster: this.siteEcsCluster,
|
|
@@ -274,7 +294,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
274
294
|
domainName: this.siteInternalDomainName,
|
|
275
295
|
domainZone: this.siteHostedZone,
|
|
276
296
|
enableECSManagedTags: true,
|
|
277
|
-
healthCheckGracePeriod:
|
|
297
|
+
healthCheckGracePeriod: Duration.seconds(60),
|
|
278
298
|
listenerPort: this.props.siteTask.listenerPort,
|
|
279
299
|
loadBalancerName: this.props.siteTask.loadBalancerName
|
|
280
300
|
? `${this.props.siteTask.loadBalancerName}-${this.props.stage}`
|
|
@@ -290,7 +310,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
290
310
|
environment: this.siteEcsEnvironment,
|
|
291
311
|
executionRole: this.siteEcsRole,
|
|
292
312
|
image: this.siteEcsContainerImage,
|
|
293
|
-
logDriver:
|
|
313
|
+
logDriver: LogDriver.awsLogs({
|
|
294
314
|
logGroup: this.siteEcsLogGroup,
|
|
295
315
|
logRetention: this.props.siteTask.logging?.logRetention,
|
|
296
316
|
multilinePattern: this.props.siteTask.logging?.multilinePattern,
|
|
@@ -307,11 +327,11 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
307
327
|
healthyGrpcCodes: this.props.siteHealthCheck.healthyGrpcCodes,
|
|
308
328
|
healthyHttpCodes: this.props.siteHealthCheck.healthyHttpCodes,
|
|
309
329
|
healthyThresholdCount: this.props.siteHealthCheck.healthyThresholdCount,
|
|
310
|
-
interval:
|
|
330
|
+
interval: Duration.seconds(this.props.siteHealthCheck.intervalInSecs),
|
|
311
331
|
path: this.props.siteHealthCheck.path ?? '/',
|
|
312
332
|
port: this.props.siteHealthCheck.port,
|
|
313
333
|
protocol: this.props.siteHealthCheck.protocol,
|
|
314
|
-
timeout:
|
|
334
|
+
timeout: Duration.seconds(this.props.siteHealthCheck.timeoutInSecs),
|
|
315
335
|
unhealthyThresholdCount: this.props.siteHealthCheck.unhealthyThresholdCount,
|
|
316
336
|
})
|
|
317
337
|
}
|
|
@@ -370,7 +390,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
370
390
|
|
|
371
391
|
/* add EFS permissions to ECS Role */
|
|
372
392
|
this.siteEcsRole.addToPolicy(
|
|
373
|
-
new
|
|
393
|
+
new PolicyStatement(this.iamManager.statementForWriteEfs([this.siteFileSystem.fileSystemArn]))
|
|
374
394
|
)
|
|
375
395
|
|
|
376
396
|
/* add the efs volume to ecs task definition */
|
|
@@ -411,17 +431,16 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
411
431
|
}
|
|
412
432
|
|
|
413
433
|
protected createSiteCachePolicy(id: string, siteCachePolicy: SiteCachePolicyProps) {
|
|
414
|
-
return new
|
|
434
|
+
return new CachePolicy(this, `${id}`, {
|
|
415
435
|
cachePolicyName: `${this.id}-${siteCachePolicy.cachePolicyName}`,
|
|
416
436
|
comment: `Policy for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
417
|
-
|
|
418
|
-
minTtl: cdk.Duration.seconds(siteCachePolicy.minTtlInSeconds),
|
|
419
|
-
maxTtl: cdk.Duration.seconds(siteCachePolicy.maxTtlInSeconds),
|
|
420
|
-
enableAcceptEncodingGzip: siteCachePolicy.enableAcceptEncodingGzip,
|
|
437
|
+
cookieBehavior: siteCachePolicy.cookieBehavior,
|
|
421
438
|
enableAcceptEncodingBrotli: siteCachePolicy.enableAcceptEncodingBrotli,
|
|
422
|
-
|
|
439
|
+
enableAcceptEncodingGzip: siteCachePolicy.enableAcceptEncodingGzip,
|
|
423
440
|
headerBehavior: siteCachePolicy.headerBehavior,
|
|
424
|
-
|
|
441
|
+
maxTtl: Duration.seconds(siteCachePolicy.maxTtlInSeconds),
|
|
442
|
+
minTtl: Duration.seconds(siteCachePolicy.minTtlInSeconds),
|
|
443
|
+
queryStringBehavior: siteCachePolicy.queryStringBehavior,
|
|
425
444
|
})
|
|
426
445
|
}
|
|
427
446
|
|
|
@@ -435,7 +454,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
435
454
|
|
|
436
455
|
protected createSiteOriginRequestPolicy() {
|
|
437
456
|
if (!this.props.siteOriginRequestPolicy) return
|
|
438
|
-
this.siteOriginRequestPolicy = new
|
|
457
|
+
this.siteOriginRequestPolicy = new OriginRequestPolicy(this, `${this.id}-sorp`, {
|
|
439
458
|
comment: `Request Policy for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
440
459
|
cookieBehavior: this.props.siteOriginRequestPolicy.cookieBehavior,
|
|
441
460
|
headerBehavior: this.props.siteOriginRequestPolicy.headerBehavior,
|
|
@@ -450,7 +469,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
450
469
|
|
|
451
470
|
protected createResponseHeaderPolicy(props: SiteResponseHeadersPolicyProps) {
|
|
452
471
|
if (!props) return undefined
|
|
453
|
-
return new
|
|
472
|
+
return new ResponseHeadersPolicy(this, `${this.id}-${props.type}-srhp`, {
|
|
454
473
|
...props,
|
|
455
474
|
comment: `Response Header Policy for ${props.type} for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
456
475
|
responseHeadersPolicyName: `${this.id}-${props.type}-response`,
|
|
@@ -458,7 +477,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
458
477
|
...props.securityHeadersBehavior,
|
|
459
478
|
strictTransportSecurity: {
|
|
460
479
|
...props.securityHeadersBehavior?.strictTransportSecurity,
|
|
461
|
-
accessControlMaxAge:
|
|
480
|
+
accessControlMaxAge: Duration.seconds(
|
|
462
481
|
props.securityHeadersBehavior?.strictTransportSecurity?.accessControlMaxAgeInSeconds
|
|
463
482
|
),
|
|
464
483
|
},
|
|
@@ -475,10 +494,10 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
475
494
|
}
|
|
476
495
|
|
|
477
496
|
protected createSiteOrigin() {
|
|
478
|
-
this.siteOrigin = new
|
|
497
|
+
this.siteOrigin = new HttpOrigin(this.siteInternalDomainName, {
|
|
479
498
|
httpPort: this.props.siteTask.listenerPort,
|
|
480
499
|
originId: `${this.id}-server`,
|
|
481
|
-
protocolPolicy:
|
|
500
|
+
protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,
|
|
482
501
|
})
|
|
483
502
|
}
|
|
484
503
|
|
|
@@ -502,7 +521,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
502
521
|
if (this.props.siteCloudfrontFunctionProps) {
|
|
503
522
|
this.siteFunctionAssociations = [
|
|
504
523
|
{
|
|
505
|
-
eventType:
|
|
524
|
+
eventType: FunctionEventType.VIEWER_REQUEST,
|
|
506
525
|
function: this.siteCloudfrontFunction,
|
|
507
526
|
},
|
|
508
527
|
]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IBucket } from 'aws-cdk-lib/aws-s3'
|
|
2
|
+
import { BucketDeployment } from 'aws-cdk-lib/aws-s3-deployment'
|
|
2
3
|
import { Construct } from 'constructs'
|
|
3
|
-
import
|
|
4
|
-
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment'
|
|
4
|
+
import { CommonConstruct } from '../../common'
|
|
5
5
|
import { StaticAssetDeploymentProps } from './types'
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -25,7 +25,7 @@ export class StaticAssetDeployment extends CommonConstruct {
|
|
|
25
25
|
id: string
|
|
26
26
|
|
|
27
27
|
/* construct resources */
|
|
28
|
-
staticAssetBucket:
|
|
28
|
+
staticAssetBucket: IBucket
|
|
29
29
|
|
|
30
30
|
constructor(parent: Construct, id: string, props: StaticAssetDeploymentProps) {
|
|
31
31
|
super(parent, id, props)
|
|
@@ -49,10 +49,10 @@ export class StaticAssetDeployment extends CommonConstruct {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
* @summary Deploy the static
|
|
52
|
+
* @summary Deploy the static assets into the static asset bucket
|
|
53
53
|
*/
|
|
54
54
|
protected deployStaticAssets() {
|
|
55
|
-
new
|
|
55
|
+
new BucketDeployment(this, `${this.id}-static-deployment`, {
|
|
56
56
|
...this.props.staticAssetDeployment,
|
|
57
57
|
destinationBucket: this.staticAssetBucket,
|
|
58
58
|
sources: this.props.staticAssetSources,
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'
|
|
2
|
+
import {
|
|
3
|
+
FunctionAssociation,
|
|
4
|
+
FunctionEventType,
|
|
5
|
+
IDistribution,
|
|
6
|
+
IFunction,
|
|
7
|
+
OriginAccessIdentity,
|
|
8
|
+
} from 'aws-cdk-lib/aws-cloudfront'
|
|
9
|
+
import { S3Origin } from 'aws-cdk-lib/aws-cloudfront-origins'
|
|
10
|
+
import { ARecord, IHostedZone } from 'aws-cdk-lib/aws-route53'
|
|
11
|
+
import { IBucket } from 'aws-cdk-lib/aws-s3'
|
|
6
12
|
import { Construct } from 'constructs'
|
|
7
13
|
import { CommonConstruct } from '../../common'
|
|
8
14
|
import { StaticSiteProps } from './types'
|
|
@@ -28,16 +34,16 @@ export class StaticSite extends CommonConstruct {
|
|
|
28
34
|
id: string
|
|
29
35
|
|
|
30
36
|
/* static site resources */
|
|
31
|
-
siteHostedZone:
|
|
32
|
-
siteCertificate:
|
|
33
|
-
siteARecord:
|
|
34
|
-
siteBucket:
|
|
35
|
-
siteOrigin:
|
|
36
|
-
siteDistribution:
|
|
37
|
-
siteLogBucket:
|
|
38
|
-
siteOriginAccessIdentity:
|
|
39
|
-
siteCloudfrontFunction:
|
|
40
|
-
siteFunctionAssociations:
|
|
37
|
+
siteHostedZone: IHostedZone
|
|
38
|
+
siteCertificate: ICertificate
|
|
39
|
+
siteARecord: ARecord
|
|
40
|
+
siteBucket: IBucket
|
|
41
|
+
siteOrigin: S3Origin
|
|
42
|
+
siteDistribution: IDistribution
|
|
43
|
+
siteLogBucket: IBucket
|
|
44
|
+
siteOriginAccessIdentity: OriginAccessIdentity
|
|
45
|
+
siteCloudfrontFunction: IFunction
|
|
46
|
+
siteFunctionAssociations: FunctionAssociation[]
|
|
41
47
|
|
|
42
48
|
constructor(parent: Construct, id: string, props: StaticSiteProps) {
|
|
43
49
|
super(parent, id, props)
|
|
@@ -113,7 +119,7 @@ export class StaticSite extends CommonConstruct {
|
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
protected createSiteOrigin() {
|
|
116
|
-
this.siteOrigin = new
|
|
122
|
+
this.siteOrigin = new S3Origin(this.siteBucket)
|
|
117
123
|
}
|
|
118
124
|
|
|
119
125
|
/**
|
|
@@ -136,7 +142,7 @@ export class StaticSite extends CommonConstruct {
|
|
|
136
142
|
if (this.props.siteCloudfrontFunctionProps) {
|
|
137
143
|
this.siteFunctionAssociations = [
|
|
138
144
|
{
|
|
139
|
-
eventType:
|
|
145
|
+
eventType: FunctionEventType.VIEWER_REQUEST,
|
|
140
146
|
function: this.siteCloudfrontFunction,
|
|
141
147
|
},
|
|
142
148
|
]
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Tags } from 'aws-cdk-lib'
|
|
2
|
+
import {
|
|
3
|
+
Cors,
|
|
4
|
+
Deployment,
|
|
5
|
+
DomainName,
|
|
6
|
+
EndpointType,
|
|
7
|
+
IAuthorizer,
|
|
8
|
+
IResource,
|
|
9
|
+
IRestApi,
|
|
10
|
+
Integration,
|
|
11
|
+
LambdaRestApi,
|
|
12
|
+
SecurityPolicy,
|
|
13
|
+
} from 'aws-cdk-lib/aws-apigateway'
|
|
14
|
+
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'
|
|
15
|
+
import { IFunction } from 'aws-cdk-lib/aws-lambda'
|
|
7
16
|
import { CommonConstruct } from '../../../common'
|
|
17
|
+
import { createCfnOutput } from '../../../utils'
|
|
18
|
+
import { LambdaRestApiProps } from './types'
|
|
8
19
|
|
|
9
20
|
/**
|
|
10
21
|
* @classdesc Provides operations on AWS API Gateway.
|
|
@@ -14,7 +25,7 @@ import { CommonConstruct } from '../../../common'
|
|
|
14
25
|
* import { CommonConstruct } from '@gradientedge/cdk-utils'
|
|
15
26
|
*
|
|
16
27
|
* class CustomConstruct extends CommonConstruct {
|
|
17
|
-
* constructor(parent:
|
|
28
|
+
* constructor(parent: Construct, id: string, props: common.CommonStackProps) {
|
|
18
29
|
* super(parent, id, props)
|
|
19
30
|
* this.props = props
|
|
20
31
|
* const lambdaFunction = this.lambdaManager.createLambdaFunction('MyFunction', this, role, layers, code)
|
|
@@ -31,14 +42,9 @@ export class ApiManager {
|
|
|
31
42
|
* @param props lambda rest restApi props
|
|
32
43
|
* @param lambdaFunction
|
|
33
44
|
*/
|
|
34
|
-
public createLambdaRestApi(
|
|
35
|
-
id: string,
|
|
36
|
-
scope: CommonConstruct,
|
|
37
|
-
props: LambdaRestApiProps,
|
|
38
|
-
lambdaFunction: lambda.IFunction
|
|
39
|
-
) {
|
|
45
|
+
public createLambdaRestApi(id: string, scope: CommonConstruct, props: LambdaRestApiProps, lambdaFunction: IFunction) {
|
|
40
46
|
if (!props) throw `Api props undefined for ${id}`
|
|
41
|
-
const api = new
|
|
47
|
+
const api = new LambdaRestApi(scope, `${id}`, {
|
|
42
48
|
binaryMediaTypes: props.binaryMediaTypes,
|
|
43
49
|
cloudWatchRole: props.cloudWatchRole || false,
|
|
44
50
|
defaultCorsPreflightOptions: props.defaultCorsPreflightOptions,
|
|
@@ -63,7 +69,7 @@ export class ApiManager {
|
|
|
63
69
|
},
|
|
64
70
|
domainName: props.domainName,
|
|
65
71
|
endpointConfiguration: {
|
|
66
|
-
types: props.endpointConfiguration?.types || [
|
|
72
|
+
types: props.endpointConfiguration?.types || [EndpointType.REGIONAL],
|
|
67
73
|
vpcEndpoints: props.endpointConfiguration?.vpcEndpoints,
|
|
68
74
|
},
|
|
69
75
|
endpointTypes: props.endpointTypes,
|
|
@@ -79,12 +85,12 @@ export class ApiManager {
|
|
|
79
85
|
|
|
80
86
|
if (props.tags && props.tags.length > 0) {
|
|
81
87
|
props.tags.forEach(tag => {
|
|
82
|
-
|
|
88
|
+
Tags.of(api).add(tag.key, tag.value)
|
|
83
89
|
})
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
createCfnOutput(`${id}-restApiId`, scope, api.restApiId)
|
|
93
|
+
createCfnOutput(`${id}-restApiName`, scope, api.restApiName)
|
|
88
94
|
|
|
89
95
|
return api
|
|
90
96
|
}
|
|
@@ -96,15 +102,15 @@ export class ApiManager {
|
|
|
96
102
|
* @param domainName the domain name to use
|
|
97
103
|
* @param certificate the certificate used for custom restApi domain
|
|
98
104
|
*/
|
|
99
|
-
public createApiDomain(id: string, scope: CommonConstruct, domainName: string, certificate:
|
|
100
|
-
const apiDomain = new
|
|
105
|
+
public createApiDomain(id: string, scope: CommonConstruct, domainName: string, certificate: ICertificate) {
|
|
106
|
+
const apiDomain = new DomainName(scope, `${id}`, {
|
|
101
107
|
certificate: certificate,
|
|
102
108
|
domainName: domainName,
|
|
103
|
-
endpointType: scope.isProductionStage() ?
|
|
104
|
-
securityPolicy:
|
|
109
|
+
endpointType: scope.isProductionStage() ? EndpointType.EDGE : EndpointType.REGIONAL,
|
|
110
|
+
securityPolicy: SecurityPolicy.TLS_1_2,
|
|
105
111
|
})
|
|
106
112
|
|
|
107
|
-
|
|
113
|
+
createCfnOutput(`${id}-customDomainName`, scope, apiDomain.domainName)
|
|
108
114
|
|
|
109
115
|
return apiDomain
|
|
110
116
|
}
|
|
@@ -127,24 +133,24 @@ export class ApiManager {
|
|
|
127
133
|
public createApiResource(
|
|
128
134
|
id: string,
|
|
129
135
|
scope: CommonConstruct,
|
|
130
|
-
parent:
|
|
136
|
+
parent: IResource,
|
|
131
137
|
path: string,
|
|
132
|
-
integration:
|
|
138
|
+
integration: Integration,
|
|
133
139
|
addProxy: boolean,
|
|
134
|
-
authorizer?:
|
|
140
|
+
authorizer?: IAuthorizer,
|
|
135
141
|
allowedOrigins?: string[],
|
|
136
142
|
allowedMethods?: string[],
|
|
137
143
|
allowedHeaders?: string[],
|
|
138
144
|
methodRequestParameters?: { [param: string]: boolean },
|
|
139
|
-
proxyIntegration?:
|
|
145
|
+
proxyIntegration?: Integration
|
|
140
146
|
) {
|
|
141
|
-
const methods = allowedMethods ??
|
|
147
|
+
const methods = allowedMethods ?? Cors.ALL_METHODS
|
|
142
148
|
const resource = parent.addResource(path, {
|
|
143
149
|
defaultCorsPreflightOptions: {
|
|
144
150
|
allowCredentials: true,
|
|
145
|
-
allowHeaders: allowedHeaders ??
|
|
151
|
+
allowHeaders: allowedHeaders ?? Cors.DEFAULT_HEADERS,
|
|
146
152
|
allowMethods: [...methods, 'OPTIONS'],
|
|
147
|
-
allowOrigins: allowedOrigins ??
|
|
153
|
+
allowOrigins: allowedOrigins ?? Cors.ALL_ORIGINS,
|
|
148
154
|
},
|
|
149
155
|
})
|
|
150
156
|
methods.forEach(method =>
|
|
@@ -153,15 +159,15 @@ export class ApiManager {
|
|
|
153
159
|
requestParameters: methodRequestParameters,
|
|
154
160
|
})
|
|
155
161
|
)
|
|
156
|
-
|
|
162
|
+
createCfnOutput(`${id}-${path}ResourceId`, scope, resource.resourceId)
|
|
157
163
|
|
|
158
164
|
if (addProxy) {
|
|
159
165
|
const resourceProxy = resource.addResource(`{${path}+}`, {
|
|
160
166
|
defaultCorsPreflightOptions: {
|
|
161
167
|
allowCredentials: true,
|
|
162
|
-
allowHeaders: allowedHeaders ??
|
|
168
|
+
allowHeaders: allowedHeaders ?? Cors.DEFAULT_HEADERS,
|
|
163
169
|
allowMethods: [...methods, 'OPTIONS'],
|
|
164
|
-
allowOrigins: allowedOrigins ??
|
|
170
|
+
allowOrigins: allowedOrigins ?? Cors.ALL_ORIGINS,
|
|
165
171
|
},
|
|
166
172
|
})
|
|
167
173
|
methods.forEach(method =>
|
|
@@ -170,7 +176,7 @@ export class ApiManager {
|
|
|
170
176
|
requestParameters: methodRequestParameters,
|
|
171
177
|
})
|
|
172
178
|
)
|
|
173
|
-
|
|
179
|
+
createCfnOutput(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId)
|
|
174
180
|
}
|
|
175
181
|
|
|
176
182
|
return resource
|
|
@@ -182,8 +188,8 @@ export class ApiManager {
|
|
|
182
188
|
* @param scope
|
|
183
189
|
* @param restApi
|
|
184
190
|
*/
|
|
185
|
-
public createApiDeployment(id: string, scope: CommonConstruct, restApi:
|
|
186
|
-
new
|
|
191
|
+
public createApiDeployment(id: string, scope: CommonConstruct, restApi: IRestApi) {
|
|
192
|
+
new Deployment(scope, `${id}`, {
|
|
187
193
|
api: restApi,
|
|
188
194
|
retainDeployments: false,
|
|
189
195
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { LambdaRestApiProps as LambdaRestApigProps } from 'aws-cdk-lib/aws-apigateway'
|
|
1
2
|
import { TagProps } from '../../../types'
|
|
2
|
-
import * as apig from 'aws-cdk-lib/aws-apigateway'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*/
|
|
6
|
-
export interface LambdaRestApiProps extends
|
|
6
|
+
export interface LambdaRestApiProps extends LambdaRestApigProps {
|
|
7
7
|
tags?: TagProps[]
|
|
8
8
|
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { Fn } from 'aws-cdk-lib'
|
|
2
|
+
import { CfnApplication, CfnConfigurationProfile, CfnEnvironment } from 'aws-cdk-lib/aws-appconfig'
|
|
3
|
+
import { CommonConstruct } from '../../../common'
|
|
4
|
+
import { createCfnOutput } from '../../../utils'
|
|
4
5
|
import { Architecture } from '../constants'
|
|
5
|
-
import { AppConfigProps } from './types'
|
|
6
6
|
import { ArnsByRegionForArm64, ArnsByRegionForX86_64 } from './constants'
|
|
7
|
-
import {
|
|
7
|
+
import { AppConfigProps } from './types'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @classdesc Provides operations on AWS
|
|
10
|
+
* @classdesc Provides operations on AWS
|
|
11
11
|
* - A new instance of this class is injected into {@link CommonConstruct} constructor.
|
|
12
12
|
* - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
|
|
13
13
|
* @example
|
|
14
14
|
* import { CommonConstruct } from '@gradientedge/cdk-utils'
|
|
15
15
|
*
|
|
16
16
|
* class CustomConstruct extends CommonConstruct {
|
|
17
|
-
* constructor(parent:
|
|
17
|
+
* constructor(parent: Construct, id: string, props: common.CommonStackProps) {
|
|
18
18
|
* super(parent, id, props)
|
|
19
19
|
* this.props = props
|
|
20
20
|
* this.appConfigManager.createApplication('MyApplication', this)
|
|
@@ -46,17 +46,17 @@ export class AppConfigManager {
|
|
|
46
46
|
* @param props
|
|
47
47
|
* @returns the appconfig application
|
|
48
48
|
*/
|
|
49
|
-
public createApplication(id: string, scope: CommonConstruct, props: AppConfigProps):
|
|
49
|
+
public createApplication(id: string, scope: CommonConstruct, props: AppConfigProps): CfnApplication {
|
|
50
50
|
if (!props) throw `AppConfig props undefined for ${id}`
|
|
51
51
|
|
|
52
|
-
const application = new
|
|
52
|
+
const application = new CfnApplication(scope, `${id}`, {
|
|
53
53
|
description: props.application.description,
|
|
54
54
|
name: `${props.application.name}-${scope.props.stage}`,
|
|
55
55
|
tags: props.application.tags,
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
createCfnOutput(`${id}-ApplicationId`, scope, Fn.ref(application.logicalId))
|
|
59
|
+
createCfnOutput(`${id}-ApplicationName`, scope, application.name)
|
|
60
60
|
|
|
61
61
|
return application
|
|
62
62
|
}
|
|
@@ -74,10 +74,10 @@ export class AppConfigManager {
|
|
|
74
74
|
scope: CommonConstruct,
|
|
75
75
|
applicationId: string,
|
|
76
76
|
props: AppConfigProps
|
|
77
|
-
):
|
|
77
|
+
): CfnEnvironment {
|
|
78
78
|
if (!props) throw `AppConfig props undefined for ${id}`
|
|
79
79
|
|
|
80
|
-
const environment = new
|
|
80
|
+
const environment = new CfnEnvironment(scope, `${id}`, {
|
|
81
81
|
applicationId: applicationId,
|
|
82
82
|
description: props.environment.description,
|
|
83
83
|
monitors: props.environment.monitors,
|
|
@@ -85,8 +85,8 @@ export class AppConfigManager {
|
|
|
85
85
|
tags: props.environment.tags,
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
createCfnOutput(`${id}-configurationEnvironmentId`, scope, Fn.ref(environment.logicalId))
|
|
89
|
+
createCfnOutput(`${id}-configurationEnvironmentName`, scope, environment.name)
|
|
90
90
|
|
|
91
91
|
return environment
|
|
92
92
|
}
|
|
@@ -105,10 +105,10 @@ export class AppConfigManager {
|
|
|
105
105
|
scope: CommonConstruct,
|
|
106
106
|
applicationId: string,
|
|
107
107
|
props: AppConfigProps
|
|
108
|
-
):
|
|
108
|
+
): CfnConfigurationProfile {
|
|
109
109
|
if (!props) throw `AppConfig props undefined for ${id}`
|
|
110
110
|
|
|
111
|
-
const profile = new
|
|
111
|
+
const profile = new CfnConfigurationProfile(scope, `${id}`, {
|
|
112
112
|
applicationId: applicationId,
|
|
113
113
|
description: props.configurationProfile.description,
|
|
114
114
|
locationUri: props.configurationProfile.locationUri || 'hosted',
|
|
@@ -119,8 +119,8 @@ export class AppConfigManager {
|
|
|
119
119
|
validators: props.configurationProfile.validators,
|
|
120
120
|
})
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
createCfnOutput(`${id}-configurationProfileId`, scope, Fn.ref(profile.logicalId))
|
|
123
|
+
createCfnOutput(`${id}-configurationProfileName`, scope, profile.name)
|
|
124
124
|
|
|
125
125
|
return profile
|
|
126
126
|
}
|