@gradientedge/cdk-utils 5.14.0 → 6.0.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/dist/src/lib/construct/api-to-eventbridge-target/index.d.ts +0 -3
- package/dist/src/lib/construct/api-to-eventbridge-target/index.js +0 -3
- package/dist/src/lib/construct/api-to-eventbridge-target/main.d.ts +23 -68
- package/dist/src/lib/construct/api-to-eventbridge-target/main.js +120 -241
- package/dist/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.d.ts +1 -1
- package/dist/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.js +1 -1
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/index.d.ts +2 -0
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/index.js +18 -0
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.d.ts +193 -0
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.js +631 -0
- package/dist/src/lib/construct/index.d.ts +1 -0
- package/dist/src/lib/construct/index.js +1 -0
- package/dist/src/lib/{construct/api-to-eventbridge-target/api-destination-event.d.ts → helper/api-to-eventbridge-target-event.d.ts} +5 -3
- package/dist/src/lib/{construct/api-to-eventbridge-target/api-destination-event.js → helper/api-to-eventbridge-target-event.js} +6 -4
- package/dist/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.d.ts → helper/api-to-eventbridge-target-rest-api.d.ts} +4 -4
- package/dist/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.js → helper/api-to-eventbridge-target-rest-api.js} +5 -5
- package/dist/src/lib/helper/index.d.ts +2 -0
- package/dist/src/lib/helper/index.js +18 -0
- package/dist/src/lib/types/aws/index.d.ts +10 -5
- package/package.json +1 -1
- package/src/lib/construct/api-to-eventbridge-target/index.ts +0 -3
- package/src/lib/construct/api-to-eventbridge-target/main.ts +127 -278
- package/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.ts +1 -1
- package/src/lib/construct/api-to-eventbridge-target-with-sns/index.ts +2 -0
- package/src/lib/construct/api-to-eventbridge-target-with-sns/main.ts +703 -0
- package/src/lib/construct/index.ts +1 -0
- package/src/lib/{construct/api-to-eventbridge-target/api-destination-event.ts → helper/api-to-eventbridge-target-event.ts} +5 -3
- package/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.ts → helper/api-to-eventbridge-target-rest-api.ts} +4 -4
- package/src/lib/helper/index.ts +2 -0
- package/src/lib/types/aws/index.ts +10 -5
|
@@ -29,11 +29,8 @@ const apig = __importStar(require("aws-cdk-lib/aws-apigateway"));
|
|
|
29
29
|
const events = __importStar(require("aws-cdk-lib/aws-events"));
|
|
30
30
|
const eventstargets = __importStar(require("aws-cdk-lib/aws-events-targets"));
|
|
31
31
|
const iam = __importStar(require("aws-cdk-lib/aws-iam"));
|
|
32
|
-
const destinations = __importStar(require("aws-cdk-lib/aws-lambda-destinations"));
|
|
33
32
|
const common_1 = require("../../common");
|
|
34
|
-
const
|
|
35
|
-
const api_destined_lambda_1 = require("./api-destined-lambda");
|
|
36
|
-
const api_destined_rest_api_1 = require("./api-destined-rest-api");
|
|
33
|
+
const helper = __importStar(require("../../helper"));
|
|
37
34
|
/**
|
|
38
35
|
* @stability stable
|
|
39
36
|
* @category cdk-utils.api-to-eventbridge-target
|
|
@@ -61,20 +58,17 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
61
58
|
id;
|
|
62
59
|
/* application related resources */
|
|
63
60
|
applicationSecrets;
|
|
64
|
-
/* destined lambda related resources */
|
|
65
|
-
apiDestinedLambda;
|
|
66
61
|
/* event related resources */
|
|
67
62
|
apiEvent;
|
|
68
63
|
/* rest restApi related resources */
|
|
69
|
-
|
|
64
|
+
apiToEventBridgeTargetRestApi;
|
|
70
65
|
apiResource;
|
|
71
66
|
constructor(parent, id, props) {
|
|
72
67
|
super(parent, id, props);
|
|
73
68
|
this.props = props;
|
|
74
69
|
this.id = id;
|
|
75
|
-
this.
|
|
76
|
-
this.
|
|
77
|
-
this.apiDestinedRestApi = new api_destined_rest_api_1.ApiDestinedRestApi();
|
|
70
|
+
this.apiEvent = new helper.ApiToEventbridgeTargetEvent();
|
|
71
|
+
this.apiToEventBridgeTargetRestApi = new helper.ApiToEventbridgeTargetRestApi();
|
|
78
72
|
this.apiResource = 'notify';
|
|
79
73
|
}
|
|
80
74
|
initResources() {
|
|
@@ -84,34 +78,25 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
84
78
|
this.resolveHostedZone();
|
|
85
79
|
this.resolveCertificate();
|
|
86
80
|
/* optional custom event bus */
|
|
87
|
-
this.
|
|
88
|
-
/* destined lambda related resources */
|
|
89
|
-
this.createApiDestinedLambdaPolicy();
|
|
90
|
-
this.createApiDestinedLambdaRole();
|
|
91
|
-
this.createApiDestinedLambdaEnvironment();
|
|
92
|
-
this.createApiDestinedLambdaLayers();
|
|
93
|
-
this.createApiDestinedLambdaDestinations();
|
|
94
|
-
this.createApiDestinedLambdaFunction();
|
|
81
|
+
this.createApiToEventBridgeTargetEventBus();
|
|
95
82
|
/* event related resources */
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
83
|
+
this.createApiToEventBridgeTargetLogGroup();
|
|
84
|
+
this.createApiToEventBridgeTargetRule();
|
|
85
|
+
this.createApiToEventBridgeTargetPolicy();
|
|
86
|
+
this.createApiToEventBridgeTargetRole();
|
|
100
87
|
/* restApi related resources */
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
108
|
-
this.
|
|
109
|
-
this.
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
113
|
-
this.createApiDestinedMethodErrorResponse();
|
|
114
|
-
this.createApiDestinedResourceMethod();
|
|
88
|
+
this.createApiToEventBridgeTargetIntegrationRequestParameters();
|
|
89
|
+
this.createApiToEventBridgeTargetIntegrationRequestTemplates();
|
|
90
|
+
this.createApiToEventBridgeTargetIntegrationResponse();
|
|
91
|
+
this.createApiToEventBridgeTargetIntegrationErrorResponse();
|
|
92
|
+
this.createApiToEventBridgeTargetIntegration();
|
|
93
|
+
this.createApiToEventBridgeTargetRestApi();
|
|
94
|
+
this.createApiToEventBridgeTargetResource();
|
|
95
|
+
this.createApiToEventBridgeTargetResponseModel();
|
|
96
|
+
this.createApiToEventBridgeTargetErrorResponseModel();
|
|
97
|
+
this.createApiToEventBridgeTargetMethodResponse();
|
|
98
|
+
this.createApiToEventBridgeTargetMethodErrorResponse();
|
|
99
|
+
this.createApiToEventBridgeTargetResourceMethod();
|
|
115
100
|
this.createApiDomain();
|
|
116
101
|
this.createApiBasePathMapping();
|
|
117
102
|
this.createApiRouteAssets();
|
|
@@ -129,7 +114,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
129
114
|
* @protected
|
|
130
115
|
*/
|
|
131
116
|
resolveHostedZone() {
|
|
132
|
-
this.
|
|
117
|
+
this.apiToEventBridgeTargetRestApi.hostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(`${this.id}-hosted-zone`, this, this.props.useExistingHostedZone);
|
|
133
118
|
}
|
|
134
119
|
/**
|
|
135
120
|
* @summary Method to resolve a certificate based on attributes
|
|
@@ -143,200 +128,79 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
143
128
|
this.props.api.certificate.certificateRegion) {
|
|
144
129
|
this.props.api.certificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-param`, this, this.props.api.certificate.certificateSsmName, this.props.api.certificate.certificateRegion);
|
|
145
130
|
}
|
|
146
|
-
this.
|
|
131
|
+
this.apiToEventBridgeTargetRestApi.certificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.api.certificate);
|
|
147
132
|
}
|
|
148
133
|
/**
|
|
149
|
-
* @summary Method to create
|
|
134
|
+
* @summary Method to create or use an existing eventbus for api payload deliveries
|
|
150
135
|
* @protected
|
|
151
136
|
*/
|
|
152
|
-
|
|
153
|
-
if (this.props.api.useExisting)
|
|
154
|
-
return;
|
|
155
|
-
this.apiDestinedLambda.policy = new iam.PolicyDocument({
|
|
156
|
-
statements: [this.iamManager.statementForReadSecrets(this), this.iamManager.statementForPutEvents()],
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* @summary Method to create iam role for Api Destined Lambda function
|
|
161
|
-
* @protected
|
|
162
|
-
*/
|
|
163
|
-
createApiDestinedLambdaRole() {
|
|
164
|
-
if (this.props.api.useExisting)
|
|
165
|
-
return;
|
|
166
|
-
this.apiDestinedLambda.role = this.iamManager.createRoleForLambda(`${this.id}-lambda-destined-role`, this, this.apiDestinedLambda.policy);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* @summary Method to create environment variables for Api Destined Lambda function
|
|
170
|
-
* @protected
|
|
171
|
-
*/
|
|
172
|
-
createApiDestinedLambdaEnvironment() {
|
|
173
|
-
if (this.props.api.useExisting)
|
|
174
|
-
return;
|
|
175
|
-
this.apiDestinedLambda.environment = {
|
|
176
|
-
NODE_ENV: this.props.nodeEnv,
|
|
177
|
-
LOG_LEVEL: this.props.logLevel,
|
|
178
|
-
TZ: this.props.timezone,
|
|
179
|
-
SOURCE_ID: this.id,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* @summary Method to create layers for Api Destined Lambda function
|
|
184
|
-
* @protected
|
|
185
|
-
*/
|
|
186
|
-
createApiDestinedLambdaLayers() {
|
|
187
|
-
if (this.props.api.useExisting)
|
|
188
|
-
return;
|
|
189
|
-
const layers = [];
|
|
190
|
-
if (this.props.lambda.layerSource) {
|
|
191
|
-
layers.push(this.lambdaManager.createLambdaLayer(`${this.id}-lambda-destined-layer`, this, this.props.lambda.layerSource));
|
|
192
|
-
}
|
|
193
|
-
this.apiDestinedLambda.layers = layers;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* @summary Method to create destination for Api Destined function
|
|
197
|
-
* @protected
|
|
198
|
-
*/
|
|
199
|
-
createApiDestinedLambdaDestinations() {
|
|
200
|
-
if (this.props.api.useExisting)
|
|
201
|
-
return;
|
|
202
|
-
this.apiDestinedLambda.destinationSuccess = new destinations.EventBridgeDestination(this.apiEvent.eventBus);
|
|
203
|
-
this.apiDestinedLambda.destinationFailure = new destinations.EventBridgeDestination(this.apiEvent.eventBus);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* @summary Method to create lambda function for Api Destined
|
|
207
|
-
* @protected
|
|
208
|
-
*/
|
|
209
|
-
createApiDestinedLambdaFunction() {
|
|
210
|
-
if (this.props.api.useExisting)
|
|
211
|
-
return;
|
|
212
|
-
if (!this.props.lambda.source)
|
|
213
|
-
throw 'Api Destined Lambda props undefined';
|
|
214
|
-
this.apiDestinedLambda.function = this.lambdaManager.createLambdaFunction(`${this.id}-lambda-destined`, this, {
|
|
215
|
-
...this.props.lambda.function,
|
|
216
|
-
...{
|
|
217
|
-
onSuccess: this.apiDestinedLambda.destinationSuccess,
|
|
218
|
-
onFailure: this.apiDestinedLambda.destinationFailure,
|
|
219
|
-
},
|
|
220
|
-
}, this.apiDestinedLambda.role, this.apiDestinedLambda.layers, this.props.lambda.source, this.props.lambda.handler ?? 'lambda.handler', this.apiDestinedLambda.environment);
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* @summary Method to create or use an existing eventbus for api destined payload deliveries
|
|
224
|
-
* @protected
|
|
225
|
-
*/
|
|
226
|
-
createApiDestinedEventBus() {
|
|
137
|
+
createApiToEventBridgeTargetEventBus() {
|
|
227
138
|
if (this.props.api.useExisting) {
|
|
228
|
-
this.apiEvent.eventBus = events.EventBus.fromEventBusName(this, `${this.id}-
|
|
139
|
+
this.apiEvent.eventBus = events.EventBus.fromEventBusName(this, `${this.id}-event-bus`, `${this.props.event.eventBusName}-${this.props.stage}`);
|
|
229
140
|
return;
|
|
230
141
|
}
|
|
231
|
-
this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-
|
|
142
|
+
this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-event-bus`, this, {
|
|
232
143
|
eventBusName: `${this.props.event.eventBusName}`,
|
|
233
144
|
});
|
|
234
145
|
}
|
|
235
146
|
/**
|
|
236
|
-
* @summary Method to create a log group for successful api
|
|
147
|
+
* @summary Method to create a log group for successful api payload deliveries
|
|
237
148
|
* @protected
|
|
238
149
|
*/
|
|
239
|
-
|
|
150
|
+
createApiToEventBridgeTargetLogGroup() {
|
|
240
151
|
if (this.props.api.useExisting)
|
|
241
152
|
return;
|
|
242
|
-
this.apiEvent.
|
|
153
|
+
this.apiEvent.logGroup = this.logManager.createLogGroup(`${this.id}-log`, this, {
|
|
243
154
|
...{
|
|
244
|
-
logGroupName: `/${this.id}/events/api-
|
|
155
|
+
logGroupName: `/${this.id}/events/api-to-eventbridge-target`,
|
|
245
156
|
},
|
|
246
|
-
...this.props.event.
|
|
157
|
+
...this.props.event.logGroup,
|
|
247
158
|
});
|
|
248
159
|
}
|
|
249
160
|
/**
|
|
250
161
|
* Method to create EventBridge rule with lambda target for success
|
|
251
162
|
* @protected
|
|
252
163
|
*/
|
|
253
|
-
|
|
164
|
+
createApiToEventBridgeTargetRule() {
|
|
254
165
|
if (this.props.api.useExisting)
|
|
255
166
|
return;
|
|
256
|
-
this.props.event.
|
|
167
|
+
this.props.event.rule = {
|
|
257
168
|
...{
|
|
258
|
-
ruleName: `${this.id}-api-
|
|
169
|
+
ruleName: `${this.id}-api-to-eventbridge-target`,
|
|
259
170
|
eventPattern: {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
condition: ['Success'],
|
|
263
|
-
},
|
|
264
|
-
responsePayload: {
|
|
265
|
-
source: ['custom:api-destined-lambda'],
|
|
266
|
-
sourceId: [this.id],
|
|
267
|
-
},
|
|
268
|
-
},
|
|
171
|
+
source: ['api-to-eventbridge-target'],
|
|
172
|
+
detailType: ['external-client-event'],
|
|
269
173
|
},
|
|
270
174
|
},
|
|
271
|
-
...this.props.event.
|
|
175
|
+
...this.props.event.rule,
|
|
272
176
|
};
|
|
273
|
-
this.apiEvent.
|
|
177
|
+
this.apiEvent.rule = this.eventManager.createRule(`${this.id}-api-to-eventbridge-target-rule`, this, this.props.event.rule, this.apiEvent.eventBus, [new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroup)]);
|
|
274
178
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
*/
|
|
279
|
-
createApiDestinationLogGroupFailure() {
|
|
280
|
-
if (this.props.api.useExisting)
|
|
281
|
-
return;
|
|
282
|
-
this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
|
|
283
|
-
...{
|
|
284
|
-
logGroupName: `/${this.id}/events/api-destination-failure`,
|
|
285
|
-
},
|
|
286
|
-
...this.props.event.logGroupFailure,
|
|
179
|
+
createApiToEventBridgeTargetPolicy() {
|
|
180
|
+
this.apiToEventBridgeTargetRestApi.policy = new iam.PolicyDocument({
|
|
181
|
+
statements: [this.iamManager.statementForPutEvents()],
|
|
287
182
|
});
|
|
288
183
|
}
|
|
289
184
|
/**
|
|
290
|
-
* Method to create
|
|
291
|
-
* @protected
|
|
292
|
-
*/
|
|
293
|
-
createApiDestinationRuleFailure() {
|
|
294
|
-
if (this.props.api.useExisting)
|
|
295
|
-
return;
|
|
296
|
-
this.props.event.ruleFailure = {
|
|
297
|
-
...{
|
|
298
|
-
ruleName: `${this.id}-api-destination-failure`,
|
|
299
|
-
eventPattern: {
|
|
300
|
-
detail: {
|
|
301
|
-
responsePayload: {
|
|
302
|
-
errorType: ['Error'],
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
},
|
|
307
|
-
...this.props.event.ruleFailure,
|
|
308
|
-
};
|
|
309
|
-
this.apiEvent.ruleFailure = this.eventManager.createRule(`${this.id}-api-destination-rule-failure`, this, this.props.event.ruleFailure, this.apiEvent.eventBus, [new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroupFailure)]);
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* @summary Method to create a role for sns topic
|
|
185
|
+
* @summary Method to create a role for api integration
|
|
313
186
|
* @protected
|
|
314
187
|
*/
|
|
315
|
-
|
|
316
|
-
|
|
188
|
+
createApiToEventBridgeTargetRole() {
|
|
189
|
+
if (!this.apiToEventBridgeTargetRestApi.policy)
|
|
190
|
+
throw 'Policy undefined';
|
|
191
|
+
this.apiToEventBridgeTargetRestApi.role = new iam.Role(this, `${this.id}-rest-api-role`, {
|
|
317
192
|
assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
|
|
193
|
+
inlinePolicies: { policy: this.apiToEventBridgeTargetRestApi.policy },
|
|
318
194
|
});
|
|
319
195
|
}
|
|
320
|
-
/**
|
|
321
|
-
* @summary Method to create API destined SNS topic
|
|
322
|
-
* @protected
|
|
323
|
-
*/
|
|
324
|
-
createApiDestinedTopic() {
|
|
325
|
-
if (!this.props.api.withResource)
|
|
326
|
-
return;
|
|
327
|
-
this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(`${this.id}-destined-topic`, this, {
|
|
328
|
-
topicName: `${this.id}-destined-topic`,
|
|
329
|
-
}, this.apiDestinedLambda.function);
|
|
330
|
-
this.apiDestinedRestApi.topic.grantPublish(this.apiDestinedRestApi.topicRole);
|
|
331
|
-
}
|
|
332
196
|
/**
|
|
333
197
|
* @summary Method to create api integration request parameters
|
|
334
198
|
* @protected
|
|
335
199
|
*/
|
|
336
|
-
|
|
200
|
+
createApiToEventBridgeTargetIntegrationRequestParameters() {
|
|
337
201
|
if (!this.props.api.withResource)
|
|
338
202
|
return;
|
|
339
|
-
this.
|
|
203
|
+
this.apiToEventBridgeTargetRestApi.integrationRequestParameters = {
|
|
340
204
|
'integration.request.header.Content-Type': "'application/x-www-form-urlencoded'",
|
|
341
205
|
};
|
|
342
206
|
}
|
|
@@ -344,26 +208,35 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
344
208
|
* @summary Method to create api integration request templates
|
|
345
209
|
* @protected
|
|
346
210
|
*/
|
|
347
|
-
|
|
211
|
+
createApiToEventBridgeTargetIntegrationRequestTemplates() {
|
|
348
212
|
if (!this.props.api.withResource)
|
|
349
213
|
return;
|
|
350
|
-
this.
|
|
214
|
+
this.apiToEventBridgeTargetRestApi.integrationRequestTemplates = {
|
|
351
215
|
'application/json': [
|
|
352
|
-
'
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
216
|
+
'#set($context.requestOverride.header.X-Amz-Target = "AWSEvents.PutEvents")',
|
|
217
|
+
'#set($context.requestOverride.header.Content-Type = "application/x-amz-json-1.1")',
|
|
218
|
+
"#set($inputRoot = $input.path('$'))",
|
|
219
|
+
`{
|
|
220
|
+
"Entries": [
|
|
221
|
+
{
|
|
222
|
+
"EventBusName": "${this.apiEvent.eventBus.eventBusName}",
|
|
223
|
+
"Source": "api-to-eventbridge-target",
|
|
224
|
+
"DetailType": "external-client-event",
|
|
225
|
+
"Detail": "$util.escapeJavaScript($input.json('$'))"
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
}`,
|
|
229
|
+
].join('\r'),
|
|
357
230
|
};
|
|
358
231
|
}
|
|
359
232
|
/**
|
|
360
233
|
* @summary Method to create api integration response
|
|
361
234
|
* @protected
|
|
362
235
|
*/
|
|
363
|
-
|
|
236
|
+
createApiToEventBridgeTargetIntegrationResponse() {
|
|
364
237
|
if (!this.props.api.withResource)
|
|
365
238
|
return;
|
|
366
|
-
this.
|
|
239
|
+
this.apiToEventBridgeTargetRestApi.integrationResponse = this.props.api.integrationResponse ?? {
|
|
367
240
|
...{
|
|
368
241
|
statusCode: '200',
|
|
369
242
|
responseTemplates: {
|
|
@@ -376,10 +249,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
376
249
|
* @summary Method to create api integration error response
|
|
377
250
|
* @protected
|
|
378
251
|
*/
|
|
379
|
-
|
|
252
|
+
createApiToEventBridgeTargetIntegrationErrorResponse() {
|
|
380
253
|
if (!this.props.api.withResource)
|
|
381
254
|
return;
|
|
382
|
-
this.
|
|
255
|
+
this.apiToEventBridgeTargetRestApi.integrationErrorResponse = {
|
|
383
256
|
...{
|
|
384
257
|
selectionPattern: '^\\[Error\\].*',
|
|
385
258
|
statusCode: '400',
|
|
@@ -402,22 +275,22 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
402
275
|
* @summary Method to create api integration
|
|
403
276
|
* @protected
|
|
404
277
|
*/
|
|
405
|
-
|
|
278
|
+
createApiToEventBridgeTargetIntegration() {
|
|
406
279
|
if (!this.props.api.withResource)
|
|
407
280
|
return;
|
|
408
|
-
this.
|
|
281
|
+
this.apiToEventBridgeTargetRestApi.integration = new apig.Integration({
|
|
409
282
|
type: apig.IntegrationType.AWS,
|
|
410
283
|
integrationHttpMethod: 'POST',
|
|
411
|
-
uri: `arn:aws:apigateway:${this.props.region}:
|
|
284
|
+
uri: `arn:aws:apigateway:${this.props.region}:events:path//`,
|
|
412
285
|
options: {
|
|
413
286
|
...{
|
|
414
|
-
credentialsRole: this.
|
|
415
|
-
requestParameters: this.
|
|
416
|
-
requestTemplates: this.
|
|
287
|
+
credentialsRole: this.apiToEventBridgeTargetRestApi.role,
|
|
288
|
+
requestParameters: this.apiToEventBridgeTargetRestApi.integrationRequestParameters,
|
|
289
|
+
requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
|
|
417
290
|
passthroughBehavior: apig.PassthroughBehavior.NEVER,
|
|
418
291
|
integrationResponses: [
|
|
419
|
-
this.
|
|
420
|
-
this.
|
|
292
|
+
this.apiToEventBridgeTargetRestApi.integrationResponse,
|
|
293
|
+
this.apiToEventBridgeTargetRestApi.integrationErrorResponse,
|
|
421
294
|
],
|
|
422
295
|
},
|
|
423
296
|
...this.props.api.integrationOptions,
|
|
@@ -428,10 +301,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
428
301
|
* @summary Method to create api integration method response
|
|
429
302
|
* @protected
|
|
430
303
|
*/
|
|
431
|
-
|
|
304
|
+
createApiToEventBridgeTargetMethodResponse() {
|
|
432
305
|
if (!this.props.api.withResource)
|
|
433
306
|
return;
|
|
434
|
-
this.
|
|
307
|
+
this.apiToEventBridgeTargetRestApi.methodResponse = {
|
|
435
308
|
...{
|
|
436
309
|
statusCode: '200',
|
|
437
310
|
responseParameters: {
|
|
@@ -440,7 +313,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
440
313
|
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
441
314
|
},
|
|
442
315
|
responseModels: {
|
|
443
|
-
'application/json': this.
|
|
316
|
+
'application/json': this.apiToEventBridgeTargetRestApi.responseModel,
|
|
444
317
|
},
|
|
445
318
|
},
|
|
446
319
|
...this.props.api.methodResponse,
|
|
@@ -450,10 +323,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
450
323
|
* @summary Method to create api integration method error response
|
|
451
324
|
* @protected
|
|
452
325
|
*/
|
|
453
|
-
|
|
326
|
+
createApiToEventBridgeTargetMethodErrorResponse() {
|
|
454
327
|
if (!this.props.api.withResource)
|
|
455
328
|
return;
|
|
456
|
-
this.
|
|
329
|
+
this.apiToEventBridgeTargetRestApi.methodErrorResponse = {
|
|
457
330
|
...{
|
|
458
331
|
statusCode: '400',
|
|
459
332
|
responseParameters: {
|
|
@@ -462,7 +335,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
462
335
|
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
463
336
|
},
|
|
464
337
|
responseModels: {
|
|
465
|
-
'application/json': this.
|
|
338
|
+
'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
|
|
466
339
|
},
|
|
467
340
|
},
|
|
468
341
|
...this.props.api.methodErrorResponse,
|
|
@@ -472,20 +345,23 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
472
345
|
* @summary Method to create rest restApi for Api
|
|
473
346
|
* @protected
|
|
474
347
|
*/
|
|
475
|
-
|
|
348
|
+
createApiToEventBridgeTargetRestApi() {
|
|
476
349
|
if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
|
|
477
|
-
this.
|
|
350
|
+
this.apiToEventBridgeTargetRestApi.api = apig.RestApi.fromRestApiId(this, `${this.id}-rest-api`, cdk.Fn.importValue(this.props.api.importedRestApiRef));
|
|
478
351
|
return;
|
|
479
352
|
}
|
|
480
|
-
const accessLogGroup = this.logManager.createLogGroup(`${this.id}-
|
|
481
|
-
logGroupName: `/custom/api/${this.id}-
|
|
353
|
+
const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
|
|
354
|
+
logGroupName: `/custom/api/${this.id}-rest-api-access-${this.props.stage}`,
|
|
482
355
|
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
483
356
|
});
|
|
484
|
-
this.
|
|
357
|
+
this.apiToEventBridgeTargetRestApi.api = new apig.RestApi(this, `${this.id}-rest-api`, {
|
|
485
358
|
...{
|
|
486
|
-
defaultIntegration: this.
|
|
359
|
+
defaultIntegration: this.apiToEventBridgeTargetRestApi.integration,
|
|
487
360
|
defaultMethodOptions: {
|
|
488
|
-
methodResponses: [
|
|
361
|
+
methodResponses: [
|
|
362
|
+
this.apiToEventBridgeTargetRestApi.methodResponse,
|
|
363
|
+
this.apiToEventBridgeTargetRestApi.methodErrorResponse,
|
|
364
|
+
],
|
|
489
365
|
},
|
|
490
366
|
deployOptions: {
|
|
491
367
|
dataTraceEnabled: true,
|
|
@@ -504,22 +380,22 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
504
380
|
allowMethods: ['POST'],
|
|
505
381
|
allowHeaders: apig.Cors.DEFAULT_HEADERS,
|
|
506
382
|
},
|
|
507
|
-
restApiName: `${this.id}-
|
|
383
|
+
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
508
384
|
},
|
|
509
385
|
...this.props.api,
|
|
510
386
|
});
|
|
511
|
-
this.addCfnOutput(`${this.id}-restApiId`, this.
|
|
512
|
-
this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.
|
|
387
|
+
this.addCfnOutput(`${this.id}-restApiId`, this.apiToEventBridgeTargetRestApi.api.restApiId);
|
|
388
|
+
this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiToEventBridgeTargetRestApi.api.root.resourceId);
|
|
513
389
|
}
|
|
514
390
|
/**
|
|
515
391
|
* @summary Method to create api integration response model
|
|
516
392
|
* @protected
|
|
517
393
|
*/
|
|
518
|
-
|
|
394
|
+
createApiToEventBridgeTargetResponseModel() {
|
|
519
395
|
if (!this.props.api.withResource)
|
|
520
396
|
return;
|
|
521
|
-
this.
|
|
522
|
-
restApi: this.
|
|
397
|
+
this.apiToEventBridgeTargetRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
|
|
398
|
+
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
523
399
|
...{
|
|
524
400
|
contentType: 'application/json',
|
|
525
401
|
modelName: 'ResponseModel',
|
|
@@ -537,11 +413,11 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
537
413
|
* @summary Method to create api integration error response model
|
|
538
414
|
* @protected
|
|
539
415
|
*/
|
|
540
|
-
|
|
416
|
+
createApiToEventBridgeTargetErrorResponseModel() {
|
|
541
417
|
if (!this.props.api.withResource)
|
|
542
418
|
return;
|
|
543
|
-
this.
|
|
544
|
-
restApi: this.
|
|
419
|
+
this.apiToEventBridgeTargetRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
|
|
420
|
+
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
545
421
|
...{
|
|
546
422
|
contentType: 'application/json',
|
|
547
423
|
modelName: 'ErrorResponseModel',
|
|
@@ -562,32 +438,35 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
562
438
|
* @summary Method to create api integration resource
|
|
563
439
|
* @protected
|
|
564
440
|
*/
|
|
565
|
-
|
|
441
|
+
createApiToEventBridgeTargetResource() {
|
|
566
442
|
if (!this.props.api.withResource)
|
|
567
443
|
return;
|
|
568
444
|
let rootResource;
|
|
569
445
|
if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
|
|
570
446
|
rootResource = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
|
|
571
447
|
resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
|
|
572
|
-
restApi: this.
|
|
448
|
+
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
573
449
|
path: '/',
|
|
574
450
|
});
|
|
575
451
|
}
|
|
576
452
|
else {
|
|
577
|
-
rootResource = this.
|
|
453
|
+
rootResource = this.apiToEventBridgeTargetRestApi.api.root;
|
|
578
454
|
}
|
|
579
|
-
this.
|
|
455
|
+
this.apiToEventBridgeTargetRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource);
|
|
580
456
|
}
|
|
581
457
|
/**
|
|
582
458
|
* @summary Method to create api integration resource method
|
|
583
459
|
* @protected
|
|
584
460
|
*/
|
|
585
|
-
|
|
461
|
+
createApiToEventBridgeTargetResourceMethod() {
|
|
586
462
|
if (!this.props.api.withResource)
|
|
587
463
|
return;
|
|
588
|
-
this.
|
|
589
|
-
authorizer: this.
|
|
590
|
-
methodResponses: [
|
|
464
|
+
this.apiToEventBridgeTargetRestApi.method = this.apiToEventBridgeTargetRestApi.resource.addMethod('POST', this.apiToEventBridgeTargetRestApi.integration, {
|
|
465
|
+
authorizer: this.apiToEventBridgeTargetRestApi.authoriser,
|
|
466
|
+
methodResponses: [
|
|
467
|
+
this.apiToEventBridgeTargetRestApi.methodResponse,
|
|
468
|
+
this.apiToEventBridgeTargetRestApi.methodErrorResponse,
|
|
469
|
+
],
|
|
591
470
|
});
|
|
592
471
|
}
|
|
593
472
|
/**
|
|
@@ -597,9 +476,9 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
597
476
|
createApiDomain() {
|
|
598
477
|
if (this.props.api.useExisting)
|
|
599
478
|
return;
|
|
600
|
-
this.
|
|
479
|
+
this.apiToEventBridgeTargetRestApi.domain = this.apiManager.createApiDomain(`${this.id}-api-domain`, this, this.isProductionStage() || this.props.skipStageForARecords
|
|
601
480
|
? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
|
|
602
|
-
: `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`, this.
|
|
481
|
+
: `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`, this.apiToEventBridgeTargetRestApi.certificate);
|
|
603
482
|
}
|
|
604
483
|
/**
|
|
605
484
|
* @summary Method to create base path mappings for Api API
|
|
@@ -610,9 +489,9 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
610
489
|
return;
|
|
611
490
|
new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
|
|
612
491
|
basePath: '',
|
|
613
|
-
domainName: this.
|
|
614
|
-
restApi: this.
|
|
615
|
-
stage: this.
|
|
492
|
+
domainName: this.apiToEventBridgeTargetRestApi.domain,
|
|
493
|
+
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
494
|
+
stage: this.apiToEventBridgeTargetRestApi.api.deploymentStage,
|
|
616
495
|
});
|
|
617
496
|
}
|
|
618
497
|
/**
|
|
@@ -622,7 +501,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
622
501
|
createApiRouteAssets() {
|
|
623
502
|
if (this.props.api.useExisting)
|
|
624
503
|
return;
|
|
625
|
-
this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.
|
|
504
|
+
this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.apiToEventBridgeTargetRestApi.domain, this.apiToEventBridgeTargetRestApi.hostedZone, this.props.skipStageForARecords);
|
|
626
505
|
}
|
|
627
506
|
}
|
|
628
507
|
exports.ApiToEventBridgeTarget = ApiToEventBridgeTarget;
|
|
@@ -6,7 +6,7 @@ import * as types from '../../types/aws';
|
|
|
6
6
|
* @stability stable
|
|
7
7
|
* @category cdk-utils.api-to-eventbridge-target
|
|
8
8
|
* @subcategory member
|
|
9
|
-
* @classdesc Provides a construct to contain lambda resources for
|
|
9
|
+
* @classdesc Provides a construct to contain lambda resources for ApiToEventBridgeTargetWithSns
|
|
10
10
|
*/
|
|
11
11
|
export declare class ApiDestinedLambda implements types.ApiDestinedLambdaType {
|
|
12
12
|
destinationFailure: destinations.EventBridgeDestination;
|
|
@@ -5,7 +5,7 @@ exports.ApiDestinedLambda = void 0;
|
|
|
5
5
|
* @stability stable
|
|
6
6
|
* @category cdk-utils.api-to-eventbridge-target
|
|
7
7
|
* @subcategory member
|
|
8
|
-
* @classdesc Provides a construct to contain lambda resources for
|
|
8
|
+
* @classdesc Provides a construct to contain lambda resources for ApiToEventBridgeTargetWithSns
|
|
9
9
|
*/
|
|
10
10
|
class ApiDestinedLambda {
|
|
11
11
|
destinationFailure;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api-destined-lambda"), exports);
|
|
18
|
+
__exportStar(require("./main"), exports);
|