@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,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as utils from '../../../utils'
|
|
1
|
+
import { Key } from 'aws-cdk-lib/aws-kms'
|
|
3
2
|
import { CommonConstruct } from '../../../common'
|
|
3
|
+
import { createCfnOutput } from '../../../utils'
|
|
4
4
|
import { KmsKeyProps } from './types'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -29,7 +29,7 @@ export class KmsManager {
|
|
|
29
29
|
public createKey(id: string, scope: CommonConstruct, props: KmsKeyProps) {
|
|
30
30
|
if (!props) throw `KMS Key props undefined for ${id}`
|
|
31
31
|
|
|
32
|
-
const key = new
|
|
32
|
+
const key = new Key(scope, `${id}`, {
|
|
33
33
|
admins: props.admins,
|
|
34
34
|
alias: `${props.alias}-${scope.props.stage}`,
|
|
35
35
|
description: props.description,
|
|
@@ -42,8 +42,8 @@ export class KmsManager {
|
|
|
42
42
|
removalPolicy: props.removalPolicy,
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
createCfnOutput(`${id}-keyId`, scope, key.keyId)
|
|
46
|
+
createCfnOutput(`${id}-keyArn`, scope, key.keyArn)
|
|
47
47
|
|
|
48
48
|
return key
|
|
49
49
|
}
|
|
@@ -1,25 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Duration, Tags } from 'aws-cdk-lib'
|
|
2
|
+
import { ISecurityGroup, IVpc, SubnetSelection } from 'aws-cdk-lib/aws-ec2'
|
|
3
|
+
import { IAccessPoint } from 'aws-cdk-lib/aws-efs'
|
|
4
|
+
import { CfnRole, Role } from 'aws-cdk-lib/aws-iam'
|
|
5
|
+
import {
|
|
6
|
+
Alias,
|
|
7
|
+
Architecture,
|
|
8
|
+
AssetCode,
|
|
9
|
+
DockerImageCode,
|
|
10
|
+
DockerImageFunction,
|
|
11
|
+
FileSystem,
|
|
12
|
+
Function,
|
|
13
|
+
ILayerVersion,
|
|
14
|
+
IVersion,
|
|
15
|
+
LayerVersion,
|
|
16
|
+
} from 'aws-cdk-lib/aws-lambda'
|
|
17
|
+
import { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources'
|
|
9
18
|
import { CommonConstruct, CommonStack } from '../../../common'
|
|
10
|
-
import {
|
|
19
|
+
import { createCfnOutput } from '../../../utils'
|
|
11
20
|
import { CloudFrontManager } from '../cloudfront'
|
|
12
21
|
import { SsmManager } from '../systems-manager'
|
|
22
|
+
import { LambdaAliasProps, LambdaEdgeProps, LambdaProps } from './types'
|
|
13
23
|
|
|
14
24
|
/**
|
|
15
|
-
* @classdesc Provides operations on AWS Lambda
|
|
25
|
+
* @classdesc Provides operations on AWS Lambda
|
|
16
26
|
* - A new instance of this class is injected into {@link CommonConstruct} constructor.
|
|
17
27
|
* - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
|
|
18
28
|
* @example
|
|
19
29
|
* import { CommonConstruct } from '@gradientedge/cdk-utils'
|
|
20
30
|
*
|
|
21
31
|
* class CustomConstruct extends CommonConstruct {
|
|
22
|
-
* constructor(parent:
|
|
32
|
+
* constructor(parent: Construct, id: string, props: common.CommonStackProps) {
|
|
23
33
|
* super(parent, id, props)
|
|
24
34
|
* this.props = props
|
|
25
35
|
* this.lambdaManager.createLambdaFunction('MyFunction', this, role, layers, code)
|
|
@@ -34,15 +44,15 @@ export class LambdaManager {
|
|
|
34
44
|
* @param scope scope in which this resource is defined
|
|
35
45
|
* @param code
|
|
36
46
|
*/
|
|
37
|
-
public createLambdaLayer(id: string, scope: CommonConstruct, code:
|
|
38
|
-
const lambdaLayer = new
|
|
47
|
+
public createLambdaLayer(id: string, scope: CommonConstruct, code: AssetCode) {
|
|
48
|
+
const lambdaLayer = new LayerVersion(scope, `${id}`, {
|
|
39
49
|
code: code,
|
|
40
50
|
compatibleRuntimes: [scope.props.nodejsRuntime ?? CommonStack.NODEJS_RUNTIME],
|
|
41
51
|
description: `${id}`,
|
|
42
52
|
layerVersionName: `${id}-${scope.props.stage}`,
|
|
43
53
|
})
|
|
44
54
|
|
|
45
|
-
|
|
55
|
+
createCfnOutput(`${id}-lambdaLayerArn`, scope, lambdaLayer.layerVersionArn)
|
|
46
56
|
|
|
47
57
|
return lambdaLayer
|
|
48
58
|
}
|
|
@@ -67,16 +77,16 @@ export class LambdaManager {
|
|
|
67
77
|
id: string,
|
|
68
78
|
scope: CommonConstruct,
|
|
69
79
|
props: LambdaProps,
|
|
70
|
-
role:
|
|
71
|
-
layers:
|
|
72
|
-
code:
|
|
80
|
+
role: Role | CfnRole,
|
|
81
|
+
layers: ILayerVersion[],
|
|
82
|
+
code: AssetCode,
|
|
73
83
|
handler?: string,
|
|
74
84
|
environment?: any,
|
|
75
|
-
vpc?:
|
|
76
|
-
securityGroups?:
|
|
77
|
-
accessPoint?:
|
|
85
|
+
vpc?: IVpc,
|
|
86
|
+
securityGroups?: ISecurityGroup[],
|
|
87
|
+
accessPoint?: IAccessPoint,
|
|
78
88
|
mountPath?: string,
|
|
79
|
-
vpcSubnets?:
|
|
89
|
+
vpcSubnets?: SubnetSelection
|
|
80
90
|
) {
|
|
81
91
|
if (!props) throw `Lambda props undefined for ${id}`
|
|
82
92
|
|
|
@@ -88,11 +98,11 @@ export class LambdaManager {
|
|
|
88
98
|
deadLetterQueue = scope.sqsManager.createDeadLetterQueueForLambda(`${id}-dlq`, scope, props, redriveQueue)
|
|
89
99
|
}
|
|
90
100
|
|
|
91
|
-
const lambdaFunction = new
|
|
101
|
+
const lambdaFunction = new Function(scope, `${id}`, {
|
|
92
102
|
...props,
|
|
93
103
|
...{
|
|
94
104
|
allowPublicSubnet: !!vpc,
|
|
95
|
-
architecture: props.architecture ??
|
|
105
|
+
architecture: props.architecture ?? Architecture.ARM_64,
|
|
96
106
|
code: code,
|
|
97
107
|
deadLetterQueue: deadLetterQueue,
|
|
98
108
|
environment: {
|
|
@@ -107,9 +117,7 @@ export class LambdaManager {
|
|
|
107
117
|
STAGE: scope.props.stage,
|
|
108
118
|
...environment,
|
|
109
119
|
},
|
|
110
|
-
filesystem: accessPoint
|
|
111
|
-
? lambda.FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg')
|
|
112
|
-
: undefined,
|
|
120
|
+
filesystem: accessPoint ? FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg') : undefined,
|
|
113
121
|
functionName: functionName,
|
|
114
122
|
handler: handler || 'index.lambda_handler',
|
|
115
123
|
insightsVersion: props.insightsVersion,
|
|
@@ -117,10 +125,10 @@ export class LambdaManager {
|
|
|
117
125
|
logRetention: scope.props.logRetention ?? props.logRetention,
|
|
118
126
|
reservedConcurrentExecutions:
|
|
119
127
|
props.reservedConcurrentExecutions ?? scope.props.defaultReservedLambdaConcurrentExecutions,
|
|
120
|
-
role: role instanceof
|
|
128
|
+
role: role instanceof Role ? role : undefined,
|
|
121
129
|
runtime: props.runtime ?? scope.props.nodejsRuntime ?? CommonStack.NODEJS_RUNTIME,
|
|
122
130
|
securityGroups: securityGroups,
|
|
123
|
-
timeout: props.timeoutInSecs ?
|
|
131
|
+
timeout: props.timeoutInSecs ? Duration.seconds(props.timeoutInSecs) : Duration.minutes(15),
|
|
124
132
|
tracing: scope.props.defaultTracing ?? props.tracing,
|
|
125
133
|
vpc,
|
|
126
134
|
vpcSubnets,
|
|
@@ -129,7 +137,7 @@ export class LambdaManager {
|
|
|
129
137
|
|
|
130
138
|
if (lambdaFunction.deadLetterQueue && props.dlq?.retriesEnabled) {
|
|
131
139
|
lambdaFunction.addEventSource(
|
|
132
|
-
new
|
|
140
|
+
new SqsEventSource(lambdaFunction.deadLetterQueue, {
|
|
133
141
|
batchSize: props.dlq.retryBatchSize ?? 1,
|
|
134
142
|
reportBatchItemFailures: true,
|
|
135
143
|
})
|
|
@@ -140,8 +148,8 @@ export class LambdaManager {
|
|
|
140
148
|
props.lambdaAliases.forEach(alias => {
|
|
141
149
|
const aliasId = alias.id ?? `${id}-${alias.aliasName}`
|
|
142
150
|
const functionAlias = this.createLambdaFunctionAlias(`${aliasId}`, scope, alias, lambdaFunction.currentVersion)
|
|
143
|
-
|
|
144
|
-
|
|
151
|
+
createCfnOutput(`${id}-${alias.aliasName}AliasArn`, scope, functionAlias.functionArn)
|
|
152
|
+
createCfnOutput(`${id}-${alias.aliasName}AliasName`, scope, functionAlias.aliasName)
|
|
145
153
|
|
|
146
154
|
if (alias.provisionedConcurrency) {
|
|
147
155
|
const functionAutoScaling = functionAlias.addAutoScaling(alias.provisionedConcurrency)
|
|
@@ -154,12 +162,12 @@ export class LambdaManager {
|
|
|
154
162
|
|
|
155
163
|
if (props.tags && props.tags.length > 0) {
|
|
156
164
|
props.tags.forEach(tag => {
|
|
157
|
-
|
|
165
|
+
Tags.of(lambdaFunction).add(tag.key, tag.value)
|
|
158
166
|
})
|
|
159
167
|
}
|
|
160
168
|
|
|
161
|
-
|
|
162
|
-
|
|
169
|
+
createCfnOutput(`${id}-lambdaArn`, scope, lambdaFunction.functionArn)
|
|
170
|
+
createCfnOutput(`${id}-lambdaName`, scope, lambdaFunction.functionName)
|
|
163
171
|
|
|
164
172
|
return lambdaFunction
|
|
165
173
|
}
|
|
@@ -182,13 +190,13 @@ export class LambdaManager {
|
|
|
182
190
|
id: string,
|
|
183
191
|
scope: CommonConstruct,
|
|
184
192
|
props: LambdaEdgeProps,
|
|
185
|
-
layers:
|
|
186
|
-
code:
|
|
187
|
-
role:
|
|
193
|
+
layers: ILayerVersion[],
|
|
194
|
+
code: AssetCode,
|
|
195
|
+
role: Role,
|
|
188
196
|
environment?: any,
|
|
189
|
-
vpc?:
|
|
190
|
-
securityGroups?:
|
|
191
|
-
accessPoint?:
|
|
197
|
+
vpc?: IVpc,
|
|
198
|
+
securityGroups?: ISecurityGroup[],
|
|
199
|
+
accessPoint?: IAccessPoint,
|
|
192
200
|
mountPath?: string
|
|
193
201
|
) {
|
|
194
202
|
return new CloudFrontManager().createEdgeFunction(
|
|
@@ -224,14 +232,14 @@ export class LambdaManager {
|
|
|
224
232
|
id: string,
|
|
225
233
|
scope: CommonConstruct,
|
|
226
234
|
props: LambdaProps,
|
|
227
|
-
role:
|
|
228
|
-
code:
|
|
235
|
+
role: Role | CfnRole,
|
|
236
|
+
code: DockerImageCode,
|
|
229
237
|
environment?: any,
|
|
230
|
-
vpc?:
|
|
231
|
-
securityGroups?:
|
|
232
|
-
accessPoint?:
|
|
238
|
+
vpc?: IVpc,
|
|
239
|
+
securityGroups?: ISecurityGroup[],
|
|
240
|
+
accessPoint?: IAccessPoint,
|
|
233
241
|
mountPath?: string,
|
|
234
|
-
vpcSubnets?:
|
|
242
|
+
vpcSubnets?: SubnetSelection
|
|
235
243
|
) {
|
|
236
244
|
if (!props) throw `Lambda props undefined for ${id}`
|
|
237
245
|
|
|
@@ -243,11 +251,11 @@ export class LambdaManager {
|
|
|
243
251
|
deadLetterQueue = scope.sqsManager.createDeadLetterQueueForLambda(`${id}-dlq`, scope, props, redriveQueue)
|
|
244
252
|
}
|
|
245
253
|
|
|
246
|
-
const lambdaFunction = new
|
|
254
|
+
const lambdaFunction = new DockerImageFunction(scope, `${id}`, {
|
|
247
255
|
...props,
|
|
248
256
|
...{
|
|
249
257
|
allowPublicSubnet: !!vpc,
|
|
250
|
-
architecture: props.architecture ??
|
|
258
|
+
architecture: props.architecture ?? Architecture.ARM_64,
|
|
251
259
|
code: code,
|
|
252
260
|
deadLetterQueue: deadLetterQueue,
|
|
253
261
|
environment: {
|
|
@@ -262,17 +270,15 @@ export class LambdaManager {
|
|
|
262
270
|
STAGE: scope.props.stage,
|
|
263
271
|
...environment,
|
|
264
272
|
},
|
|
265
|
-
filesystem: accessPoint
|
|
266
|
-
? lambda.FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg')
|
|
267
|
-
: undefined,
|
|
273
|
+
filesystem: accessPoint ? FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg') : undefined,
|
|
268
274
|
functionName: functionName,
|
|
269
275
|
insightsVersion: props.insightsVersion,
|
|
270
276
|
logRetention: scope.props.logRetention ?? props.logRetention,
|
|
271
277
|
reservedConcurrentExecutions: props.reservedConcurrentExecutions,
|
|
272
|
-
role: role instanceof
|
|
278
|
+
role: role instanceof Role ? role : undefined,
|
|
273
279
|
runtime: props.runtime ?? scope.props.nodejsRuntime ?? CommonStack.NODEJS_RUNTIME,
|
|
274
280
|
securityGroups: securityGroups,
|
|
275
|
-
timeout: props.timeoutInSecs ?
|
|
281
|
+
timeout: props.timeoutInSecs ? Duration.seconds(props.timeoutInSecs) : Duration.minutes(1),
|
|
276
282
|
tracing: props.tracing,
|
|
277
283
|
vpc,
|
|
278
284
|
vpcSubnets,
|
|
@@ -281,15 +287,15 @@ export class LambdaManager {
|
|
|
281
287
|
|
|
282
288
|
if (lambdaFunction.deadLetterQueue && props.dlq?.retriesEnabled) {
|
|
283
289
|
lambdaFunction.addEventSource(
|
|
284
|
-
new
|
|
290
|
+
new SqsEventSource(lambdaFunction.deadLetterQueue, {
|
|
285
291
|
batchSize: props.dlq.retryBatchSize ?? 1,
|
|
286
292
|
reportBatchItemFailures: true,
|
|
287
293
|
})
|
|
288
294
|
)
|
|
289
295
|
}
|
|
290
296
|
|
|
291
|
-
|
|
292
|
-
|
|
297
|
+
createCfnOutput(`${id}-lambdaArn`, scope, lambdaFunction.functionArn)
|
|
298
|
+
createCfnOutput(`${id}-lambdaName`, scope, lambdaFunction.functionName)
|
|
293
299
|
|
|
294
300
|
return lambdaFunction
|
|
295
301
|
}
|
|
@@ -309,7 +315,7 @@ export class LambdaManager {
|
|
|
309
315
|
) {
|
|
310
316
|
if (!props) throw `Lambda Alias props undefined for ${id}`
|
|
311
317
|
|
|
312
|
-
const lambdaFunctionAlias = new
|
|
318
|
+
const lambdaFunctionAlias = new Alias(scope, `${id}`, {
|
|
313
319
|
...props,
|
|
314
320
|
...{
|
|
315
321
|
additionalVersions: props.additionalVersions,
|
|
@@ -324,8 +330,8 @@ export class LambdaManager {
|
|
|
324
330
|
},
|
|
325
331
|
})
|
|
326
332
|
|
|
327
|
-
|
|
328
|
-
|
|
333
|
+
createCfnOutput(`${id}-lambdaAliasName`, scope, lambdaFunctionAlias.functionArn)
|
|
334
|
+
createCfnOutput(`${id}-lambdaAliasArn`, scope, lambdaFunctionAlias.functionName)
|
|
329
335
|
|
|
330
336
|
return lambdaFunctionAlias
|
|
331
337
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import * as utils from '../../../utils'
|
|
1
|
+
import { DomainName } from 'aws-cdk-lib/aws-apigateway'
|
|
2
|
+
import { IDistribution } from 'aws-cdk-lib/aws-cloudfront'
|
|
3
|
+
import { ARecord, HostedZone, IHostedZone, RecordTarget } from 'aws-cdk-lib/aws-route53'
|
|
4
|
+
import { ApiGatewayDomain, CloudFrontTarget } from 'aws-cdk-lib/aws-route53-targets'
|
|
6
5
|
import { CommonConstruct } from '../../../common'
|
|
6
|
+
import { createCfnOutput } from '../../../utils'
|
|
7
7
|
import { Route53Props } from './types'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @classdesc Provides operations on AWS Route53
|
|
10
|
+
* @classdesc Provides operations on AWS Route53
|
|
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
|
|
@@ -30,23 +30,23 @@ export class Route53Manager {
|
|
|
30
30
|
* @param props
|
|
31
31
|
*/
|
|
32
32
|
public createHostedZone(id: string, scope: CommonConstruct, props: Route53Props) {
|
|
33
|
-
let hostedZone:
|
|
33
|
+
let hostedZone: IHostedZone
|
|
34
34
|
|
|
35
35
|
if (!props) throw `Route53 props undefined for ${id}`
|
|
36
36
|
|
|
37
37
|
if (props.useExistingHostedZone) {
|
|
38
|
-
hostedZone =
|
|
38
|
+
hostedZone = HostedZone.fromLookup(scope, `${id}`, {
|
|
39
39
|
domainName: scope.props.domainName,
|
|
40
40
|
})
|
|
41
41
|
} else {
|
|
42
|
-
hostedZone = new
|
|
42
|
+
hostedZone = new HostedZone(scope, `${id}`, {
|
|
43
43
|
comment: `Hosted zone for ${scope.props.domainName}`,
|
|
44
44
|
zoneName: scope.props.domainName,
|
|
45
45
|
})
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
createCfnOutput(`${id}-hostedZoneId`, scope, hostedZone.hostedZoneId)
|
|
49
|
+
createCfnOutput(`${id}-hostedZoneArn`, scope, hostedZone.hostedZoneArn)
|
|
50
50
|
|
|
51
51
|
return hostedZone
|
|
52
52
|
}
|
|
@@ -62,21 +62,21 @@ export class Route53Manager {
|
|
|
62
62
|
scope: CommonConstruct,
|
|
63
63
|
useExistingHostedZone: boolean
|
|
64
64
|
) {
|
|
65
|
-
let hostedZone:
|
|
65
|
+
let hostedZone: IHostedZone
|
|
66
66
|
|
|
67
67
|
if (useExistingHostedZone) {
|
|
68
|
-
hostedZone =
|
|
68
|
+
hostedZone = HostedZone.fromLookup(scope, `${id}`, {
|
|
69
69
|
domainName: scope.fullyQualifiedDomainName,
|
|
70
70
|
})
|
|
71
71
|
} else {
|
|
72
|
-
hostedZone = new
|
|
72
|
+
hostedZone = new HostedZone(scope, `${id}`, {
|
|
73
73
|
comment: `Hosted zone for ${scope.fullyQualifiedDomainName}`,
|
|
74
74
|
zoneName: scope.fullyQualifiedDomainName,
|
|
75
75
|
})
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
createCfnOutput(`${id}-hostedZoneId`, scope, hostedZone.hostedZoneId)
|
|
79
|
+
createCfnOutput(`${id}-hostedZoneArn`, scope, hostedZone.hostedZoneArn)
|
|
80
80
|
|
|
81
81
|
return hostedZone
|
|
82
82
|
}
|
|
@@ -93,24 +93,24 @@ export class Route53Manager {
|
|
|
93
93
|
public createCloudFrontTargetARecord(
|
|
94
94
|
id: string,
|
|
95
95
|
scope: CommonConstruct,
|
|
96
|
-
distribution?:
|
|
97
|
-
hostedZone?:
|
|
96
|
+
distribution?: IDistribution,
|
|
97
|
+
hostedZone?: IHostedZone,
|
|
98
98
|
recordName?: string,
|
|
99
99
|
skipStageFromRecord?: boolean
|
|
100
100
|
) {
|
|
101
101
|
if (!distribution) throw `Distribution undefined for ${id}`
|
|
102
102
|
if (!hostedZone) throw `HostedZone undefined for ${id}`
|
|
103
103
|
|
|
104
|
-
const aRecord = new
|
|
104
|
+
const aRecord = new ARecord(scope, `${id}`, {
|
|
105
105
|
recordName:
|
|
106
106
|
(recordName && scope.isProductionStage()) || skipStageFromRecord
|
|
107
107
|
? `${recordName}`
|
|
108
108
|
: `${recordName}-${scope.props.stage}`,
|
|
109
|
-
target:
|
|
109
|
+
target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),
|
|
110
110
|
zone: hostedZone,
|
|
111
111
|
})
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
createCfnOutput(`${id}-aRecordDomainName`, scope, aRecord.domainName)
|
|
114
114
|
|
|
115
115
|
return aRecord
|
|
116
116
|
}
|
|
@@ -126,20 +126,20 @@ export class Route53Manager {
|
|
|
126
126
|
public createCloudFrontTargetARecordV2(
|
|
127
127
|
id: string,
|
|
128
128
|
scope: CommonConstruct,
|
|
129
|
-
distribution?:
|
|
130
|
-
hostedZone?:
|
|
129
|
+
distribution?: IDistribution,
|
|
130
|
+
hostedZone?: IHostedZone,
|
|
131
131
|
recordName?: string
|
|
132
132
|
) {
|
|
133
133
|
if (!distribution) throw `Distribution undefined for ${id}`
|
|
134
134
|
if (!hostedZone) throw `HostedZone undefined for ${id}`
|
|
135
135
|
|
|
136
|
-
const aRecord = new
|
|
136
|
+
const aRecord = new ARecord(scope, `${id}`, {
|
|
137
137
|
recordName: recordName,
|
|
138
|
-
target:
|
|
138
|
+
target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),
|
|
139
139
|
zone: hostedZone,
|
|
140
140
|
})
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
createCfnOutput(`${id}-aRecordDomainName`, scope, aRecord.domainName)
|
|
143
143
|
|
|
144
144
|
return aRecord
|
|
145
145
|
}
|
|
@@ -157,8 +157,8 @@ export class Route53Manager {
|
|
|
157
157
|
id: string,
|
|
158
158
|
scope: CommonConstruct,
|
|
159
159
|
recordName: string,
|
|
160
|
-
apiDomain:
|
|
161
|
-
hostedZone:
|
|
160
|
+
apiDomain: DomainName,
|
|
161
|
+
hostedZone: IHostedZone,
|
|
162
162
|
skipStageFromRecord?: boolean
|
|
163
163
|
) {
|
|
164
164
|
let apiRecordName = ''
|
|
@@ -166,13 +166,13 @@ export class Route53Manager {
|
|
|
166
166
|
apiRecordName =
|
|
167
167
|
scope.isProductionStage() || skipStageFromRecord ? `${recordName}` : `${recordName}-${scope.props.stage}`
|
|
168
168
|
|
|
169
|
-
const apiARecord = new
|
|
169
|
+
const apiARecord = new ARecord(scope, `${id}`, {
|
|
170
170
|
recordName: apiRecordName,
|
|
171
|
-
target:
|
|
171
|
+
target: RecordTarget.fromAlias(new ApiGatewayDomain(apiDomain)),
|
|
172
172
|
zone: hostedZone,
|
|
173
173
|
})
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
createCfnOutput(`${id}-a-record-domain-name`, scope, apiARecord.domainName)
|
|
176
176
|
|
|
177
177
|
return apiARecord
|
|
178
178
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as utils from '../../../utils'
|
|
2
|
+
import { Fn } from 'aws-cdk-lib'
|
|
3
|
+
import { Secret, SecretProps } from 'aws-cdk-lib/aws-secretsmanager'
|
|
5
4
|
import { CommonConstruct } from '../../../common'
|
|
5
|
+
import { createCfnOutput, determineCredentials } from '../../../utils'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @classdesc Provides operations on AWS Secrets Manager.
|
|
@@ -12,10 +12,10 @@ import { CommonConstruct } from '../../../common'
|
|
|
12
12
|
* import { CommonConstruct } from '@gradientedge/cdk-utils'
|
|
13
13
|
*
|
|
14
14
|
* class CustomConstruct extends CommonConstruct {
|
|
15
|
-
* constructor(parent:
|
|
15
|
+
* constructor(parent: Construct, id: string, props: common.CommonStackProps) {
|
|
16
16
|
* super(parent, id, props)
|
|
17
17
|
* this.props = props
|
|
18
|
-
* this.
|
|
18
|
+
* this.loadSecret('MySecretName', 'eu-west-1')
|
|
19
19
|
* }
|
|
20
20
|
* }
|
|
21
21
|
* @see [CDK Secrets Manager Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager-readme.html}
|
|
@@ -27,14 +27,14 @@ export class SecretsManager {
|
|
|
27
27
|
* @param scope scope in which this resource is defined
|
|
28
28
|
* @param props the secret properties
|
|
29
29
|
*/
|
|
30
|
-
public createSecret(id: string, scope: CommonConstruct, props:
|
|
31
|
-
const secret = new
|
|
30
|
+
public createSecret(id: string, scope: CommonConstruct, props: SecretProps) {
|
|
31
|
+
const secret = new Secret(scope, `${id}`, {
|
|
32
32
|
...props,
|
|
33
33
|
secretName: `${props.secretName}-${scope.props.stage}`,
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
createCfnOutput(`${id}-secretName`, scope, secret.secretName)
|
|
37
|
+
createCfnOutput(`${id}-secretArn`, scope, secret.secretArn)
|
|
38
38
|
|
|
39
39
|
return secret
|
|
40
40
|
}
|
|
@@ -47,11 +47,7 @@ export class SecretsManager {
|
|
|
47
47
|
* @param exportName
|
|
48
48
|
*/
|
|
49
49
|
public retrieveSecretFromSecretsManager(id: string, scope: CommonConstruct, stackName: string, exportName: string) {
|
|
50
|
-
return
|
|
51
|
-
scope,
|
|
52
|
-
`${id}`,
|
|
53
|
-
cdk.Fn.importValue(`${stackName}-${scope.props.stage}-${exportName}`)
|
|
54
|
-
)
|
|
50
|
+
return Secret.fromSecretNameV2(scope, `${id}`, Fn.importValue(`${stackName}-${scope.props.stage}-${exportName}`))
|
|
55
51
|
}
|
|
56
52
|
|
|
57
53
|
/**
|
|
@@ -62,7 +58,7 @@ export class SecretsManager {
|
|
|
62
58
|
*/
|
|
63
59
|
public async resolveSecretValue(region: string, secretId: string, secretKey: string) {
|
|
64
60
|
const client = new SecretsManagerClient({
|
|
65
|
-
credentials:
|
|
61
|
+
credentials: determineCredentials(),
|
|
66
62
|
region: region,
|
|
67
63
|
})
|
|
68
64
|
const command = new GetSecretValueCommand({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as utils from '../../../utils'
|
|
1
|
+
import { IFunction } from 'aws-cdk-lib/aws-lambda'
|
|
2
|
+
import { Topic } from 'aws-cdk-lib/aws-sns'
|
|
3
|
+
import { EmailSubscription, LambdaSubscription } from 'aws-cdk-lib/aws-sns-subscriptions'
|
|
5
4
|
import { CommonConstruct } from '../../../common'
|
|
5
|
+
import { createCfnOutput } from '../../../utils'
|
|
6
6
|
import { SubscriptionProps } from './types'
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -37,18 +37,18 @@ export class SnsManager {
|
|
|
37
37
|
) {
|
|
38
38
|
if (!props) throw `Subscription props undefined for ${id}`
|
|
39
39
|
|
|
40
|
-
const topic = new
|
|
40
|
+
const topic = new Topic(scope, id, {
|
|
41
41
|
displayName: `${props.topicName}-${scope.props.stage}`,
|
|
42
42
|
fifo: props.fifo,
|
|
43
43
|
topicName: `${props.topicName}-${scope.props.stage}`,
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
if (emails && emails.length > 0) {
|
|
47
|
-
emails.forEach((email: string) => topic.addSubscription(new
|
|
47
|
+
emails.forEach((email: string) => topic.addSubscription(new EmailSubscription(email)))
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
createCfnOutput(`${id}-subscriptionArn`, scope, topic.topicArn)
|
|
51
|
+
createCfnOutput(`${id}-subscriptionName`, scope, topic.topicName)
|
|
52
52
|
|
|
53
53
|
return topic
|
|
54
54
|
}
|
|
@@ -64,20 +64,20 @@ export class SnsManager {
|
|
|
64
64
|
id: string,
|
|
65
65
|
scope: CommonConstruct,
|
|
66
66
|
props: SubscriptionProps,
|
|
67
|
-
lambdaFunction:
|
|
67
|
+
lambdaFunction: IFunction
|
|
68
68
|
) {
|
|
69
69
|
if (!props) throw `Subscription props undefined for ${id}`
|
|
70
70
|
|
|
71
|
-
const topic = new
|
|
71
|
+
const topic = new Topic(scope, id, {
|
|
72
72
|
displayName: `${props.topicName}-${scope.props.stage}`,
|
|
73
73
|
fifo: props.fifo,
|
|
74
74
|
topicName: `${props.topicName}-${scope.props.stage}`,
|
|
75
75
|
})
|
|
76
76
|
|
|
77
|
-
topic.addSubscription(new
|
|
77
|
+
topic.addSubscription(new LambdaSubscription(lambdaFunction))
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
createCfnOutput(`${id}-subscriptionArn`, scope, topic.topicArn)
|
|
80
|
+
createCfnOutput(`${id}-subscriptionName`, scope, topic.topicName)
|
|
81
81
|
|
|
82
82
|
return topic
|
|
83
83
|
}
|