@gradientedge/cdk-utils 9.20.0 → 9.21.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.
@@ -39,7 +39,6 @@ export declare class ApiToAnyTarget extends CommonConstruct {
39
39
  * @summary Method to resolve a certificate based on attributes
40
40
  */
41
41
  protected resolveCertificate(): void;
42
- protected createApiToAnyTargetRestApiLogGroup(): void;
43
42
  protected createApiToAnyTargetRestApi(): void;
44
43
  protected createApiToAnyTargetResource(apiResourceProps: ApiToAnyTargetRestApiResource): Resource | undefined;
45
44
  protected createApiDomain(): void;
@@ -41,7 +41,6 @@ class ApiToAnyTarget extends common_1.CommonConstruct {
41
41
  this.resolveHostedZone();
42
42
  this.resolveCertificate();
43
43
  /* restApi related resources */
44
- this.createApiToAnyTargetRestApiLogGroup();
45
44
  this.createApiToAnyTargetRestApi();
46
45
  this.createApiDomain();
47
46
  this.createApiBasePathMapping();
@@ -73,12 +72,6 @@ class ApiToAnyTarget extends common_1.CommonConstruct {
73
72
  }
74
73
  this.apiToAnyTargetRestApi.certificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.api.certificate);
75
74
  }
76
- createApiToAnyTargetRestApiLogGroup() {
77
- this.apiToAnyTargetRestApi.accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
78
- logGroupName: `${this.id}-access`,
79
- removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
80
- });
81
- }
82
75
  createApiToAnyTargetRestApi() {
83
76
  if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
84
77
  this.apiToAnyTargetRestApi.api = aws_apigateway_1.RestApi.fromRestApiId(this, `${this.id}-rest-api`, aws_cdk_lib_1.Fn.importValue(this.props.api.importedRestApiRef));
@@ -86,6 +79,12 @@ class ApiToAnyTarget extends common_1.CommonConstruct {
86
79
  }
87
80
  if (!this.props.api.restApi?.restApiName)
88
81
  throw `RestApi name undefined for ${this.id}`;
82
+ const restApiName = this.resourceNameFormatter.format(this.props.api.restApi?.restApiName, this.props.resourceNameOptions?.apigateway);
83
+ const restApiAccessLogName = this.resourceNameFormatter.format(`${this.props.api.restApi?.restApiName}-access`, this.props.resourceNameOptions?.apigateway);
84
+ this.apiToAnyTargetRestApi.accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
85
+ logGroupName: restApiAccessLogName,
86
+ removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
87
+ });
89
88
  this.apiToAnyTargetRestApi.api = new aws_apigateway_1.RestApi(this, `${this.id}-rest-api`, {
90
89
  cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
91
90
  defaultCorsPreflightOptions: {
@@ -112,7 +111,7 @@ class ApiToAnyTarget extends common_1.CommonConstruct {
112
111
  types: [this.isProductionStage() ? aws_apigateway_1.EndpointType.EDGE : aws_apigateway_1.EndpointType.REGIONAL],
113
112
  },
114
113
  ...this.props.api.restApi,
115
- restApiName: this.resourceNameFormatter.format(this.props.api.restApi?.restApiName, this.props.resourceNameOptions?.apigateway),
114
+ restApiName,
116
115
  });
117
116
  this.addCfnOutput(`${this.id}-restApiId`, this.apiToAnyTargetRestApi.api.restApiId);
118
117
  this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiToAnyTargetRestApi.api.root.resourceId);
@@ -86,7 +86,6 @@ export declare class ApiToEventBridgeTarget extends CommonConstruct {
86
86
  * @summary Method to create api integration method error response
87
87
  */
88
88
  protected createApiToEventBridgeTargetMethodErrorResponse(): void;
89
- protected createApiToEventBridgeTargetRestApiLogGroup(): void;
90
89
  /**
91
90
  * @summary Method to create rest restApi for Api
92
91
  */
@@ -63,7 +63,6 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
63
63
  this.createApiToEventBridgeTargetIntegrationResponse();
64
64
  this.createApiToEventBridgeTargetIntegrationErrorResponse();
65
65
  this.createApiToEventBridgeTargetIntegration();
66
- this.createApiToEventBridgeTargetRestApiLogGroup();
67
66
  this.createApiToEventBridgeTargetRestApi();
68
67
  this.createApiToEventBridgeTargetResource();
69
68
  this.createApiToEventBridgeTargetResponseModel();
@@ -121,7 +120,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
121
120
  return;
122
121
  this.apiEvent.logGroup = this.logManager.createLogGroup(`${this.id}-log`, this, {
123
122
  ...{
124
- logGroupName: `${this.id}-api-to-event-bridge-target`,
123
+ logGroupName: `${this.id}-api-to-event-bridge-target-${this.props.stage}`,
125
124
  },
126
125
  ...this.props.event.logGroup,
127
126
  });
@@ -288,12 +287,6 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
288
287
  ...this.props.api.methodErrorResponse,
289
288
  };
290
289
  }
291
- createApiToEventBridgeTargetRestApiLogGroup() {
292
- this.apiToEventBridgeTargetRestApi.accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
293
- logGroupName: `${this.id}-access`,
294
- removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
295
- });
296
- }
297
290
  /**
298
291
  * @summary Method to create rest restApi for Api
299
292
  */
@@ -304,6 +297,12 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
304
297
  }
305
298
  if (!this.props.api.restApi?.restApiName)
306
299
  throw `RestApi name undefined for ${this.id}`;
300
+ const restApiName = this.resourceNameFormatter.format(this.props.api.restApi?.restApiName, this.props.resourceNameOptions?.apigateway);
301
+ const restApiAccessLogName = this.resourceNameFormatter.format(`${this.props.api.restApi?.restApiName}-access`, this.props.resourceNameOptions?.apigateway);
302
+ this.apiToEventBridgeTargetRestApi.accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
303
+ logGroupName: restApiAccessLogName,
304
+ removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
305
+ });
307
306
  this.apiToEventBridgeTargetRestApi.api = new aws_apigateway_1.RestApi(this, `${this.id}-rest-api`, {
308
307
  cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
309
308
  defaultCorsPreflightOptions: {
@@ -333,7 +332,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
333
332
  types: [aws_apigateway_1.EndpointType.REGIONAL],
334
333
  },
335
334
  ...this.props.api.restApi,
336
- restApiName: this.resourceNameFormatter.format(this.props.api.restApi?.restApiName, this.props.resourceNameOptions?.apigateway),
335
+ restApiName,
337
336
  });
338
337
  this.addCfnOutput(`${this.id}-restApiId`, this.apiToEventBridgeTargetRestApi.api.restApiId);
339
338
  this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiToEventBridgeTargetRestApi.api.root.resourceId);
@@ -199,7 +199,7 @@ class ApiToEventBridgeTargetWithSns extends common_1.CommonConstruct {
199
199
  if (this.props.api.useExisting)
200
200
  return;
201
201
  this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
202
- logGroupName: `${this.id}-destination`,
202
+ logGroupName: `${this.id}-destination-${this.props.stage}`,
203
203
  ...this.props.event.logGroupSuccess,
204
204
  });
205
205
  }
@@ -233,7 +233,7 @@ class ApiToEventBridgeTargetWithSns extends common_1.CommonConstruct {
233
233
  if (this.props.api.useExisting)
234
234
  return;
235
235
  this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
236
- logGroupName: `${this.id}-destination-failure`,
236
+ logGroupName: `${this.id}-destination-failure-${this.props.stage}`,
237
237
  ...this.props.event.logGroupFailure,
238
238
  });
239
239
  }
@@ -409,12 +409,14 @@ class ApiToEventBridgeTargetWithSns extends common_1.CommonConstruct {
409
409
  this.apiDestinedRestApi.api = aws_apigateway_1.RestApi.fromRestApiId(this, `${this.id}-sns-rest-api`, aws_cdk_lib_1.Fn.importValue(this.props.api.importedRestApiRef));
410
410
  return;
411
411
  }
412
- const accessLogGroup = this.logManager.createLogGroup(`${this.id}-sns-rest-api-access-log`, this, {
413
- logGroupName: `${this.id}-access`,
414
- removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
415
- });
416
412
  if (!this.props.api.restApi?.restApiName)
417
413
  throw `RestApi name undefined for ${this.id}`;
414
+ const restApiName = this.resourceNameFormatter.format(this.props.api.restApi?.restApiName, this.props.resourceNameOptions?.apigateway);
415
+ const restApiAccessLogName = this.resourceNameFormatter.format(`${this.props.api.restApi?.restApiName}-access`, this.props.resourceNameOptions?.apigateway);
416
+ const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
417
+ logGroupName: restApiAccessLogName,
418
+ removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
419
+ });
418
420
  this.apiDestinedRestApi.api = new aws_apigateway_1.RestApi(this, `${this.id}-sns-rest-api`, {
419
421
  defaultCorsPreflightOptions: {
420
422
  allowHeaders: aws_apigateway_1.Cors.DEFAULT_HEADERS,
@@ -438,7 +440,7 @@ class ApiToEventBridgeTargetWithSns extends common_1.CommonConstruct {
438
440
  types: [aws_apigateway_1.EndpointType.REGIONAL],
439
441
  },
440
442
  ...this.props.api,
441
- restApiName: this.resourceNameFormatter.format(this.props.api.restApi?.restApiName, this.props.resourceNameOptions?.apigateway),
443
+ restApiName,
442
444
  });
443
445
  this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId);
444
446
  this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId);
@@ -113,10 +113,6 @@ class ApiToLambdaTarget extends common_1.CommonConstruct {
113
113
  this.apiToLambdaTargetRestApi.api = aws_apigateway_1.RestApi.fromRestApiId(this, `${this.id}-rest-api`, aws_cdk_lib_1.Fn.importValue(this.props.api.importedRestApiRef));
114
114
  return;
115
115
  }
116
- const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
117
- logGroupName: `${this.id}-access`,
118
- removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
119
- });
120
116
  this.props.api.restApi = {
121
117
  ...this.props.api.restApi,
122
118
  defaultMethodOptions: {
@@ -125,9 +121,6 @@ class ApiToLambdaTarget extends common_1.CommonConstruct {
125
121
  this.apiToLambdaTargetRestApi.methodErrorResponse,
126
122
  ],
127
123
  },
128
- deployOptions: {
129
- accessLogDestination: new aws_apigateway_1.LogGroupLogDestination(accessLogGroup),
130
- },
131
124
  };
132
125
  this.apiToLambdaTargetRestApi.api = this.apiManager.createLambdaRestApi(`${this.id}-lambda-rest-api`, this, this.props.api.restApi, this.apiToLambdaTargetRestApi.lambda);
133
126
  this.addCfnOutput(`${this.id}-restApiId`, this.apiToLambdaTargetRestApi.api.restApiId);
@@ -38,12 +38,19 @@ class ApiManager {
38
38
  throw `Api props undefined for ${id}`;
39
39
  if (!props.restApiName)
40
40
  throw `Api restApiName undefined for ${id}`;
41
+ const restApiName = scope.resourceNameFormatter.format(props.restApiName, scope.props.resourceNameOptions?.apigateway);
42
+ const restApiAccessLogName = scope.resourceNameFormatter.format(`${props.restApiName}-access`, scope.props.resourceNameOptions?.apigateway);
43
+ const accessLogGroup = scope.logManager.createLogGroup(`${id}-rest-api-access-log`, scope, {
44
+ logGroupName: restApiAccessLogName,
45
+ removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
46
+ });
41
47
  const api = new aws_apigateway_1.LambdaRestApi(scope, `${id}`, {
42
48
  ...props,
43
49
  cloudWatchRole: props.cloudWatchRole || false,
44
50
  deploy: props.deploy || true,
45
51
  deployOptions: {
46
52
  ...props.deployOptions,
53
+ accessLogDestination: new aws_apigateway_1.LogGroupLogDestination(accessLogGroup),
47
54
  description: `${id} - ${scope.props.stage} stage`,
48
55
  stageName: scope.props.stage,
49
56
  },
@@ -55,7 +62,7 @@ class ApiManager {
55
62
  handler: lambdaFunction,
56
63
  minCompressionSize: props.minCompressionSizeInBytes ? aws_cdk_lib_1.Size.bytes(props.minCompressionSizeInBytes) : undefined,
57
64
  proxy: props.proxy ?? true,
58
- restApiName: scope.resourceNameFormatter.format(props.restApiName, scope.props.resourceNameOptions?.apigateway),
65
+ restApiName,
59
66
  });
60
67
  if (props.tags && !lodash_1.default.isEmpty(props.tags)) {
61
68
  lodash_1.default.forEach(props.tags, tag => {
@@ -88,7 +88,7 @@ class LogManager {
88
88
  throw `Logs logGroupName undefined for ${id}`;
89
89
  const logGroup = new logs.CfnLogGroup(scope, `${id}`, {
90
90
  ...props,
91
- logGroupName: `${scope.resourceNameFormatter.format(props.logGroupName, scope.props.resourceNameOptions?.logs)}`,
91
+ logGroupName: props.logGroupName,
92
92
  retentionInDays: props.retention,
93
93
  });
94
94
  if (props.tags && !lodash_1.default.isEmpty(props.tags)) {
@@ -112,7 +112,7 @@ class LogManager {
112
112
  throw `Logs logGroupName undefined for ${id}`;
113
113
  const logGroup = new logs.LogGroup(scope, `${id}`, {
114
114
  ...props,
115
- logGroupName: `${scope.resourceNameFormatter.format(props.logGroupName, scope.props.resourceNameOptions?.logs)}`,
115
+ logGroupName: props.logGroupName,
116
116
  removalPolicy: props.removalPolicy ?? cdk.RemovalPolicy.DESTROY,
117
117
  retention: props.retention,
118
118
  });
@@ -102,7 +102,7 @@ class LambdaManager {
102
102
  handler: handler || 'index.lambda_handler',
103
103
  layers,
104
104
  logGroup: scope.logManager.createLogGroup(`${id}-log-group`, scope, {
105
- logGroupName: props.functionName,
105
+ logGroupName: functionName,
106
106
  removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
107
107
  retention: scope.props.logRetention ?? logRetention,
108
108
  }),
@@ -205,7 +205,7 @@ class LambdaManager {
205
205
  filesystem: accessPoint ? aws_lambda_1.FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg') : undefined,
206
206
  functionName,
207
207
  logGroup: scope.logManager.createLogGroup(`${id}-log-group`, scope, {
208
- logGroupName: props.functionName,
208
+ logGroupName: functionName,
209
209
  removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY,
210
210
  retention: scope.props.logRetention ?? logRetention,
211
211
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "9.20.0",
3
+ "version": "9.21.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -58,7 +58,6 @@ export class ApiToAnyTarget extends CommonConstruct {
58
58
  this.resolveCertificate()
59
59
 
60
60
  /* restApi related resources */
61
- this.createApiToAnyTargetRestApiLogGroup()
62
61
  this.createApiToAnyTargetRestApi()
63
62
  this.createApiDomain()
64
63
  this.createApiBasePathMapping()
@@ -109,13 +108,6 @@ export class ApiToAnyTarget extends CommonConstruct {
109
108
  )
110
109
  }
111
110
 
112
- protected createApiToAnyTargetRestApiLogGroup() {
113
- this.apiToAnyTargetRestApi.accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
114
- logGroupName: `${this.id}-access`,
115
- removalPolicy: RemovalPolicy.DESTROY,
116
- })
117
- }
118
-
119
111
  protected createApiToAnyTargetRestApi() {
120
112
  if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
121
113
  this.apiToAnyTargetRestApi.api = RestApi.fromRestApiId(
@@ -128,6 +120,21 @@ export class ApiToAnyTarget extends CommonConstruct {
128
120
 
129
121
  if (!this.props.api.restApi?.restApiName) throw `RestApi name undefined for ${this.id}`
130
122
 
123
+ const restApiName = this.resourceNameFormatter.format(
124
+ this.props.api.restApi?.restApiName,
125
+ this.props.resourceNameOptions?.apigateway
126
+ )
127
+
128
+ const restApiAccessLogName = this.resourceNameFormatter.format(
129
+ `${this.props.api.restApi?.restApiName}-access`,
130
+ this.props.resourceNameOptions?.apigateway
131
+ )
132
+
133
+ this.apiToAnyTargetRestApi.accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
134
+ logGroupName: restApiAccessLogName,
135
+ removalPolicy: RemovalPolicy.DESTROY,
136
+ })
137
+
131
138
  this.apiToAnyTargetRestApi.api = new RestApi(this, `${this.id}-rest-api`, {
132
139
  cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
133
140
  defaultCorsPreflightOptions: {
@@ -154,10 +161,7 @@ export class ApiToAnyTarget extends CommonConstruct {
154
161
  types: [this.isProductionStage() ? EndpointType.EDGE : EndpointType.REGIONAL],
155
162
  },
156
163
  ...this.props.api.restApi,
157
- restApiName: this.resourceNameFormatter.format(
158
- this.props.api.restApi?.restApiName,
159
- this.props.resourceNameOptions?.apigateway
160
- ),
164
+ restApiName,
161
165
  })
162
166
  this.addCfnOutput(`${this.id}-restApiId`, this.apiToAnyTargetRestApi.api.restApiId)
163
167
  this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiToAnyTargetRestApi.api.root.resourceId)
@@ -94,7 +94,6 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
94
94
  this.createApiToEventBridgeTargetIntegrationResponse()
95
95
  this.createApiToEventBridgeTargetIntegrationErrorResponse()
96
96
  this.createApiToEventBridgeTargetIntegration()
97
- this.createApiToEventBridgeTargetRestApiLogGroup()
98
97
  this.createApiToEventBridgeTargetRestApi()
99
98
  this.createApiToEventBridgeTargetResource()
100
99
  this.createApiToEventBridgeTargetResponseModel()
@@ -178,7 +177,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
178
177
  if (this.props.api.useExisting) return
179
178
  this.apiEvent.logGroup = this.logManager.createLogGroup(`${this.id}-log`, this, {
180
179
  ...{
181
- logGroupName: `${this.id}-api-to-event-bridge-target`,
180
+ logGroupName: `${this.id}-api-to-event-bridge-target-${this.props.stage}`,
182
181
  },
183
182
  ...this.props.event.logGroup,
184
183
  })
@@ -354,17 +353,6 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
354
353
  }
355
354
  }
356
355
 
357
- protected createApiToEventBridgeTargetRestApiLogGroup() {
358
- this.apiToEventBridgeTargetRestApi.accessLogGroup = this.logManager.createLogGroup(
359
- `${this.id}-rest-api-access-log`,
360
- this,
361
- {
362
- logGroupName: `${this.id}-access`,
363
- removalPolicy: RemovalPolicy.DESTROY,
364
- }
365
- )
366
- }
367
-
368
356
  /**
369
357
  * @summary Method to create rest restApi for Api
370
358
  */
@@ -380,6 +368,25 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
380
368
 
381
369
  if (!this.props.api.restApi?.restApiName) throw `RestApi name undefined for ${this.id}`
382
370
 
371
+ const restApiName = this.resourceNameFormatter.format(
372
+ this.props.api.restApi?.restApiName,
373
+ this.props.resourceNameOptions?.apigateway
374
+ )
375
+
376
+ const restApiAccessLogName = this.resourceNameFormatter.format(
377
+ `${this.props.api.restApi?.restApiName}-access`,
378
+ this.props.resourceNameOptions?.apigateway
379
+ )
380
+
381
+ this.apiToEventBridgeTargetRestApi.accessLogGroup = this.logManager.createLogGroup(
382
+ `${this.id}-rest-api-access-log`,
383
+ this,
384
+ {
385
+ logGroupName: restApiAccessLogName,
386
+ removalPolicy: RemovalPolicy.DESTROY,
387
+ }
388
+ )
389
+
383
390
  this.apiToEventBridgeTargetRestApi.api = new RestApi(this, `${this.id}-rest-api`, {
384
391
  cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
385
392
  defaultCorsPreflightOptions: {
@@ -409,10 +416,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
409
416
  types: [EndpointType.REGIONAL],
410
417
  },
411
418
  ...this.props.api.restApi,
412
- restApiName: this.resourceNameFormatter.format(
413
- this.props.api.restApi?.restApiName,
414
- this.props.resourceNameOptions?.apigateway
415
- ),
419
+ restApiName,
416
420
  })
417
421
 
418
422
  this.addCfnOutput(`${this.id}-restApiId`, this.apiToEventBridgeTargetRestApi.api.restApiId)
@@ -274,7 +274,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
274
274
  protected createApiDestinationLogGroupSuccess() {
275
275
  if (this.props.api.useExisting) return
276
276
  this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
277
- logGroupName: `${this.id}-destination`,
277
+ logGroupName: `${this.id}-destination-${this.props.stage}`,
278
278
  ...this.props.event.logGroupSuccess,
279
279
  })
280
280
  }
@@ -314,7 +314,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
314
314
  protected createApiDestinationLogGroupFailure() {
315
315
  if (this.props.api.useExisting) return
316
316
  this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
317
- logGroupName: `${this.id}-destination-failure`,
317
+ logGroupName: `${this.id}-destination-failure-${this.props.stage}`,
318
318
  ...this.props.event.logGroupFailure,
319
319
  })
320
320
  }
@@ -508,13 +508,23 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
508
508
  return
509
509
  }
510
510
 
511
- const accessLogGroup = this.logManager.createLogGroup(`${this.id}-sns-rest-api-access-log`, this, {
512
- logGroupName: `${this.id}-access`,
511
+ if (!this.props.api.restApi?.restApiName) throw `RestApi name undefined for ${this.id}`
512
+
513
+ const restApiName = this.resourceNameFormatter.format(
514
+ this.props.api.restApi?.restApiName,
515
+ this.props.resourceNameOptions?.apigateway
516
+ )
517
+
518
+ const restApiAccessLogName = this.resourceNameFormatter.format(
519
+ `${this.props.api.restApi?.restApiName}-access`,
520
+ this.props.resourceNameOptions?.apigateway
521
+ )
522
+
523
+ const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
524
+ logGroupName: restApiAccessLogName,
513
525
  removalPolicy: RemovalPolicy.DESTROY,
514
526
  })
515
527
 
516
- if (!this.props.api.restApi?.restApiName) throw `RestApi name undefined for ${this.id}`
517
-
518
528
  this.apiDestinedRestApi.api = new RestApi(this, `${this.id}-sns-rest-api`, {
519
529
  defaultCorsPreflightOptions: {
520
530
  allowHeaders: Cors.DEFAULT_HEADERS,
@@ -538,10 +548,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
538
548
  types: [EndpointType.REGIONAL],
539
549
  },
540
550
  ...this.props.api,
541
- restApiName: this.resourceNameFormatter.format(
542
- this.props.api.restApi?.restApiName,
543
- this.props.resourceNameOptions?.apigateway
544
- ),
551
+ restApiName,
545
552
  })
546
553
  this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId)
547
554
  this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId)
@@ -1,11 +1,5 @@
1
- import { Fn, RemovalPolicy } from 'aws-cdk-lib'
2
- import {
3
- BasePathMapping,
4
- LambdaIntegration,
5
- LogGroupLogDestination,
6
- Resource,
7
- RestApi,
8
- } from 'aws-cdk-lib/aws-apigateway'
1
+ import { Fn } from 'aws-cdk-lib'
2
+ import { BasePathMapping, LambdaIntegration, Resource, RestApi } from 'aws-cdk-lib/aws-apigateway'
9
3
  import { PolicyDocument, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'
10
4
  import { Function } from 'aws-cdk-lib/aws-lambda'
11
5
  import { ISecret } from 'aws-cdk-lib/aws-secretsmanager'
@@ -155,11 +149,6 @@ export class ApiToLambdaTarget extends CommonConstruct {
155
149
  return
156
150
  }
157
151
 
158
- const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
159
- logGroupName: `${this.id}-access`,
160
- removalPolicy: RemovalPolicy.DESTROY,
161
- })
162
-
163
152
  this.props.api.restApi = {
164
153
  ...this.props.api.restApi,
165
154
  defaultMethodOptions: {
@@ -168,9 +157,6 @@ export class ApiToLambdaTarget extends CommonConstruct {
168
157
  this.apiToLambdaTargetRestApi.methodErrorResponse,
169
158
  ],
170
159
  },
171
- deployOptions: {
172
- accessLogDestination: new LogGroupLogDestination(accessLogGroup),
173
- },
174
160
  }
175
161
 
176
162
  this.apiToLambdaTargetRestApi.api = this.apiManager.createLambdaRestApi(
@@ -1,4 +1,4 @@
1
- import { Tags, Size } from 'aws-cdk-lib'
1
+ import { RemovalPolicy, Size, Tags } from 'aws-cdk-lib'
2
2
  import {
3
3
  Cors,
4
4
  Deployment,
@@ -9,8 +9,9 @@ import {
9
9
  IRestApi,
10
10
  Integration,
11
11
  LambdaRestApi,
12
- SecurityPolicy,
12
+ LogGroupLogDestination,
13
13
  MethodResponse,
14
+ SecurityPolicy,
14
15
  } from 'aws-cdk-lib/aws-apigateway'
15
16
  import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'
16
17
  import { IFunction } from 'aws-cdk-lib/aws-lambda'
@@ -48,12 +49,27 @@ export class ApiManager {
48
49
  if (!props) throw `Api props undefined for ${id}`
49
50
  if (!props.restApiName) throw `Api restApiName undefined for ${id}`
50
51
 
52
+ const restApiName = scope.resourceNameFormatter.format(
53
+ props.restApiName,
54
+ scope.props.resourceNameOptions?.apigateway
55
+ )
56
+ const restApiAccessLogName = scope.resourceNameFormatter.format(
57
+ `${props.restApiName}-access`,
58
+ scope.props.resourceNameOptions?.apigateway
59
+ )
60
+
61
+ const accessLogGroup = scope.logManager.createLogGroup(`${id}-rest-api-access-log`, scope, {
62
+ logGroupName: restApiAccessLogName,
63
+ removalPolicy: RemovalPolicy.DESTROY,
64
+ })
65
+
51
66
  const api = new LambdaRestApi(scope, `${id}`, {
52
67
  ...props,
53
68
  cloudWatchRole: props.cloudWatchRole || false,
54
69
  deploy: props.deploy || true,
55
70
  deployOptions: {
56
71
  ...props.deployOptions,
72
+ accessLogDestination: new LogGroupLogDestination(accessLogGroup),
57
73
  description: `${id} - ${scope.props.stage} stage`,
58
74
  stageName: scope.props.stage,
59
75
  },
@@ -65,7 +81,7 @@ export class ApiManager {
65
81
  handler: lambdaFunction,
66
82
  minCompressionSize: props.minCompressionSizeInBytes ? Size.bytes(props.minCompressionSizeInBytes) : undefined,
67
83
  proxy: props.proxy ?? true,
68
- restApiName: scope.resourceNameFormatter.format(props.restApiName, scope.props.resourceNameOptions?.apigateway),
84
+ restApiName,
69
85
  })
70
86
 
71
87
  if (props.tags && !_.isEmpty(props.tags)) {
@@ -64,7 +64,7 @@ export class LogManager {
64
64
 
65
65
  const logGroup = new logs.CfnLogGroup(scope, `${id}`, {
66
66
  ...props,
67
- logGroupName: `${scope.resourceNameFormatter.format(props.logGroupName, scope.props.resourceNameOptions?.logs)}`,
67
+ logGroupName: props.logGroupName,
68
68
  retentionInDays: props.retention,
69
69
  })
70
70
 
@@ -91,7 +91,7 @@ export class LogManager {
91
91
 
92
92
  const logGroup = new logs.LogGroup(scope, `${id}`, {
93
93
  ...props,
94
- logGroupName: `${scope.resourceNameFormatter.format(props.logGroupName, scope.props.resourceNameOptions?.logs)}`,
94
+ logGroupName: props.logGroupName,
95
95
  removalPolicy: props.removalPolicy ?? cdk.RemovalPolicy.DESTROY,
96
96
  retention: props.retention,
97
97
  })
@@ -147,7 +147,7 @@ export class LambdaManager {
147
147
  handler: handler || 'index.lambda_handler',
148
148
  layers,
149
149
  logGroup: scope.logManager.createLogGroup(`${id}-log-group`, scope, {
150
- logGroupName: props.functionName,
150
+ logGroupName: functionName,
151
151
  removalPolicy: RemovalPolicy.DESTROY,
152
152
  retention: scope.props.logRetention ?? logRetention,
153
153
  }),
@@ -306,7 +306,7 @@ export class LambdaManager {
306
306
  filesystem: accessPoint ? FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg') : undefined,
307
307
  functionName,
308
308
  logGroup: scope.logManager.createLogGroup(`${id}-log-group`, scope, {
309
- logGroupName: props.functionName,
309
+ logGroupName: functionName,
310
310
  removalPolicy: RemovalPolicy.DESTROY,
311
311
  retention: scope.props.logRetention ?? logRetention,
312
312
  }),