@gradientedge/cdk-utils 8.73.0 → 8.75.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.
@@ -8,7 +8,8 @@ import { Construct } from 'constructs';
8
8
  import { CommonConstruct } from '../../common';
9
9
  import { GraphQlApiLambdaEnvironment, GraphQlApiLambdaProps } from '../../types';
10
10
  /**
11
- * @stability stable
11
+ * @deprecated Use RestApiLambda instead. This will be removed in a future release.
12
+ *
12
13
  * @category cdk-utils.graphql-api-lambda
13
14
  * @subcategory construct
14
15
  * @classdesc Provides a construct to create and deploy a Graphql API as Lambda
@@ -28,7 +28,8 @@ const apig = __importStar(require("aws-cdk-lib/aws-apigateway"));
28
28
  const iam = __importStar(require("aws-cdk-lib/aws-iam"));
29
29
  const common_1 = require("../../common");
30
30
  /**
31
- * @stability stable
31
+ * @deprecated Use RestApiLambda instead. This will be removed in a future release.
32
+ *
32
33
  * @category cdk-utils.graphql-api-lambda
33
34
  * @subcategory construct
34
35
  * @classdesc Provides a construct to create and deploy a Graphql API as Lambda
@@ -8,8 +8,6 @@ import { Construct } from 'constructs';
8
8
  import { CommonConstruct } from '../../common';
9
9
  import { RestApiLambdaEnvironment, RestApiLambdaProps } from '../../types';
10
10
  /**
11
- * @deprecated Use RestApiLambda instead. This will be removed in a future release.
12
- *
13
11
  * @category cdk-utils.rest-api-lambda
14
12
  * @subcategory construct
15
13
  * @classdesc Provides a construct to create and deploy a RestApi as Lambda
@@ -30,7 +28,7 @@ import { RestApiLambdaEnvironment, RestApiLambdaProps } from '../../types';
30
28
  * }
31
29
  * @mixin
32
30
  */
33
- export declare class RestApiLambda extends CommonConstruct {
31
+ export declare abstract class RestApiLambda extends CommonConstruct {
34
32
  props: RestApiLambdaProps;
35
33
  id: string;
36
34
  applicationSecrets: secretsmanager.ISecret[];
@@ -44,7 +42,7 @@ export declare class RestApiLambda extends CommonConstruct {
44
42
  restApiCertificate: acm.ICertificate;
45
43
  restApiDomain: apig.DomainName;
46
44
  restApiBasePathMappings: apig.BasePathMapping[];
47
- constructor(parent: Construct, id: string, props: RestApiLambdaProps);
45
+ protected constructor(parent: Construct, id: string, props: RestApiLambdaProps);
48
46
  /**
49
47
  * @summary Initialise and provision resources
50
48
  * @protected
@@ -96,19 +94,25 @@ export declare class RestApiLambda extends CommonConstruct {
96
94
  * @protected
97
95
  */
98
96
  protected createRestApi(): void;
97
+ protected abstract createRestApiResources(): void;
99
98
  /**
100
- * @summary Method to create custom restApiLambda domain for RestApi API
99
+ * @summary Method to create custom restApiLambda domain for RestApi
101
100
  * @protected
102
101
  */
103
102
  protected createApiDomain(): void;
104
103
  /**
105
- * @summary Method to create base path mappings for RestApi API
104
+ * @summary Method to create base path mappings for RestApi
106
105
  * @protected
107
106
  */
108
107
  protected createApiBasePathMapping(): void;
109
108
  /**
110
- * @summary Method to create route53 records for RestApi API
109
+ * @summary Method to create route53 records for RestApi
111
110
  * @protected
112
111
  */
113
112
  protected createApiRouteAssets(): void;
113
+ /**
114
+ * @summary Method to deploy the changes to the RestApi
115
+ * @protected
116
+ */
117
+ protected createRestApiDeployment(): void;
114
118
  }
@@ -28,8 +28,6 @@ const apig = __importStar(require("aws-cdk-lib/aws-apigateway"));
28
28
  const iam = __importStar(require("aws-cdk-lib/aws-iam"));
29
29
  const common_1 = require("../../common");
30
30
  /**
31
- * @deprecated Use RestApiLambda instead. This will be removed in a future release.
32
- *
33
31
  * @category cdk-utils.rest-api-lambda
34
32
  * @subcategory construct
35
33
  * @classdesc Provides a construct to create and deploy a RestApi as Lambda
@@ -85,9 +83,11 @@ class RestApiLambda extends common_1.CommonConstruct {
85
83
  this.createLambdaLayers();
86
84
  this.createLambdaFunction();
87
85
  this.createRestApi();
86
+ this.createRestApiResources();
88
87
  this.createApiDomain();
89
88
  this.createApiBasePathMapping();
90
89
  this.createApiRouteAssets();
90
+ this.createRestApiDeployment();
91
91
  }
92
92
  /**
93
93
  * @summary Method to resolve secrets from SecretsManager
@@ -171,7 +171,7 @@ class RestApiLambda extends common_1.CommonConstruct {
171
171
  this.restApi = this.apiManager.createLambdaRestApi(`${this.id}-lambda-rest-api`, this, this.props.restApi, this.restApiLambdaFunction);
172
172
  }
173
173
  /**
174
- * @summary Method to create custom restApiLambda domain for RestApi API
174
+ * @summary Method to create custom restApiLambda domain for RestApi
175
175
  * @protected
176
176
  */
177
177
  createApiDomain() {
@@ -180,7 +180,7 @@ class RestApiLambda extends common_1.CommonConstruct {
180
180
  : `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`, this.restApiCertificate);
181
181
  }
182
182
  /**
183
- * @summary Method to create base path mappings for RestApi API
183
+ * @summary Method to create base path mappings for RestApi
184
184
  * @protected
185
185
  */
186
186
  createApiBasePathMapping() {
@@ -204,11 +204,18 @@ class RestApiLambda extends common_1.CommonConstruct {
204
204
  });
205
205
  }
206
206
  /**
207
- * @summary Method to create route53 records for RestApi API
207
+ * @summary Method to create route53 records for RestApi
208
208
  * @protected
209
209
  */
210
210
  createApiRouteAssets() {
211
211
  this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.restApiDomain, this.restApiHostedZone, this.props.skipStageForARecords);
212
212
  }
213
+ /**
214
+ * @summary Method to deploy the changes to the RestApi
215
+ * @protected
216
+ */
217
+ createRestApiDeployment() {
218
+ this.apiManager.createApiDeployment(`${this.id}-deployment`, this, this.restApi);
219
+ }
213
220
  }
214
221
  exports.RestApiLambda = RestApiLambda;
@@ -25,14 +25,14 @@ import { RestApiLambdaWithCacheProps } from '../../types';
25
25
  * }
26
26
  * @mixin
27
27
  */
28
- export declare class RestApiLambdaWithCache extends RestApiLambda {
28
+ export declare abstract class RestApiLambdaWithCache extends RestApiLambda {
29
29
  props: RestApiLambdaWithCacheProps;
30
30
  id: string;
31
31
  restApivpc: ec2.IVpc;
32
32
  restApiCache: elasticache.CfnReplicationGroup;
33
33
  restApiSecurityGroup: ec2.ISecurityGroup;
34
34
  restApiSecurityGroupExportName: string;
35
- constructor(parent: Construct, id: string, props: RestApiLambdaWithCacheProps);
35
+ protected constructor(parent: Construct, id: string, props: RestApiLambdaWithCacheProps);
36
36
  protected initResources(): void;
37
37
  /**
38
38
  * Create VPC
@@ -105,7 +105,17 @@ class RestApiLambdaWithCache extends __1.RestApiLambda {
105
105
  * @protected
106
106
  */
107
107
  createElastiCache() {
108
- this.restApiCache = this.elasticacheManager.createReplicatedElastiCache(`${this.id}-elasticache`, this, this.props.restApiElastiCache, this.restApivpc.privateSubnets.map(subnet => subnet.subnetId), [this.restApiSecurityGroup.securityGroupId]);
108
+ this.restApiCache = this.elasticacheManager.createReplicatedElastiCache(`${this.id}-elasticache`, this, this.props.restApiCache, this.restApivpc.privateSubnets.map(subnet => subnet.subnetId), [this.restApiSecurityGroup.securityGroupId]);
109
+ this.ssmManager.writeStringToParameters(`${this.id}-elasticache-endpoint-address`, this, {
110
+ parameterName: `${this.id}-elasticache-endpoint-address`,
111
+ description: `Elasticache address to use by applications`,
112
+ stringValue: this.restApiCache.attrConfigurationEndPointAddress,
113
+ });
114
+ this.ssmManager.writeStringToParameters(`${this.id}-elasticache-endpoint-port`, this, {
115
+ parameterName: `${this.id}-elasticache-endpoint-port`,
116
+ description: `Elasticache port to use by applications`,
117
+ stringValue: this.restApiCache.attrConfigurationEndPointPort,
118
+ });
109
119
  }
110
120
  /**
111
121
  * Create Lambda Role
@@ -79,6 +79,7 @@ class ApiManager {
79
79
  loggingLevel: props.deployOptions?.loggingLevel,
80
80
  dataTraceEnabled: props.deployOptions?.dataTraceEnabled,
81
81
  cachingEnabled: props.deployOptions?.cachingEnabled,
82
+ metricsEnabled: props.deployOptions?.metricsEnabled,
82
83
  },
83
84
  retainDeployments: props.retainDeployments,
84
85
  parameters: props.parameters,
@@ -58,6 +58,21 @@ export declare class IamManager {
58
58
  * @param {string[]} resourceArns list of ARNs to allow access to
59
59
  */
60
60
  statementForReadAnyAppConfig(resourceArns?: string[]): cdk.aws_iam.PolicyStatement;
61
+ /**
62
+ * @summary Method to create iam statement to access app config
63
+ * @param {string[]} resourceArns list of ARNs to allow access to
64
+ */
65
+ statementForAppConfigExecution(resourceArns?: string[]): cdk.aws_iam.PolicyStatement;
66
+ /**
67
+ * @summary Method to create iam statement to put xray telemetry
68
+ * @param {string[]} resourceArns list of ARNs to allow access to
69
+ */
70
+ statementForPutXrayTelemetry(resourceArns?: string[]): cdk.aws_iam.PolicyStatement;
71
+ /**
72
+ * @summary Method to create iam statement to decrypt kms
73
+ * @param {string[]} resourceArns list of ARNs to allow access to
74
+ */
75
+ statementForDecryptKms(resourceArns?: string[]): cdk.aws_iam.PolicyStatement;
61
76
  /**
62
77
  * @summary Method to create iam statement to list s3 buckets
63
78
  * @param {common.CommonConstruct} scope scope in which this resource is defined
@@ -130,6 +130,39 @@ class IamManager {
130
130
  resources: resourceArns ?? ['*'],
131
131
  });
132
132
  }
133
+ /**
134
+ * @summary Method to create iam statement to access app config
135
+ * @param {string[]} resourceArns list of ARNs to allow access to
136
+ */
137
+ statementForAppConfigExecution(resourceArns) {
138
+ return new iam.PolicyStatement({
139
+ effect: iam.Effect.ALLOW,
140
+ actions: ['appconfig:GetLatestConfiguration', 'appconfig:StartConfigurationSession'],
141
+ resources: resourceArns ?? ['*'],
142
+ });
143
+ }
144
+ /**
145
+ * @summary Method to create iam statement to put xray telemetry
146
+ * @param {string[]} resourceArns list of ARNs to allow access to
147
+ */
148
+ statementForPutXrayTelemetry(resourceArns) {
149
+ return new iam.PolicyStatement({
150
+ effect: iam.Effect.ALLOW,
151
+ actions: ['xray:PutTraceSegments', 'xray:PutTelemetryRecords'],
152
+ resources: resourceArns ?? ['*'],
153
+ });
154
+ }
155
+ /**
156
+ * @summary Method to create iam statement to decrypt kms
157
+ * @param {string[]} resourceArns list of ARNs to allow access to
158
+ */
159
+ statementForDecryptKms(resourceArns) {
160
+ return new iam.PolicyStatement({
161
+ effect: iam.Effect.ALLOW,
162
+ actions: ['kms:Decrypt'],
163
+ resources: resourceArns ?? ['*'],
164
+ });
165
+ }
133
166
  /**
134
167
  * @summary Method to create iam statement to list s3 buckets
135
168
  * @param {common.CommonConstruct} scope scope in which this resource is defined
@@ -215,6 +215,7 @@ class LambdaManager {
215
215
  filesystem: accessPoint
216
216
  ? lambda.FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg')
217
217
  : undefined,
218
+ logRetention: scope.props.logRetention ?? props.logRetention,
218
219
  reservedConcurrentExecutions: props.reservedConcurrentExecutions,
219
220
  role: role instanceof iam.Role ? role : undefined,
220
221
  securityGroups: securityGroups,
@@ -316,7 +316,7 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
316
316
  */
317
317
  export interface RestApiLambdaWithCacheProps extends RestApiLambdaProps {
318
318
  restApiVpc: ec2.VpcProps;
319
- restApiElastiCache: ReplicatedElastiCacheProps;
319
+ restApiCache: ReplicatedElastiCacheProps;
320
320
  securityGroupExportName: string;
321
321
  useExistingVpc: boolean;
322
322
  vpcName?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.73.0",
3
+ "version": "8.75.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -9,7 +9,8 @@ import { CommonConstruct } from '../../common'
9
9
  import { GraphQlApiLambdaEnvironment, GraphQlApiLambdaProps } from '../../types'
10
10
 
11
11
  /**
12
- * @stability stable
12
+ * @deprecated Use RestApiLambda instead. This will be removed in a future release.
13
+ *
13
14
  * @category cdk-utils.graphql-api-lambda
14
15
  * @subcategory construct
15
16
  * @classdesc Provides a construct to create and deploy a Graphql API as Lambda
@@ -9,8 +9,6 @@ import { CommonConstruct } from '../../common'
9
9
  import { RestApiLambdaEnvironment, RestApiLambdaProps } from '../../types'
10
10
 
11
11
  /**
12
- * @deprecated Use RestApiLambda instead. This will be removed in a future release.
13
- *
14
12
  * @category cdk-utils.rest-api-lambda
15
13
  * @subcategory construct
16
14
  * @classdesc Provides a construct to create and deploy a RestApi as Lambda
@@ -31,7 +29,7 @@ import { RestApiLambdaEnvironment, RestApiLambdaProps } from '../../types'
31
29
  * }
32
30
  * @mixin
33
31
  */
34
- export class RestApiLambda extends CommonConstruct {
32
+ export abstract class RestApiLambda extends CommonConstruct {
35
33
  /* restApiLambda props */
36
34
  props: RestApiLambdaProps
37
35
  id: string
@@ -49,7 +47,7 @@ export class RestApiLambda extends CommonConstruct {
49
47
  restApiDomain: apig.DomainName
50
48
  restApiBasePathMappings: apig.BasePathMapping[] = []
51
49
 
52
- constructor(parent: Construct, id: string, props: RestApiLambdaProps) {
50
+ protected constructor(parent: Construct, id: string, props: RestApiLambdaProps) {
53
51
  super(parent, id, props)
54
52
 
55
53
  this.props = props
@@ -70,9 +68,11 @@ export class RestApiLambda extends CommonConstruct {
70
68
  this.createLambdaLayers()
71
69
  this.createLambdaFunction()
72
70
  this.createRestApi()
71
+ this.createRestApiResources()
73
72
  this.createApiDomain()
74
73
  this.createApiBasePathMapping()
75
74
  this.createApiRouteAssets()
75
+ this.createRestApiDeployment()
76
76
  }
77
77
 
78
78
  /**
@@ -201,8 +201,10 @@ export class RestApiLambda extends CommonConstruct {
201
201
  )
202
202
  }
203
203
 
204
+ protected abstract createRestApiResources(): void
205
+
204
206
  /**
205
- * @summary Method to create custom restApiLambda domain for RestApi API
207
+ * @summary Method to create custom restApiLambda domain for RestApi
206
208
  * @protected
207
209
  */
208
210
  protected createApiDomain() {
@@ -217,7 +219,7 @@ export class RestApiLambda extends CommonConstruct {
217
219
  }
218
220
 
219
221
  /**
220
- * @summary Method to create base path mappings for RestApi API
222
+ * @summary Method to create base path mappings for RestApi
221
223
  * @protected
222
224
  */
223
225
  protected createApiBasePathMapping() {
@@ -245,7 +247,7 @@ export class RestApiLambda extends CommonConstruct {
245
247
  }
246
248
 
247
249
  /**
248
- * @summary Method to create route53 records for RestApi API
250
+ * @summary Method to create route53 records for RestApi
249
251
  * @protected
250
252
  */
251
253
  protected createApiRouteAssets() {
@@ -258,4 +260,12 @@ export class RestApiLambda extends CommonConstruct {
258
260
  this.props.skipStageForARecords
259
261
  )
260
262
  }
263
+
264
+ /**
265
+ * @summary Method to deploy the changes to the RestApi
266
+ * @protected
267
+ */
268
+ protected createRestApiDeployment() {
269
+ this.apiManager.createApiDeployment(`${this.id}-deployment`, this, this.restApi)
270
+ }
261
271
  }
@@ -29,7 +29,7 @@ import * as utils from '../../utils'
29
29
  * }
30
30
  * @mixin
31
31
  */
32
- export class RestApiLambdaWithCache extends RestApiLambda {
32
+ export abstract class RestApiLambdaWithCache extends RestApiLambda {
33
33
  /* restApiLambdaWithCache props */
34
34
  props: RestApiLambdaWithCacheProps
35
35
  id: string
@@ -40,7 +40,7 @@ export class RestApiLambdaWithCache extends RestApiLambda {
40
40
  restApiSecurityGroup: ec2.ISecurityGroup
41
41
  restApiSecurityGroupExportName: string
42
42
 
43
- constructor(parent: Construct, id: string, props: RestApiLambdaWithCacheProps) {
43
+ protected constructor(parent: Construct, id: string, props: RestApiLambdaWithCacheProps) {
44
44
  super(parent, id, props)
45
45
 
46
46
  this.props = props
@@ -97,10 +97,22 @@ export class RestApiLambdaWithCache extends RestApiLambda {
97
97
  this.restApiCache = this.elasticacheManager.createReplicatedElastiCache(
98
98
  `${this.id}-elasticache`,
99
99
  this,
100
- this.props.restApiElastiCache,
100
+ this.props.restApiCache,
101
101
  this.restApivpc.privateSubnets.map(subnet => subnet.subnetId),
102
102
  [this.restApiSecurityGroup.securityGroupId]
103
103
  )
104
+
105
+ this.ssmManager.writeStringToParameters(`${this.id}-elasticache-endpoint-address`, this, {
106
+ parameterName: `${this.id}-elasticache-endpoint-address`,
107
+ description: `Elasticache address to use by applications`,
108
+ stringValue: this.restApiCache.attrConfigurationEndPointAddress,
109
+ })
110
+
111
+ this.ssmManager.writeStringToParameters(`${this.id}-elasticache-endpoint-port`, this, {
112
+ parameterName: `${this.id}-elasticache-endpoint-port`,
113
+ description: `Elasticache port to use by applications`,
114
+ stringValue: this.restApiCache.attrConfigurationEndPointPort,
115
+ })
104
116
  }
105
117
 
106
118
  /**
@@ -62,6 +62,7 @@ export class ApiManager {
62
62
  loggingLevel: props.deployOptions?.loggingLevel,
63
63
  dataTraceEnabled: props.deployOptions?.dataTraceEnabled,
64
64
  cachingEnabled: props.deployOptions?.cachingEnabled,
65
+ metricsEnabled: props.deployOptions?.metricsEnabled,
65
66
  },
66
67
  retainDeployments: props.retainDeployments,
67
68
  parameters: props.parameters,
@@ -117,6 +117,42 @@ export class IamManager {
117
117
  })
118
118
  }
119
119
 
120
+ /**
121
+ * @summary Method to create iam statement to access app config
122
+ * @param {string[]} resourceArns list of ARNs to allow access to
123
+ */
124
+ public statementForAppConfigExecution(resourceArns?: string[]) {
125
+ return new iam.PolicyStatement({
126
+ effect: iam.Effect.ALLOW,
127
+ actions: ['appconfig:GetLatestConfiguration', 'appconfig:StartConfigurationSession'],
128
+ resources: resourceArns ?? ['*'],
129
+ })
130
+ }
131
+
132
+ /**
133
+ * @summary Method to create iam statement to put xray telemetry
134
+ * @param {string[]} resourceArns list of ARNs to allow access to
135
+ */
136
+ public statementForPutXrayTelemetry(resourceArns?: string[]) {
137
+ return new iam.PolicyStatement({
138
+ effect: iam.Effect.ALLOW,
139
+ actions: ['xray:PutTraceSegments', 'xray:PutTelemetryRecords'],
140
+ resources: resourceArns ?? ['*'],
141
+ })
142
+ }
143
+
144
+ /**
145
+ * @summary Method to create iam statement to decrypt kms
146
+ * @param {string[]} resourceArns list of ARNs to allow access to
147
+ */
148
+ public statementForDecryptKms(resourceArns?: string[]) {
149
+ return new iam.PolicyStatement({
150
+ effect: iam.Effect.ALLOW,
151
+ actions: ['kms:Decrypt'],
152
+ resources: resourceArns ?? ['*'],
153
+ })
154
+ }
155
+
120
156
  /**
121
157
  * @summary Method to create iam statement to list s3 buckets
122
158
  * @param {common.CommonConstruct} scope scope in which this resource is defined
@@ -270,6 +270,7 @@ export class LambdaManager {
270
270
  filesystem: accessPoint
271
271
  ? lambda.FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg')
272
272
  : undefined,
273
+ logRetention: scope.props.logRetention ?? props.logRetention,
273
274
  reservedConcurrentExecutions: props.reservedConcurrentExecutions,
274
275
  role: role instanceof iam.Role ? role : undefined,
275
276
  securityGroups: securityGroups,
@@ -340,7 +340,7 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
340
340
  */
341
341
  export interface RestApiLambdaWithCacheProps extends RestApiLambdaProps {
342
342
  restApiVpc: ec2.VpcProps
343
- restApiElastiCache: ReplicatedElastiCacheProps
343
+ restApiCache: ReplicatedElastiCacheProps
344
344
  securityGroupExportName: string
345
345
  useExistingVpc: boolean
346
346
  vpcName?: string