@gradientedge/cdk-utils 8.121.0 → 8.123.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/README.md +2 -1
- package/dist/src/lib/aws/common/construct.d.ts +0 -1
- package/dist/src/lib/aws/common/construct.js +6 -13
- package/dist/src/lib/aws/common/stack.js +7 -9
- package/dist/src/lib/aws/common/types.d.ts +2 -8
- package/dist/src/lib/aws/construct/api-to-any-target/main.js +24 -26
- package/dist/src/lib/aws/construct/api-to-eventbridge-target/main.js +85 -103
- package/dist/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.js +94 -120
- package/dist/src/lib/aws/construct/api-to-lambda-target/main.js +8 -10
- package/dist/src/lib/aws/construct/graphql-api-lambda/main.js +7 -3
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/main.js +5 -1
- package/dist/src/lib/aws/construct/lambda-with-iam-access/main.js +5 -1
- package/dist/src/lib/aws/construct/rest-api-lambda/main.js +7 -3
- package/dist/src/lib/aws/construct/rest-api-lambda-with-cache/main.js +5 -1
- package/dist/src/lib/aws/construct/site-with-ecs-backend/main.js +8 -6
- package/dist/src/lib/aws/construct/static-asset-deployment/main.js +5 -1
- package/dist/src/lib/aws/services/api-gateway/main.js +18 -10
- package/dist/src/lib/aws/services/cloudfront/main.js +11 -7
- package/dist/src/lib/aws/services/cloudwatch/logs.js +8 -4
- package/dist/src/lib/aws/services/cloudwatch/main.js +36 -78
- package/dist/src/lib/aws/services/dynamodb/main.js +6 -2
- package/dist/src/lib/aws/services/elastic-container-service/main.js +8 -4
- package/dist/src/lib/aws/services/elastic-file-system/main.js +5 -1
- package/dist/src/lib/aws/services/elasticache/main.js +6 -2
- package/dist/src/lib/aws/services/eventbridge/main.js +8 -4
- package/dist/src/lib/aws/services/lambda/main.js +7 -3
- package/dist/src/lib/aws/services/simple-notification-service/main.js +6 -2
- package/dist/src/lib/aws/services/simple-queue-service/main.js +6 -2
- package/dist/src/lib/aws/services/simple-storage-service/main.js +8 -4
- package/dist/src/lib/aws/services/step-function/main.js +52 -32
- package/dist/src/lib/aws/services/virtual-private-cloud/main.js +8 -4
- package/dist/src/lib/aws/types/index.d.ts +6 -1
- package/dist/src/lib/aws/types/index.js +0 -15
- package/dist/src/lib/aws/utils/index.d.ts +13 -23
- package/dist/src/lib/aws/utils/index.js +37 -46
- package/dist/src/lib/azure/common/construct.d.ts +35 -0
- package/dist/src/lib/azure/common/construct.js +49 -0
- package/dist/src/lib/azure/common/index.d.ts +3 -0
- package/dist/src/lib/azure/common/index.js +19 -0
- package/dist/src/lib/azure/common/stack.d.ts +52 -0
- package/dist/src/lib/azure/common/stack.js +134 -0
- package/dist/src/lib/azure/common/types.d.ts +7 -0
- package/dist/src/lib/azure/index.d.ts +4 -0
- package/dist/src/lib/azure/index.js +20 -0
- package/dist/src/lib/azure/services/index.d.ts +1 -0
- package/dist/src/lib/azure/services/index.js +17 -0
- package/dist/src/lib/azure/services/storage/index.d.ts +2 -0
- package/dist/src/lib/azure/services/storage/index.js +18 -0
- package/dist/src/lib/azure/services/storage/main.d.ts +43 -0
- package/dist/src/lib/azure/services/storage/main.js +124 -0
- package/dist/src/lib/azure/services/storage/types.d.ts +10 -0
- package/dist/src/lib/azure/services/storage/types.js +2 -0
- package/dist/src/lib/azure/types/index.d.ts +3 -0
- package/dist/src/lib/azure/types/index.js +2 -0
- package/dist/src/lib/azure/utils/index.d.ts +3 -0
- package/dist/src/lib/azure/utils/index.js +20 -0
- package/dist/src/lib/common/construct.d.ts +29 -0
- package/dist/src/lib/common/construct.js +8 -0
- package/dist/src/lib/common/index.d.ts +5 -0
- package/dist/src/lib/common/index.js +33 -0
- package/dist/src/lib/common/stack.d.ts +21 -0
- package/dist/src/lib/common/stack.js +8 -0
- package/dist/src/lib/common/types.d.ts +9 -0
- package/dist/src/lib/common/types.js +2 -0
- package/dist/src/lib/common/utils.d.ts +26 -0
- package/dist/src/lib/common/utils.js +34 -0
- package/dist/src/lib/index.d.ts +2 -0
- package/dist/src/lib/index.js +2 -0
- package/package.json +9 -7
- package/setup.js +2 -0
- package/src/lib/aws/common/construct.ts +2 -13
- package/src/lib/aws/common/stack.ts +6 -8
- package/src/lib/aws/common/types.ts +2 -8
- package/src/lib/aws/construct/api-to-any-target/main.ts +25 -27
- package/src/lib/aws/construct/api-to-eventbridge-target/main.ts +85 -103
- package/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.ts +94 -120
- package/src/lib/aws/construct/api-to-lambda-target/main.ts +8 -10
- package/src/lib/aws/construct/graphql-api-lambda/main.ts +4 -3
- package/src/lib/aws/construct/graphql-api-lambda-with-cache/main.ts +2 -1
- package/src/lib/aws/construct/lambda-with-iam-access/main.ts +2 -1
- package/src/lib/aws/construct/rest-api-lambda/main.ts +4 -3
- package/src/lib/aws/construct/rest-api-lambda-with-cache/main.ts +2 -1
- package/src/lib/aws/construct/site-with-ecs-backend/main.ts +8 -9
- package/src/lib/aws/construct/static-asset-deployment/main.ts +2 -1
- package/src/lib/aws/services/api-gateway/main.ts +9 -6
- package/src/lib/aws/services/cloudfront/main.ts +8 -7
- package/src/lib/aws/services/cloudwatch/logs.ts +6 -5
- package/src/lib/aws/services/cloudwatch/main.ts +35 -81
- package/src/lib/aws/services/dynamodb/main.ts +3 -2
- package/src/lib/aws/services/elastic-container-service/main.ts +5 -4
- package/src/lib/aws/services/elastic-file-system/main.ts +2 -1
- package/src/lib/aws/services/elasticache/main.ts +3 -2
- package/src/lib/aws/services/eventbridge/main.ts +5 -4
- package/src/lib/aws/services/lambda/main.ts +4 -3
- package/src/lib/aws/services/simple-notification-service/main.ts +3 -2
- package/src/lib/aws/services/simple-queue-service/main.ts +3 -2
- package/src/lib/aws/services/simple-storage-service/main.ts +5 -4
- package/src/lib/aws/services/step-function/main.ts +17 -16
- package/src/lib/aws/services/virtual-private-cloud/main.ts +5 -4
- package/src/lib/aws/types/index.ts +6 -1
- package/src/lib/aws/utils/index.ts +41 -29
- package/src/lib/azure/common/construct.ts +57 -0
- package/src/lib/azure/common/index.ts +3 -0
- package/src/lib/azure/common/stack.ts +143 -0
- package/src/lib/azure/common/types.ts +8 -0
- package/src/lib/azure/index.ts +4 -0
- package/src/lib/azure/services/index.ts +1 -0
- package/src/lib/azure/services/storage/index.ts +2 -0
- package/src/lib/azure/services/storage/main.ts +134 -0
- package/src/lib/azure/services/storage/types.ts +10 -0
- package/src/lib/azure/types/index.ts +3 -0
- package/src/lib/azure/utils/index.ts +23 -0
- package/src/lib/common/construct.ts +35 -0
- package/src/lib/common/index.ts +18 -0
- package/src/lib/common/stack.ts +26 -0
- package/src/lib/common/types.ts +9 -0
- package/src/lib/common/utils.ts +27 -0
- package/src/lib/index.ts +2 -0
- package/dist/src/lib/aws/types/aws/index.d.ts +0 -6
- package/dist/src/lib/aws/utils/aws/index.d.ts +0 -17
- package/dist/src/lib/aws/utils/aws/index.js +0 -40
- package/src/lib/aws/types/aws/index.ts +0 -6
- package/src/lib/aws/utils/aws/index.ts +0 -41
- /package/dist/src/lib/{aws/types/aws/index.js → azure/common/types.js} +0 -0
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
## Introduction
|
|
27
27
|
|
|
28
|
-
Toolkit for working with
|
|
28
|
+
Toolkit for working with CDK Constructs ([AWS CDK][aws-cdk] & [CDK for Terraform][cdktf]).
|
|
29
29
|
|
|
30
30
|
For more details, see the full [API documentation](https://gradientedge.github.io/cdk-utils/).
|
|
31
31
|
|
|
@@ -65,6 +65,7 @@ pnpm add @gradientedge/cdk-utils
|
|
|
65
65
|
[builds]: https://img.shields.io/github/actions/workflow/status/gradientedge/cdk-utils/ci.yml?branch=main
|
|
66
66
|
[builds-url]: https://github.com/gradientedge/cdk-utils/actions
|
|
67
67
|
[cdk-badge]: https://img.shields.io/github/package-json/dependency-version/gradientedge/cdk-utils/aws-cdk-lib
|
|
68
|
+
[cdktf]: https://developer.hashicorp.com/terraform/cdktf
|
|
68
69
|
[cdk-url]: https://aws.amazon.com/cdk/
|
|
69
70
|
[checks]: https://img.shields.io/github/checks-status/gradientedge/cdk-utils/main
|
|
70
71
|
[cmd]: https://img.shields.io/badge/command--line-4D4D4D?logo=windows-terminal&style=for-the-badge
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CommonConstruct = void 0;
|
|
4
4
|
const constructs_1 = require("constructs");
|
|
5
|
+
const common_1 = require("../../common");
|
|
5
6
|
const services_1 = require("../services");
|
|
6
7
|
const utils_1 = require("../utils");
|
|
7
8
|
/**
|
|
@@ -105,29 +106,21 @@ class CommonConstruct extends constructs_1.Construct {
|
|
|
105
106
|
* @summary Utility method to determine if the initialisation is in development (dev) stage
|
|
106
107
|
* This is determined by the stage property injected via cdk context
|
|
107
108
|
*/
|
|
108
|
-
isDevelopmentStage = () => (0,
|
|
109
|
+
isDevelopmentStage = () => (0, common_1.isDevStage)(this.props.stage);
|
|
109
110
|
/**
|
|
110
111
|
* @summary Utility method to determine if the initialisation is in test (tst) stage
|
|
111
112
|
* This is determined by the stage property injected via cdk context
|
|
112
113
|
*/
|
|
113
|
-
isTestStage = () => (0,
|
|
114
|
+
isTestStage = () => (0, common_1.isTestStage)(this.props.stage);
|
|
114
115
|
/**
|
|
115
116
|
* @summary Utility method to determine if the initialisation is in uat (uat) stage
|
|
116
117
|
* This is determined by the stage property injected via cdk context
|
|
117
118
|
*/
|
|
118
|
-
isUatStage = () => (0,
|
|
119
|
+
isUatStage = () => (0, common_1.isUatStage)(this.props.stage);
|
|
119
120
|
/**
|
|
120
121
|
* @summary Utility method to determine if the initialisation is in production (prd) stage
|
|
121
122
|
* This is determined by the stage property injected via cdk context
|
|
122
123
|
*/
|
|
123
|
-
isProductionStage = () => (0,
|
|
124
|
+
isProductionStage = () => (0, common_1.isPrdStage)(this.props.stage);
|
|
124
125
|
}
|
|
125
126
|
exports.CommonConstruct = CommonConstruct;
|
|
126
|
-
const applyMixins = (derivedCtor, constructors) => {
|
|
127
|
-
constructors.forEach(baseCtor => {
|
|
128
|
-
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
|
|
129
|
-
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
exports.applyMixins = applyMixins;
|
|
@@ -7,9 +7,10 @@ exports.CommonStack = void 0;
|
|
|
7
7
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
8
8
|
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const utils_1 = require("../utils");
|
|
11
10
|
const construct_1 = require("./construct");
|
|
12
11
|
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
12
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
13
|
+
const common_1 = require("../../common");
|
|
13
14
|
/**
|
|
14
15
|
* @classdesc Common stack to use as a base for all higher level constructs.
|
|
15
16
|
* @example
|
|
@@ -69,7 +70,7 @@ class CommonStack extends aws_cdk_lib_1.Stack {
|
|
|
69
70
|
console.debug(`No additional contexts provided. Using default context properties from cdk.json`);
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
+
lodash_1.default.forEach(extraContexts, (context) => {
|
|
73
74
|
const extraContextPath = `${app_root_path_1.default.path}/${context}`;
|
|
74
75
|
/* scenario where extra context is configured in cdk.json but absent in file system */
|
|
75
76
|
if (!fs_1.default.existsSync(extraContextPath))
|
|
@@ -81,7 +82,7 @@ class CommonStack extends aws_cdk_lib_1.Stack {
|
|
|
81
82
|
/* parse as JSON properties */
|
|
82
83
|
const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'));
|
|
83
84
|
/* set each of the property into the cdk node context */
|
|
84
|
-
|
|
85
|
+
lodash_1.default.keys(extraContextProps).forEach((propKey) => {
|
|
85
86
|
this.node.setContext(propKey, extraContextProps[propKey]);
|
|
86
87
|
});
|
|
87
88
|
});
|
|
@@ -96,7 +97,7 @@ class CommonStack extends aws_cdk_lib_1.Stack {
|
|
|
96
97
|
const stageContextPath = this.node.tryGetContext('stageContextPath') || 'cdkEnv';
|
|
97
98
|
const stageContextFilePath = `${app_root_path_1.default.path}/${stageContextPath}/${stage}.json`;
|
|
98
99
|
const debug = this.node.tryGetContext('debug');
|
|
99
|
-
if ((0,
|
|
100
|
+
if ((0, common_1.isDevStage)(stage)) {
|
|
100
101
|
if (debug)
|
|
101
102
|
console.debug(`Development stage. Using default stage context properties`);
|
|
102
103
|
}
|
|
@@ -115,13 +116,10 @@ class CommonStack extends aws_cdk_lib_1.Stack {
|
|
|
115
116
|
/* parse as JSON properties */
|
|
116
117
|
const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'));
|
|
117
118
|
/* set each of the property into the cdk node context */
|
|
118
|
-
|
|
119
|
+
lodash_1.default.keys(stageContextProps).forEach((propKey) => {
|
|
119
120
|
/* handle object, array properties */
|
|
120
121
|
if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
|
|
121
|
-
this.node.setContext(propKey,
|
|
122
|
-
...this.node.tryGetContext(propKey),
|
|
123
|
-
...stageContextProps[propKey],
|
|
124
|
-
});
|
|
122
|
+
this.node.setContext(propKey, lodash_1.default.merge(this.node.tryGetContext(propKey), stageContextProps[propKey]));
|
|
125
123
|
}
|
|
126
124
|
else {
|
|
127
125
|
/* handle all other primitive properties */
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { StackProps } from 'aws-cdk-lib';
|
|
2
2
|
import { Runtime, Tracing } from 'aws-cdk-lib/aws-lambda';
|
|
3
3
|
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
|
|
4
|
+
import { BaseProps } from '../../common';
|
|
4
5
|
/**
|
|
5
6
|
*/
|
|
6
|
-
export interface CommonStackProps extends StackProps {
|
|
7
|
-
name: string;
|
|
7
|
+
export interface CommonStackProps extends BaseProps, StackProps {
|
|
8
8
|
region: string;
|
|
9
|
-
stage: string;
|
|
10
|
-
domainName: string;
|
|
11
|
-
subDomain?: string;
|
|
12
|
-
extraContexts?: string[];
|
|
13
|
-
stageContextPath?: string;
|
|
14
|
-
skipStageForARecords: boolean;
|
|
15
9
|
logRetention?: RetentionDays;
|
|
16
10
|
defaultReservedLambdaConcurrentExecutions?: number;
|
|
17
11
|
defaultTracing?: Tracing;
|
|
@@ -85,33 +85,31 @@ class ApiToAnyTarget extends common_1.CommonConstruct {
|
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
this.apiToAnyTargetRestApi.api = new aws_apigateway_1.RestApi(this, `${this.id}-rest-api`, {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
allowOrigins: aws_apigateway_1.Cors.ALL_ORIGINS,
|
|
94
|
-
},
|
|
95
|
-
defaultIntegration: this.apiToAnyTargetRestApi.integration,
|
|
96
|
-
defaultMethodOptions: {
|
|
97
|
-
methodResponses: [this.apiToAnyTargetRestApi.methodResponse, this.apiToAnyTargetRestApi.methodErrorResponse],
|
|
98
|
-
},
|
|
99
|
-
deploy: this.props.api.restApi?.deploy ?? true,
|
|
100
|
-
deployOptions: {
|
|
101
|
-
accessLogDestination: new aws_apigateway_1.LogGroupLogDestination(this.apiToAnyTargetRestApi.accessLogGroup),
|
|
102
|
-
accessLogFormat: aws_apigateway_1.AccessLogFormat.jsonWithStandardFields(),
|
|
103
|
-
dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
|
|
104
|
-
description: `${this.id} - ${this.props.stage} stage`,
|
|
105
|
-
loggingLevel: aws_apigateway_1.MethodLoggingLevel.INFO,
|
|
106
|
-
metricsEnabled: true,
|
|
107
|
-
stageName: this.props.stage,
|
|
108
|
-
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
109
|
-
},
|
|
110
|
-
endpointConfiguration: {
|
|
111
|
-
types: [this.isProductionStage() ? aws_apigateway_1.EndpointType.EDGE : aws_apigateway_1.EndpointType.REGIONAL],
|
|
112
|
-
},
|
|
113
|
-
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
88
|
+
cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
|
|
89
|
+
defaultCorsPreflightOptions: {
|
|
90
|
+
allowHeaders: aws_apigateway_1.Cors.DEFAULT_HEADERS,
|
|
91
|
+
allowMethods: aws_apigateway_1.Cors.ALL_METHODS,
|
|
92
|
+
allowOrigins: aws_apigateway_1.Cors.ALL_ORIGINS,
|
|
114
93
|
},
|
|
94
|
+
defaultIntegration: this.apiToAnyTargetRestApi.integration,
|
|
95
|
+
defaultMethodOptions: {
|
|
96
|
+
methodResponses: [this.apiToAnyTargetRestApi.methodResponse, this.apiToAnyTargetRestApi.methodErrorResponse],
|
|
97
|
+
},
|
|
98
|
+
deploy: this.props.api.restApi?.deploy ?? true,
|
|
99
|
+
deployOptions: {
|
|
100
|
+
accessLogDestination: new aws_apigateway_1.LogGroupLogDestination(this.apiToAnyTargetRestApi.accessLogGroup),
|
|
101
|
+
accessLogFormat: aws_apigateway_1.AccessLogFormat.jsonWithStandardFields(),
|
|
102
|
+
dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
|
|
103
|
+
description: `${this.id} - ${this.props.stage} stage`,
|
|
104
|
+
loggingLevel: aws_apigateway_1.MethodLoggingLevel.INFO,
|
|
105
|
+
metricsEnabled: true,
|
|
106
|
+
stageName: this.props.stage,
|
|
107
|
+
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
108
|
+
},
|
|
109
|
+
endpointConfiguration: {
|
|
110
|
+
types: [this.isProductionStage() ? aws_apigateway_1.EndpointType.EDGE : aws_apigateway_1.EndpointType.REGIONAL],
|
|
111
|
+
},
|
|
112
|
+
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
115
113
|
...this.props.api.restApi,
|
|
116
114
|
});
|
|
117
115
|
this.addCfnOutput(`${this.id}-restApiId`, this.apiToAnyTargetRestApi.api.restApiId);
|
|
@@ -133,12 +133,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
133
133
|
if (this.props.api.useExisting)
|
|
134
134
|
return;
|
|
135
135
|
this.props.event.rule = {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
source: ['api-to-eventbridge-target'],
|
|
139
|
-
},
|
|
140
|
-
ruleName: `${this.id}-api-to-eventbridge-target`,
|
|
136
|
+
eventPattern: {
|
|
137
|
+
source: ['api-to-eventbridge-target'],
|
|
141
138
|
},
|
|
139
|
+
ruleName: `${this.id}-api-to-eventbridge-target`,
|
|
142
140
|
...this.props.event.rule,
|
|
143
141
|
};
|
|
144
142
|
this.apiEvent.rule = this.eventManager.createRule(`${this.id}-api-to-eventbridge-target-rule`, this, this.props.event.rule, this.apiEvent.eventBus, [new aws_events_targets_1.CloudWatchLogGroup(this.apiEvent.logGroup)]);
|
|
@@ -199,12 +197,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
199
197
|
if (!this.props.api.withResource)
|
|
200
198
|
return;
|
|
201
199
|
this.apiToEventBridgeTargetRestApi.integrationResponse = this.props.api.integrationResponse ?? {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
205
|
-
},
|
|
206
|
-
statusCode: '200',
|
|
200
|
+
responseTemplates: {
|
|
201
|
+
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
207
202
|
},
|
|
203
|
+
statusCode: '200',
|
|
208
204
|
};
|
|
209
205
|
}
|
|
210
206
|
/**
|
|
@@ -214,21 +210,19 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
214
210
|
if (!this.props.api.withResource)
|
|
215
211
|
return;
|
|
216
212
|
this.apiToEventBridgeTargetRestApi.integrationErrorResponse = {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
'method.response.header.Content-Type': "'application/json'",
|
|
222
|
-
},
|
|
223
|
-
responseTemplates: {
|
|
224
|
-
'application/json': JSON.stringify({
|
|
225
|
-
message: "$util.escapeJavaScript($input.path('$.errorMessage'))",
|
|
226
|
-
state: 'error',
|
|
227
|
-
}),
|
|
228
|
-
},
|
|
229
|
-
selectionPattern: '^\\[Error\\].*',
|
|
230
|
-
statusCode: '400',
|
|
213
|
+
responseParameters: {
|
|
214
|
+
'method.response.header.Access-Control-Allow-Credentials': "'true'",
|
|
215
|
+
'method.response.header.Access-Control-Allow-Origin': "'*'",
|
|
216
|
+
'method.response.header.Content-Type': "'application/json'",
|
|
231
217
|
},
|
|
218
|
+
responseTemplates: {
|
|
219
|
+
'application/json': JSON.stringify({
|
|
220
|
+
message: "$util.escapeJavaScript($input.path('$.errorMessage'))",
|
|
221
|
+
state: 'error',
|
|
222
|
+
}),
|
|
223
|
+
},
|
|
224
|
+
selectionPattern: '^\\[Error\\].*',
|
|
225
|
+
statusCode: '400',
|
|
232
226
|
...this.props.api.integrationErrorResponse,
|
|
233
227
|
};
|
|
234
228
|
}
|
|
@@ -241,16 +235,14 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
241
235
|
this.apiToEventBridgeTargetRestApi.integration = new aws_apigateway_1.Integration({
|
|
242
236
|
integrationHttpMethod: 'POST',
|
|
243
237
|
options: {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
|
|
253
|
-
},
|
|
238
|
+
credentialsRole: this.apiToEventBridgeTargetRestApi.role,
|
|
239
|
+
integrationResponses: [
|
|
240
|
+
this.apiToEventBridgeTargetRestApi.integrationResponse,
|
|
241
|
+
this.apiToEventBridgeTargetRestApi.integrationErrorResponse,
|
|
242
|
+
],
|
|
243
|
+
passthroughBehavior: aws_apigateway_1.PassthroughBehavior.NEVER,
|
|
244
|
+
requestParameters: this.apiToEventBridgeTargetRestApi.integrationRequestParameters,
|
|
245
|
+
requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
|
|
254
246
|
...this.props.api.integrationOptions,
|
|
255
247
|
},
|
|
256
248
|
type: aws_apigateway_1.IntegrationType.AWS,
|
|
@@ -264,17 +256,15 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
264
256
|
if (!this.props.api.withResource)
|
|
265
257
|
return;
|
|
266
258
|
this.apiToEventBridgeTargetRestApi.methodResponse = {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
'method.response.header.Content-Type': true,
|
|
275
|
-
},
|
|
276
|
-
statusCode: '200',
|
|
259
|
+
responseModels: {
|
|
260
|
+
'application/json': this.apiToEventBridgeTargetRestApi.responseModel,
|
|
261
|
+
},
|
|
262
|
+
responseParameters: {
|
|
263
|
+
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
264
|
+
'method.response.header.Access-Control-Allow-Origin': true,
|
|
265
|
+
'method.response.header.Content-Type': true,
|
|
277
266
|
},
|
|
267
|
+
statusCode: '200',
|
|
278
268
|
...this.props.api.methodResponse,
|
|
279
269
|
};
|
|
280
270
|
}
|
|
@@ -285,17 +275,15 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
285
275
|
if (!this.props.api.withResource)
|
|
286
276
|
return;
|
|
287
277
|
this.apiToEventBridgeTargetRestApi.methodErrorResponse = {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
|
|
291
|
-
},
|
|
292
|
-
responseParameters: {
|
|
293
|
-
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
294
|
-
'method.response.header.Access-Control-Allow-Origin': true,
|
|
295
|
-
'method.response.header.Content-Type': true,
|
|
296
|
-
},
|
|
297
|
-
statusCode: '400',
|
|
278
|
+
responseModels: {
|
|
279
|
+
'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
|
|
298
280
|
},
|
|
281
|
+
responseParameters: {
|
|
282
|
+
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
283
|
+
'method.response.header.Access-Control-Allow-Origin': true,
|
|
284
|
+
'method.response.header.Content-Type': true,
|
|
285
|
+
},
|
|
286
|
+
statusCode: '400',
|
|
299
287
|
...this.props.api.methodErrorResponse,
|
|
300
288
|
};
|
|
301
289
|
}
|
|
@@ -314,36 +302,34 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
314
302
|
return;
|
|
315
303
|
}
|
|
316
304
|
this.apiToEventBridgeTargetRestApi.api = new aws_apigateway_1.RestApi(this, `${this.id}-rest-api`, {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
types: [aws_apigateway_1.EndpointType.REGIONAL],
|
|
344
|
-
},
|
|
345
|
-
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
305
|
+
cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
|
|
306
|
+
defaultCorsPreflightOptions: {
|
|
307
|
+
allowHeaders: aws_apigateway_1.Cors.DEFAULT_HEADERS,
|
|
308
|
+
allowMethods: ['POST'],
|
|
309
|
+
allowOrigins: aws_apigateway_1.Cors.ALL_ORIGINS,
|
|
310
|
+
},
|
|
311
|
+
defaultIntegration: this.apiToEventBridgeTargetRestApi.integration,
|
|
312
|
+
defaultMethodOptions: {
|
|
313
|
+
methodResponses: [
|
|
314
|
+
this.apiToEventBridgeTargetRestApi.methodResponse,
|
|
315
|
+
this.apiToEventBridgeTargetRestApi.methodErrorResponse,
|
|
316
|
+
],
|
|
317
|
+
},
|
|
318
|
+
deploy: this.props.api.restApi?.deploy ?? true,
|
|
319
|
+
deployOptions: {
|
|
320
|
+
accessLogDestination: new aws_apigateway_1.LogGroupLogDestination(this.apiToEventBridgeTargetRestApi.accessLogGroup),
|
|
321
|
+
accessLogFormat: aws_apigateway_1.AccessLogFormat.jsonWithStandardFields(),
|
|
322
|
+
dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
|
|
323
|
+
description: `${this.id} - ${this.props.stage} stage`,
|
|
324
|
+
loggingLevel: aws_apigateway_1.MethodLoggingLevel.INFO,
|
|
325
|
+
metricsEnabled: true,
|
|
326
|
+
stageName: this.props.stage,
|
|
327
|
+
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
328
|
+
},
|
|
329
|
+
endpointConfiguration: {
|
|
330
|
+
types: [aws_apigateway_1.EndpointType.REGIONAL],
|
|
346
331
|
},
|
|
332
|
+
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
347
333
|
...this.props.api.restApi,
|
|
348
334
|
});
|
|
349
335
|
this.addCfnOutput(`${this.id}-restApiId`, this.apiToEventBridgeTargetRestApi.api.restApiId);
|
|
@@ -357,15 +343,13 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
357
343
|
return;
|
|
358
344
|
this.apiToEventBridgeTargetRestApi.responseModel = new aws_apigateway_1.Model(this, `${this.id}-response-model`, {
|
|
359
345
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
type: aws_apigateway_1.JsonSchemaType.OBJECT,
|
|
368
|
-
},
|
|
346
|
+
contentType: 'application/json',
|
|
347
|
+
modelName: 'ResponseModel',
|
|
348
|
+
schema: {
|
|
349
|
+
properties: { message: { type: aws_apigateway_1.JsonSchemaType.STRING } },
|
|
350
|
+
schema: aws_apigateway_1.JsonSchemaVersion.DRAFT4,
|
|
351
|
+
title: 'pollResponse',
|
|
352
|
+
type: aws_apigateway_1.JsonSchemaType.OBJECT,
|
|
369
353
|
},
|
|
370
354
|
...this.props.api.responseModel,
|
|
371
355
|
});
|
|
@@ -378,18 +362,16 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
378
362
|
return;
|
|
379
363
|
this.apiToEventBridgeTargetRestApi.errorResponseModel = new aws_apigateway_1.Model(this, `${this.id}-error-response-model`, {
|
|
380
364
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
state: { type: aws_apigateway_1.JsonSchemaType.STRING },
|
|
388
|
-
},
|
|
389
|
-
schema: aws_apigateway_1.JsonSchemaVersion.DRAFT4,
|
|
390
|
-
title: 'errorResponse',
|
|
391
|
-
type: aws_apigateway_1.JsonSchemaType.OBJECT,
|
|
365
|
+
contentType: 'application/json',
|
|
366
|
+
modelName: 'ErrorResponseModel',
|
|
367
|
+
schema: {
|
|
368
|
+
properties: {
|
|
369
|
+
message: { type: aws_apigateway_1.JsonSchemaType.STRING },
|
|
370
|
+
state: { type: aws_apigateway_1.JsonSchemaType.STRING },
|
|
392
371
|
},
|
|
372
|
+
schema: aws_apigateway_1.JsonSchemaVersion.DRAFT4,
|
|
373
|
+
title: 'errorResponse',
|
|
374
|
+
type: aws_apigateway_1.JsonSchemaType.OBJECT,
|
|
393
375
|
},
|
|
394
376
|
...this.props.api.errorResponseModel,
|
|
395
377
|
});
|