@aws-amplify/graphql-model-transformer 1.4.0 → 1.5.0-no-internal-synth.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/CHANGELOG.md +10 -0
- package/lib/rds-lambda.zip +0 -0
- package/lib/rds-notification-lambda.zip +0 -0
- package/lib/rds-patching-lambda.zip +0 -0
- package/lib/resolvers/rds/resolver.d.ts +5 -5
- package/lib/resolvers/rds/resolver.d.ts.map +1 -1
- package/lib/resolvers/rds/resolver.js +14 -11
- package/lib/resolvers/rds/resolver.js.map +1 -1
- package/lib/resources/dynamo-model-resource-generator.d.ts +2 -2
- package/lib/resources/dynamo-model-resource-generator.d.ts.map +1 -1
- package/lib/resources/dynamo-model-resource-generator.js +48 -43
- package/lib/resources/dynamo-model-resource-generator.js.map +1 -1
- package/lib/resources/model-resource-generator.js +3 -3
- package/lib/resources/model-resource-generator.js.map +1 -1
- package/lib/resources/rds-model-resource-generator.js +13 -13
- package/package.json +7 -6
- package/publish-notification-lambda/node_modules/.package-lock.json +13 -13
- package/publish-notification-lambda/node_modules/@smithy/protocol-http/package.json +2 -2
- package/publish-notification-lambda/node_modules/@smithy/types/README.md +37 -0
- package/publish-notification-lambda/node_modules/@smithy/types/package.json +3 -2
- package/publish-notification-lambda/node_modules/@types/node/README.md +2 -2
- package/publish-notification-lambda/node_modules/@types/node/package.json +2 -7
- package/publish-notification-lambda/node_modules/tslib/package.json +1 -1
- package/publish-notification-lambda/node_modules/tslib/tslib.es6.mjs +1 -1
- package/publish-notification-lambda/package-lock.json +13 -13
- package/rds-lambda/node_modules/.package-lock.json +370 -345
- package/rds-lambda/node_modules/@babel/code-frame/README.md +1 -1
- package/rds-lambda/node_modules/@babel/code-frame/package.json +3 -2
- package/rds-lambda/node_modules/@babel/core/cjs-proxy.cjs +3 -1
- package/rds-lambda/node_modules/@babel/core/package.json +10 -10
- package/rds-lambda/node_modules/@babel/generator/package.json +3 -3
- package/rds-lambda/node_modules/@babel/helper-compilation-targets/package.json +1 -5
- package/rds-lambda/node_modules/@babel/helpers/package.json +6 -6
- package/rds-lambda/node_modules/@babel/highlight/README.md +1 -1
- package/rds-lambda/node_modules/@babel/highlight/package.json +2 -3
- package/rds-lambda/node_modules/@babel/parser/package.json +3 -3
- package/rds-lambda/node_modules/@babel/traverse/package.json +6 -5
- package/rds-lambda/node_modules/@babel/types/README.md +1 -1
- package/rds-lambda/node_modules/@babel/types/package.json +3 -4
- package/rds-lambda/node_modules/@jest/console/package.json +5 -5
- package/rds-lambda/node_modules/@jest/core/package.json +20 -20
- package/rds-lambda/node_modules/@jest/environment/package.json +4 -4
- package/rds-lambda/node_modules/@jest/expect/package.json +4 -4
- package/rds-lambda/node_modules/@jest/expect-utils/package.json +3 -3
- package/rds-lambda/node_modules/@jest/fake-timers/package.json +6 -6
- package/rds-lambda/node_modules/@jest/globals/package.json +5 -5
- package/rds-lambda/node_modules/@jest/reporters/package.json +10 -10
- package/rds-lambda/node_modules/@jest/test-result/package.json +5 -5
- package/rds-lambda/node_modules/@jest/test-sequencer/package.json +5 -5
- package/rds-lambda/node_modules/@jest/transform/package.json +6 -6
- package/rds-lambda/node_modules/@jridgewell/resolve-uri/package.json +2 -2
- package/rds-lambda/node_modules/@jridgewell/trace-mapping/package.json +3 -3
- package/rds-lambda/node_modules/@smithy/protocol-http/package.json +2 -2
- package/rds-lambda/node_modules/@smithy/types/README.md +37 -0
- package/rds-lambda/node_modules/@smithy/types/package.json +3 -2
- package/rds-lambda/node_modules/@types/node/README.md +2 -2
- package/rds-lambda/node_modules/@types/node/package.json +2 -7
- package/rds-lambda/node_modules/babel-jest/package.json +4 -4
- package/rds-lambda/node_modules/browserslist/package.json +4 -4
- package/rds-lambda/node_modules/caniuse-lite/package.json +1 -1
- package/rds-lambda/node_modules/dedent/README.md +56 -0
- package/rds-lambda/node_modules/dedent/dist/dedent.d.mts +17 -0
- package/rds-lambda/node_modules/dedent/dist/dedent.mjs +59 -0
- package/rds-lambda/node_modules/dedent/package.json +54 -10
- package/rds-lambda/node_modules/electron-to-chromium/full-chromium-versions.json +1 -1
- package/rds-lambda/node_modules/electron-to-chromium/full-versions.json +1 -1
- package/rds-lambda/node_modules/electron-to-chromium/package.json +1 -1
- package/rds-lambda/node_modules/electron-to-chromium/versions.json +1 -1
- package/rds-lambda/node_modules/expect/package.json +7 -7
- package/rds-lambda/node_modules/is-core-module/CHANGELOG.md +7 -0
- package/rds-lambda/node_modules/is-core-module/core.json +3 -3
- package/rds-lambda/node_modules/is-core-module/package.json +5 -5
- package/rds-lambda/node_modules/istanbul-lib-report/CHANGELOG.md +7 -0
- package/rds-lambda/node_modules/istanbul-lib-report/package.json +5 -6
- package/rds-lambda/node_modules/istanbul-reports/CHANGELOG.md +7 -0
- package/rds-lambda/node_modules/istanbul-reports/package.json +1 -1
- package/rds-lambda/node_modules/jest/package.json +4 -4
- package/rds-lambda/node_modules/jest-circus/package.json +13 -14
- package/rds-lambda/node_modules/jest-cli/package.json +7 -7
- package/rds-lambda/node_modules/jest-config/package.json +11 -11
- package/rds-lambda/node_modules/jest-diff/package.json +4 -4
- package/rds-lambda/node_modules/jest-each/package.json +4 -4
- package/rds-lambda/node_modules/jest-environment-node/package.json +7 -7
- package/rds-lambda/node_modules/jest-haste-map/package.json +4 -4
- package/rds-lambda/node_modules/jest-leak-detector/package.json +3 -3
- package/rds-lambda/node_modules/jest-matcher-utils/package.json +5 -5
- package/rds-lambda/node_modules/jest-message-util/package.json +3 -3
- package/rds-lambda/node_modules/jest-mock/package.json +3 -3
- package/rds-lambda/node_modules/jest-resolve/package.json +5 -5
- package/rds-lambda/node_modules/jest-resolve-dependencies/package.json +7 -7
- package/rds-lambda/node_modules/jest-runner/package.json +17 -17
- package/rds-lambda/node_modules/jest-runtime/package.json +15 -15
- package/rds-lambda/node_modules/jest-snapshot/package.json +12 -12
- package/rds-lambda/node_modules/jest-util/package.json +2 -2
- package/rds-lambda/node_modules/jest-validate/package.json +3 -3
- package/rds-lambda/node_modules/jest-watcher/package.json +4 -4
- package/rds-lambda/node_modules/jest-worker/package.json +4 -4
- package/rds-lambda/node_modules/make-dir/license +1 -1
- package/rds-lambda/node_modules/make-dir/node_modules/lru-cache/LICENSE +15 -0
- package/rds-lambda/node_modules/make-dir/node_modules/lru-cache/README.md +166 -0
- package/rds-lambda/node_modules/make-dir/node_modules/lru-cache/package.json +34 -0
- package/rds-lambda/node_modules/make-dir/node_modules/semver/LICENSE +15 -0
- package/rds-lambda/node_modules/make-dir/node_modules/semver/README.md +637 -0
- package/rds-lambda/node_modules/make-dir/node_modules/semver/package.json +87 -0
- package/rds-lambda/node_modules/make-dir/node_modules/semver/range.bnf +16 -0
- package/rds-lambda/node_modules/make-dir/node_modules/yallist/LICENSE +15 -0
- package/rds-lambda/node_modules/make-dir/node_modules/yallist/README.md +204 -0
- package/rds-lambda/node_modules/make-dir/node_modules/yallist/package.json +29 -0
- package/rds-lambda/node_modules/make-dir/package.json +15 -11
- package/rds-lambda/node_modules/make-dir/readme.md +1 -1
- package/rds-lambda/node_modules/pretty-format/package.json +3 -3
- package/rds-lambda/node_modules/resolve/lib/core.json +4 -1
- package/rds-lambda/node_modules/resolve/package.json +6 -6
- package/rds-lambda/node_modules/tslib/package.json +1 -1
- package/rds-lambda/node_modules/tslib/tslib.es6.mjs +1 -1
- package/rds-lambda/package-lock.json +370 -345
- package/rds-patching-lambda/node_modules/.package-lock.json +13 -13
- package/rds-patching-lambda/node_modules/@smithy/protocol-http/package.json +2 -2
- package/rds-patching-lambda/node_modules/@smithy/types/README.md +37 -0
- package/rds-patching-lambda/node_modules/@smithy/types/package.json +3 -2
- package/rds-patching-lambda/node_modules/@types/node/README.md +2 -2
- package/rds-patching-lambda/node_modules/@types/node/package.json +2 -7
- package/rds-patching-lambda/node_modules/tslib/package.json +1 -1
- package/rds-patching-lambda/node_modules/tslib/tslib.es6.mjs +1 -1
- package/rds-patching-lambda/package-lock.json +13 -13
- package/src/__tests__/model-directive-arguments.test.ts +23 -28
- package/src/__tests__/model-transformer.test.ts +138 -160
- package/src/resolvers/rds/resolver.ts +19 -17
- package/src/resources/dynamo-model-resource-generator.ts +50 -47
- package/src/resources/model-resource-generator.ts +3 -3
- package/src/resources/rds-model-resource-generator.ts +13 -13
- package/tsconfig.tsbuildinfo +1 -1
- package/rds-lambda/node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec/LICENSE +0 -21
- package/rds-lambda/node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec/README.md +0 -200
- package/rds-lambda/node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +0 -164
- package/rds-lambda/node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs.map +0 -1
- package/rds-lambda/node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec/package.json +0 -75
- package/rds-lambda/node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec/src/sourcemap-codec.ts +0 -198
- package/rds-lambda/node_modules/@types/prettier/LICENSE +0 -21
- package/rds-lambda/node_modules/@types/prettier/README.md +0 -16
- package/rds-lambda/node_modules/@types/prettier/package.json +0 -65
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CfnMapping, Duration, Fn
|
|
1
|
+
import { CfnMapping, Duration, Fn } from 'aws-cdk-lib';
|
|
2
2
|
import {
|
|
3
3
|
Expression,
|
|
4
4
|
compoundExpression,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
toJson,
|
|
15
15
|
} from 'graphql-mapping-template';
|
|
16
16
|
import { ResourceConstants } from 'graphql-transformer-common';
|
|
17
|
-
import { RDSConnectionSecrets } from '@aws-amplify/graphql-transformer-core';
|
|
17
|
+
import { RDSConnectionSecrets, setResourceName } from '@aws-amplify/graphql-transformer-core';
|
|
18
18
|
import { GraphQLAPIProvider, RDSLayerMapping } from '@aws-amplify/graphql-transformer-interfaces';
|
|
19
19
|
import { Effect, IRole, Policy, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
|
|
20
20
|
import { IFunction, LayerVersion, Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
@@ -124,12 +124,12 @@ const getDefaultLayerMapping = (): RDSLayerMapping => ({
|
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* Create RDS Lambda function
|
|
127
|
-
* @param
|
|
127
|
+
* @param scope Construct
|
|
128
128
|
* @param apiGraphql GraphQLAPIProvider
|
|
129
129
|
* @param lambdaRole IRole
|
|
130
130
|
*/
|
|
131
131
|
export const createRdsLambda = (
|
|
132
|
-
|
|
132
|
+
scope: Construct,
|
|
133
133
|
apiGraphql: GraphQLAPIProvider,
|
|
134
134
|
lambdaRole: IRole,
|
|
135
135
|
environment?: { [key: string]: string },
|
|
@@ -144,7 +144,7 @@ export const createRdsLambda = (
|
|
|
144
144
|
Runtime.NODEJS_18_X,
|
|
145
145
|
[
|
|
146
146
|
LayerVersion.fromLayerVersionArn(
|
|
147
|
-
|
|
147
|
+
scope,
|
|
148
148
|
'SQLLambdaLayerVersion',
|
|
149
149
|
Fn.findInMap(RDSLayerMappingID, Fn.ref('AWS::Region'), 'layerRegion'),
|
|
150
150
|
),
|
|
@@ -152,19 +152,19 @@ export const createRdsLambda = (
|
|
|
152
152
|
lambdaRole,
|
|
153
153
|
environment,
|
|
154
154
|
Duration.seconds(30),
|
|
155
|
-
|
|
155
|
+
scope,
|
|
156
156
|
sqlLambdaVpcConfig,
|
|
157
157
|
);
|
|
158
158
|
};
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
161
|
* Create RDS Patching Lambda function
|
|
162
|
-
* @param
|
|
162
|
+
* @param scope Construct
|
|
163
163
|
* @param apiGraphql GraphQLAPIProvider
|
|
164
164
|
* @param lambdaRole IRole
|
|
165
165
|
*/
|
|
166
166
|
export const createRdsPatchingLambda = (
|
|
167
|
-
|
|
167
|
+
scope: Construct,
|
|
168
168
|
apiGraphql: GraphQLAPIProvider,
|
|
169
169
|
lambdaRole: IRole,
|
|
170
170
|
environment?: { [key: string]: string },
|
|
@@ -181,7 +181,7 @@ export const createRdsPatchingLambda = (
|
|
|
181
181
|
lambdaRole,
|
|
182
182
|
environment,
|
|
183
183
|
Duration.minutes(6), // We have an arbituary wait time of up to 5 minutes in the lambda function to avoid throttling errors
|
|
184
|
-
|
|
184
|
+
scope,
|
|
185
185
|
sqlLambdaVpcConfig,
|
|
186
186
|
);
|
|
187
187
|
};
|
|
@@ -189,15 +189,16 @@ export const createRdsPatchingLambda = (
|
|
|
189
189
|
/**
|
|
190
190
|
* Create RDS Lambda IAM role
|
|
191
191
|
* @param roleName string
|
|
192
|
-
* @param
|
|
192
|
+
* @param scope Construct
|
|
193
193
|
* @param secretEntry RDSConnectionSecrets
|
|
194
194
|
*/
|
|
195
|
-
export const createRdsLambdaRole = (roleName: string,
|
|
195
|
+
export const createRdsLambdaRole = (roleName: string, scope: Construct, secretEntry: RDSConnectionSecrets): IRole => {
|
|
196
196
|
const { RDSLambdaIAMRoleLogicalID, RDSLambdaLogAccessPolicy } = ResourceConstants.RESOURCES;
|
|
197
|
-
const role = new Role(
|
|
197
|
+
const role = new Role(scope, RDSLambdaIAMRoleLogicalID, {
|
|
198
198
|
assumedBy: new ServicePrincipal('lambda.amazonaws.com'),
|
|
199
199
|
roleName,
|
|
200
200
|
});
|
|
201
|
+
setResourceName(role, { name: RDSLambdaIAMRoleLogicalID, setOnDefaultChild: true });
|
|
201
202
|
const policyStatements = [
|
|
202
203
|
new PolicyStatement({
|
|
203
204
|
actions: ['logs:CreateLogGroup', 'logs:CreateLogStream', 'logs:PutLogEvents'],
|
|
@@ -222,7 +223,7 @@ export const createRdsLambdaRole = (roleName: string, stack: Construct, secretEn
|
|
|
222
223
|
}
|
|
223
224
|
|
|
224
225
|
role.attachInlinePolicy(
|
|
225
|
-
new Policy(
|
|
226
|
+
new Policy(scope, RDSLambdaLogAccessPolicy, {
|
|
226
227
|
statements: policyStatements,
|
|
227
228
|
policyName: `${roleName}Policy`,
|
|
228
229
|
}),
|
|
@@ -242,15 +243,16 @@ export const createRdsLambdaRole = (roleName: string, stack: Construct, secretEn
|
|
|
242
243
|
/**
|
|
243
244
|
* Create RDS Patching Lambda IAM role
|
|
244
245
|
* @param roleName string
|
|
245
|
-
* @param
|
|
246
|
+
* @param scope Construct
|
|
246
247
|
* @param functionArn FunctionArn
|
|
247
248
|
*/
|
|
248
|
-
export const createRdsPatchingLambdaRole = (roleName: string,
|
|
249
|
+
export const createRdsPatchingLambdaRole = (roleName: string, scope: Construct, functionArn: string): IRole => {
|
|
249
250
|
const { RDSPatchingLambdaIAMRoleLogicalID, RDSPatchingLambdaLogAccessPolicy } = ResourceConstants.RESOURCES;
|
|
250
|
-
const role = new Role(
|
|
251
|
+
const role = new Role(scope, RDSPatchingLambdaIAMRoleLogicalID, {
|
|
251
252
|
assumedBy: new ServicePrincipal('lambda.amazonaws.com'),
|
|
252
253
|
roleName,
|
|
253
254
|
});
|
|
255
|
+
setResourceName(role, { name: RDSPatchingLambdaIAMRoleLogicalID, setOnDefaultChild: true });
|
|
254
256
|
const policyStatements = [
|
|
255
257
|
new PolicyStatement({
|
|
256
258
|
actions: ['logs:CreateLogGroup', 'logs:CreateLogStream', 'logs:PutLogEvents'],
|
|
@@ -270,7 +272,7 @@ export const createRdsPatchingLambdaRole = (roleName: string, stack: Construct,
|
|
|
270
272
|
];
|
|
271
273
|
|
|
272
274
|
role.attachInlinePolicy(
|
|
273
|
-
new Policy(
|
|
275
|
+
new Policy(scope, RDSPatchingLambdaLogAccessPolicy, {
|
|
274
276
|
statements: policyStatements,
|
|
275
277
|
policyName: `${roleName}Policy`,
|
|
276
278
|
}),
|
|
@@ -2,11 +2,12 @@ import * as cdk from 'aws-cdk-lib';
|
|
|
2
2
|
import { TransformerContextProvider } from '@aws-amplify/graphql-transformer-interfaces';
|
|
3
3
|
import { ModelResourceIDs, ResourceConstants, SyncResourceIDs } from 'graphql-transformer-common';
|
|
4
4
|
import { ObjectTypeDefinitionNode } from 'graphql';
|
|
5
|
-
import { SyncUtils,
|
|
5
|
+
import { SyncUtils, setResourceName } from '@aws-amplify/graphql-transformer-core';
|
|
6
6
|
import { AttributeType, CfnTable, StreamViewType, Table, TableEncryption } from 'aws-cdk-lib/aws-dynamodb';
|
|
7
7
|
import { CfnDataSource } from 'aws-cdk-lib/aws-appsync';
|
|
8
8
|
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
9
9
|
import { CfnRole } from 'aws-cdk-lib/aws-iam';
|
|
10
|
+
import { Construct } from 'constructs';
|
|
10
11
|
import { DynamoDBModelVTLGenerator, ModelVTLGenerator } from '../resolvers';
|
|
11
12
|
import { ModelResourceGenerator } from './model-resource-generator';
|
|
12
13
|
|
|
@@ -24,28 +25,29 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
|
|
|
24
25
|
|
|
25
26
|
if (this.isProvisioned()) {
|
|
26
27
|
// add model related-parameters to the root stack
|
|
27
|
-
|
|
28
|
+
const rootStack = cdk.Stack.of(ctx.stackManager.scope);
|
|
29
|
+
new cdk.CfnParameter(rootStack, ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS, {
|
|
28
30
|
description: 'The number of read IOPS the table should support.',
|
|
29
31
|
type: 'Number',
|
|
30
32
|
default: 5,
|
|
31
33
|
});
|
|
32
|
-
|
|
34
|
+
new cdk.CfnParameter(rootStack, ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS, {
|
|
33
35
|
description: 'The number of write IOPS the table should support.',
|
|
34
36
|
type: 'Number',
|
|
35
37
|
default: 5,
|
|
36
38
|
});
|
|
37
|
-
|
|
39
|
+
new cdk.CfnParameter(rootStack, ResourceConstants.PARAMETERS.DynamoDBBillingMode, {
|
|
38
40
|
description: 'Configure @model types to create DynamoDB tables with PAY_PER_REQUEST or PROVISIONED billing modes.',
|
|
39
41
|
default: 'PAY_PER_REQUEST',
|
|
40
42
|
allowedValues: ['PAY_PER_REQUEST', 'PROVISIONED'],
|
|
41
43
|
});
|
|
42
|
-
|
|
44
|
+
new cdk.CfnParameter(rootStack, ResourceConstants.PARAMETERS.DynamoDBEnablePointInTimeRecovery, {
|
|
43
45
|
description: 'Whether to enable Point in Time Recovery on the table.',
|
|
44
46
|
type: 'String',
|
|
45
47
|
default: 'false',
|
|
46
48
|
allowedValues: ['true', 'false'],
|
|
47
49
|
});
|
|
48
|
-
|
|
50
|
+
new cdk.CfnParameter(rootStack, ResourceConstants.PARAMETERS.DynamoDBEnableServerSideEncryption, {
|
|
49
51
|
description: 'Enable server side encryption powered by KMS.',
|
|
50
52
|
type: 'String',
|
|
51
53
|
default: 'true',
|
|
@@ -57,9 +59,9 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
|
|
|
57
59
|
// This name is used by the mock functionality. Changing this can break mock.
|
|
58
60
|
const tableBaseName = ctx.resourceHelper.getModelNameMapping(model!.name.value);
|
|
59
61
|
const tableLogicalName = ModelResourceIDs.ModelTableResourceID(tableBaseName);
|
|
60
|
-
const
|
|
62
|
+
const scope = ctx.stackManager.getScopeFor(tableLogicalName, tableBaseName);
|
|
61
63
|
|
|
62
|
-
this.createModelTable(
|
|
64
|
+
this.createModelTable(scope, model, ctx);
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
this.generateResolvers(ctx);
|
|
@@ -70,71 +72,68 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
|
|
|
70
72
|
return new DynamoDBModelVTLGenerator();
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
private createModelTable(
|
|
74
|
-
const
|
|
75
|
-
const
|
|
75
|
+
private createModelTable(scope: Construct, def: ObjectTypeDefinitionNode, context: TransformerContextProvider): void {
|
|
76
|
+
const modelName = def!.name.value;
|
|
77
|
+
const tableLogicalName = ModelResourceIDs.ModelTableResourceID(modelName);
|
|
78
|
+
const tableName = context.resourceHelper.generateTableName(modelName);
|
|
76
79
|
|
|
77
80
|
// Add parameters.
|
|
78
|
-
const
|
|
79
|
-
const readIops = new cdk.CfnParameter(stack, ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS, {
|
|
81
|
+
const readIops = new cdk.CfnParameter(scope, ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS, {
|
|
80
82
|
description: 'The number of read IOPS the table should support.',
|
|
81
83
|
type: 'Number',
|
|
82
84
|
default: 5,
|
|
83
85
|
});
|
|
84
|
-
const writeIops = new cdk.CfnParameter(
|
|
86
|
+
const writeIops = new cdk.CfnParameter(scope, ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS, {
|
|
85
87
|
description: 'The number of write IOPS the table should support.',
|
|
86
88
|
type: 'Number',
|
|
87
89
|
default: 5,
|
|
88
90
|
});
|
|
89
|
-
const billingMode = new cdk.CfnParameter(
|
|
91
|
+
const billingMode = new cdk.CfnParameter(scope, ResourceConstants.PARAMETERS.DynamoDBBillingMode, {
|
|
90
92
|
description: 'Configure @model types to create DynamoDB tables with PAY_PER_REQUEST or PROVISIONED billing modes.',
|
|
91
93
|
type: 'String',
|
|
92
94
|
default: 'PAY_PER_REQUEST',
|
|
93
95
|
allowedValues: ['PAY_PER_REQUEST', 'PROVISIONED'],
|
|
94
96
|
});
|
|
95
|
-
const pointInTimeRecovery = new cdk.CfnParameter(
|
|
97
|
+
const pointInTimeRecovery = new cdk.CfnParameter(scope, ResourceConstants.PARAMETERS.DynamoDBEnablePointInTimeRecovery, {
|
|
96
98
|
description: 'Whether to enable Point in Time Recovery on the table.',
|
|
97
99
|
type: 'String',
|
|
98
100
|
default: 'false',
|
|
99
101
|
allowedValues: ['true', 'false'],
|
|
100
102
|
});
|
|
101
|
-
const enableSSE = new cdk.CfnParameter(
|
|
103
|
+
const enableSSE = new cdk.CfnParameter(scope, ResourceConstants.PARAMETERS.DynamoDBEnableServerSideEncryption, {
|
|
102
104
|
description: 'Enable server side encryption powered by KMS.',
|
|
103
105
|
type: 'String',
|
|
104
106
|
default: 'true',
|
|
105
107
|
allowedValues: ['true', 'false'],
|
|
106
108
|
});
|
|
107
109
|
// add the connection between the root and nested stack so the values can be passed down
|
|
108
|
-
(
|
|
109
|
-
(
|
|
110
|
-
(
|
|
111
|
-
(
|
|
110
|
+
(scope as cdk.NestedStack).setParameter(readIops.node.id, cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS));
|
|
111
|
+
(scope as cdk.NestedStack).setParameter(writeIops.node.id, cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS));
|
|
112
|
+
(scope as cdk.NestedStack).setParameter(billingMode.node.id, cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBBillingMode));
|
|
113
|
+
(scope as cdk.NestedStack).setParameter(
|
|
112
114
|
pointInTimeRecovery.node.id,
|
|
113
115
|
cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBEnablePointInTimeRecovery),
|
|
114
116
|
);
|
|
115
|
-
(
|
|
116
|
-
enableSSE.node.id,
|
|
117
|
-
cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBEnableServerSideEncryption),
|
|
118
|
-
);
|
|
117
|
+
(scope as cdk.NestedStack).setParameter(enableSSE.node.id, cdk.Fn.ref(ResourceConstants.PARAMETERS.DynamoDBEnableServerSideEncryption));
|
|
119
118
|
|
|
120
119
|
// Add conditions.
|
|
121
|
-
new cdk.CfnCondition(
|
|
122
|
-
expression: cdk.Fn.conditionNot(cdk.Fn.conditionEquals(
|
|
120
|
+
new cdk.CfnCondition(scope, ResourceConstants.CONDITIONS.HasEnvironmentParameter, {
|
|
121
|
+
expression: cdk.Fn.conditionNot(cdk.Fn.conditionEquals(context.synthParameters.amplifyEnvironmentName, ResourceConstants.NONE)),
|
|
123
122
|
});
|
|
124
|
-
const useSSE = new cdk.CfnCondition(
|
|
123
|
+
const useSSE = new cdk.CfnCondition(scope, ResourceConstants.CONDITIONS.ShouldUseServerSideEncryption, {
|
|
125
124
|
expression: cdk.Fn.conditionEquals(enableSSE, 'true'),
|
|
126
125
|
});
|
|
127
|
-
const usePayPerRequestBilling = new cdk.CfnCondition(
|
|
126
|
+
const usePayPerRequestBilling = new cdk.CfnCondition(scope, ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling, {
|
|
128
127
|
expression: cdk.Fn.conditionEquals(billingMode, 'PAY_PER_REQUEST'),
|
|
129
128
|
});
|
|
130
|
-
const usePointInTimeRecovery = new cdk.CfnCondition(
|
|
129
|
+
const usePointInTimeRecovery = new cdk.CfnCondition(scope, ResourceConstants.CONDITIONS.ShouldUsePointInTimeRecovery, {
|
|
131
130
|
expression: cdk.Fn.conditionEquals(pointInTimeRecovery, 'true'),
|
|
132
131
|
});
|
|
133
132
|
|
|
134
133
|
const removalPolicy = this.options.EnableDeletionProtection ? cdk.RemovalPolicy.RETAIN : cdk.RemovalPolicy.DESTROY;
|
|
135
134
|
|
|
136
135
|
// Expose a way in context to allow proper resource naming
|
|
137
|
-
const table = new Table(
|
|
136
|
+
const table = new Table(scope, tableLogicalName, {
|
|
138
137
|
tableName,
|
|
139
138
|
partitionKey: {
|
|
140
139
|
name: 'id',
|
|
@@ -146,6 +145,7 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
|
|
|
146
145
|
...(context.isProjectUsingDataStore() ? { timeToLiveAttribute: '_ttl' } : undefined),
|
|
147
146
|
});
|
|
148
147
|
const cfnTable = table.node.defaultChild as CfnTable;
|
|
148
|
+
setResourceName(table, { name: modelName, setOnDefaultChild: true });
|
|
149
149
|
|
|
150
150
|
cfnTable.provisionedThroughput = cdk.Fn.conditionIf(usePayPerRequestBilling.logicalId, cdk.Fn.ref('AWS::NoValue'), {
|
|
151
151
|
ReadCapacityUnits: readIops,
|
|
@@ -162,29 +162,31 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
|
|
|
162
162
|
};
|
|
163
163
|
|
|
164
164
|
const streamArnOutputId = `GetAtt${ModelResourceIDs.ModelTableStreamArn(def!.name.value)}`;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
if (table.tableStreamArn) {
|
|
166
|
+
new cdk.CfnOutput(cdk.Stack.of(scope), streamArnOutputId, {
|
|
167
|
+
value: table.tableStreamArn,
|
|
168
|
+
description: 'Your DynamoDB table StreamArn.',
|
|
169
|
+
exportName: cdk.Fn.join(':', [context.api.apiId, 'GetAtt', tableLogicalName, 'StreamArn']),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
170
172
|
|
|
171
173
|
const tableNameOutputId = `GetAtt${tableLogicalName}Name`;
|
|
172
|
-
new cdk.CfnOutput(
|
|
173
|
-
value:
|
|
174
|
+
new cdk.CfnOutput(cdk.Stack.of(scope), tableNameOutputId, {
|
|
175
|
+
value: table.tableName,
|
|
174
176
|
description: 'Your DynamoDB table name.',
|
|
175
177
|
exportName: cdk.Fn.join(':', [context.api.apiId, 'GetAtt', tableLogicalName, 'Name']),
|
|
176
178
|
});
|
|
177
179
|
|
|
178
|
-
const role = this.createIAMRole(context, def,
|
|
180
|
+
const role = this.createIAMRole(context, def, scope, tableName);
|
|
179
181
|
const tableDataSourceLogicalName = `${def!.name.value}Table`;
|
|
180
|
-
this.createModelTableDataSource(def, context, table,
|
|
182
|
+
this.createModelTableDataSource(def, context, table, scope, role, tableDataSourceLogicalName);
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
private createModelTableDataSource(
|
|
184
186
|
def: ObjectTypeDefinitionNode,
|
|
185
187
|
context: TransformerContextProvider,
|
|
186
188
|
table: Table,
|
|
187
|
-
|
|
189
|
+
scope: Construct,
|
|
188
190
|
role: iam.Role,
|
|
189
191
|
dataSourceLogicalName: string,
|
|
190
192
|
): void {
|
|
@@ -193,7 +195,7 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
|
|
|
193
195
|
datasourceRoleLogicalID,
|
|
194
196
|
table,
|
|
195
197
|
{ name: dataSourceLogicalName, serviceRole: role },
|
|
196
|
-
|
|
198
|
+
scope,
|
|
197
199
|
);
|
|
198
200
|
|
|
199
201
|
const cfnDataSource = dataSource.node.defaultChild as CfnDataSource;
|
|
@@ -211,7 +213,7 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
|
|
|
211
213
|
}
|
|
212
214
|
|
|
213
215
|
const datasourceOutputId = `GetAtt${datasourceRoleLogicalID}Name`;
|
|
214
|
-
new cdk.CfnOutput(
|
|
216
|
+
new cdk.CfnOutput(cdk.Stack.of(scope), datasourceOutputId, {
|
|
215
217
|
value: dataSource.ds.attrName,
|
|
216
218
|
description: 'Your model DataSource name.',
|
|
217
219
|
exportName: cdk.Fn.join(':', [context.api.apiId, 'GetAtt', datasourceRoleLogicalID, 'Name']),
|
|
@@ -225,16 +227,17 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
|
|
|
225
227
|
/**
|
|
226
228
|
* createIAMRole
|
|
227
229
|
*/
|
|
228
|
-
createIAMRole = (context: TransformerContextProvider, def: ObjectTypeDefinitionNode,
|
|
230
|
+
createIAMRole = (context: TransformerContextProvider, def: ObjectTypeDefinitionNode, scope: Construct, tableName: string): iam.Role => {
|
|
229
231
|
const roleName = context.resourceHelper.generateIAMRoleName(ModelResourceIDs.ModelTableIAMRoleID(def!.name.value));
|
|
230
|
-
const role = new iam.Role(
|
|
232
|
+
const role = new iam.Role(scope, ModelResourceIDs.ModelTableIAMRoleID(def!.name.value), {
|
|
231
233
|
roleName,
|
|
232
234
|
assumedBy: new iam.ServicePrincipal('appsync.amazonaws.com'),
|
|
233
235
|
});
|
|
236
|
+
setResourceName(role, { name: ModelResourceIDs.ModelTableIAMRoleID(def!.name.value), setOnDefaultChild: true });
|
|
234
237
|
|
|
235
238
|
const amplifyDataStoreTableName = context.resourceHelper.generateTableName(SyncResourceIDs.syncTableName);
|
|
236
239
|
role.attachInlinePolicy(
|
|
237
|
-
new iam.Policy(
|
|
240
|
+
new iam.Policy(scope, 'DynamoDBAccess', {
|
|
238
241
|
statements: [
|
|
239
242
|
new iam.PolicyStatement({
|
|
240
243
|
effect: iam.Effect.ALLOW,
|
|
@@ -278,7 +281,7 @@ export class DynamoModelResourceGenerator extends ModelResourceGenerator {
|
|
|
278
281
|
const syncConfig = SyncUtils.getSyncConfig(context, def!.name.value);
|
|
279
282
|
if (syncConfig && SyncUtils.isLambdaSyncConfig(syncConfig)) {
|
|
280
283
|
role.attachInlinePolicy(
|
|
281
|
-
SyncUtils.createSyncLambdaIAMPolicy(context,
|
|
284
|
+
SyncUtils.createSyncLambdaIAMPolicy(context, scope, syncConfig.LambdaConflictHandler.name, syncConfig.LambdaConflictHandler.region),
|
|
282
285
|
);
|
|
283
286
|
}
|
|
284
287
|
|
|
@@ -132,7 +132,7 @@ export abstract class ModelResourceGenerator {
|
|
|
132
132
|
`${query.typeName}.${query.fieldName}.{slotName}.{slotIndex}.req.vtl`,
|
|
133
133
|
),
|
|
134
134
|
);
|
|
135
|
-
resolver.
|
|
135
|
+
resolver.setScope(context.stackManager.getScopeFor(query.resolverLogicalId, def!.name.value));
|
|
136
136
|
context.resolvers.addResolver(query.typeName, query.fieldName, resolver);
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -166,7 +166,7 @@ export abstract class ModelResourceGenerator {
|
|
|
166
166
|
`${mutation.typeName}.${mutation.fieldName}.{slotName}.{slotIndex}.req.vtl`,
|
|
167
167
|
),
|
|
168
168
|
);
|
|
169
|
-
resolver.
|
|
169
|
+
resolver.setScope(context.stackManager.getScopeFor(mutation.resolverLogicalId, def!.name.value));
|
|
170
170
|
context.resolvers.addResolver(mutation.typeName, mutation.fieldName, resolver);
|
|
171
171
|
});
|
|
172
172
|
|
|
@@ -213,7 +213,7 @@ export abstract class ModelResourceGenerator {
|
|
|
213
213
|
),
|
|
214
214
|
);
|
|
215
215
|
}
|
|
216
|
-
resolver.
|
|
216
|
+
resolver.setScope(context.stackManager.getScopeFor(subscription.resolverLogicalId, def!.name.value));
|
|
217
217
|
context.resolvers.addResolver(subscription.typeName, subscription.fieldName, resolver);
|
|
218
218
|
});
|
|
219
219
|
}
|
|
@@ -37,17 +37,17 @@ export class RdsModelResourceGenerator extends ModelResourceGenerator {
|
|
|
37
37
|
RDSLambdaDataSourceLogicalID,
|
|
38
38
|
RDSPatchingSubscriptionLogicalID,
|
|
39
39
|
} = ResourceConstants.RESOURCES;
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
setRDSLayerMappings(
|
|
40
|
+
const lambdaRoleScope = context.stackManager.getScopeFor(RDSLambdaIAMRoleLogicalID, RDS_STACK_NAME);
|
|
41
|
+
const lambdaScope = context.stackManager.getScopeFor(RDSLambdaLogicalID, RDS_STACK_NAME);
|
|
42
|
+
setRDSLayerMappings(lambdaScope, context.rdsLayerMapping);
|
|
43
43
|
const role = createRdsLambdaRole(
|
|
44
44
|
context.resourceHelper.generateIAMRoleName(RDSLambdaIAMRoleLogicalID),
|
|
45
|
-
|
|
45
|
+
lambdaRoleScope,
|
|
46
46
|
secretEntry as RDSConnectionSecrets,
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
const lambda = createRdsLambda(
|
|
50
|
-
|
|
50
|
+
lambdaScope,
|
|
51
51
|
context.api,
|
|
52
52
|
role,
|
|
53
53
|
{
|
|
@@ -60,22 +60,22 @@ export class RdsModelResourceGenerator extends ModelResourceGenerator {
|
|
|
60
60
|
context.sqlLambdaVpcConfig,
|
|
61
61
|
);
|
|
62
62
|
|
|
63
|
-
const
|
|
64
|
-
const
|
|
63
|
+
const patchingLambdaRoleScope = context.stackManager.getScopeFor(RDSPatchingLambdaIAMRoleLogicalID, RDS_STACK_NAME);
|
|
64
|
+
const patchingLambdaScope = context.stackManager.getScopeFor(RDSPatchingLambdaLogicalID, RDS_STACK_NAME);
|
|
65
65
|
const patchingLambdaRole = createRdsPatchingLambdaRole(
|
|
66
66
|
context.resourceHelper.generateIAMRoleName(RDSPatchingLambdaIAMRoleLogicalID),
|
|
67
|
-
|
|
67
|
+
patchingLambdaRoleScope,
|
|
68
68
|
lambda.functionArn,
|
|
69
69
|
);
|
|
70
70
|
|
|
71
71
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
|
-
const patchingLambda = createRdsPatchingLambda(
|
|
72
|
+
const patchingLambda = createRdsPatchingLambda(patchingLambdaScope, context.api, patchingLambdaRole, {
|
|
73
73
|
LAMBDA_FUNCTION_ARN: lambda.functionArn,
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
// Add SNS subscription for patching notifications
|
|
77
|
-
const
|
|
78
|
-
const snsTopic = Topic.fromTopicArn(
|
|
77
|
+
const patchingSubscriptionScope = context.stackManager.getScopeFor(RDSPatchingSubscriptionLogicalID, RDS_STACK_NAME);
|
|
78
|
+
const snsTopic = Topic.fromTopicArn(patchingSubscriptionScope, 'RDSPatchingTopic', RDS_PATCHING_SNS_TOPIC_ARN);
|
|
79
79
|
const subscription = new LambdaSubscription(patchingLambda, {
|
|
80
80
|
filterPolicy: {
|
|
81
81
|
Region: SubscriptionFilter.stringFilter({
|
|
@@ -85,8 +85,8 @@ export class RdsModelResourceGenerator extends ModelResourceGenerator {
|
|
|
85
85
|
});
|
|
86
86
|
snsTopic.addSubscription(subscription);
|
|
87
87
|
|
|
88
|
-
const
|
|
89
|
-
const rdsDatasource = context.api.host.addLambdaDataSource(`${RDSLambdaDataSourceLogicalID}`, lambda, {},
|
|
88
|
+
const lambdaDataSourceScope = context.stackManager.getScopeFor(RDSLambdaDataSourceLogicalID, RDS_STACK_NAME);
|
|
89
|
+
const rdsDatasource = context.api.host.addLambdaDataSource(`${RDSLambdaDataSourceLogicalID}`, lambda, {}, lambdaDataSourceScope);
|
|
90
90
|
this.models.forEach((model) => {
|
|
91
91
|
context.dataSources.add(model, rdsDatasource);
|
|
92
92
|
this.datasourceMap[model.name.value] = rdsDatasource;
|