@aws-amplify/graphql-model-transformer 2.2.0-rds-1.0 → 2.2.0-rds-2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +11 -1
- package/lib/graphql-model-transformer.d.ts.map +1 -1
- package/lib/graphql-model-transformer.js +2 -1
- package/lib/graphql-model-transformer.js.map +1 -1
- 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/mutation.d.ts.map +1 -1
- package/lib/resolvers/rds/mutation.js +67 -58
- package/lib/resolvers/rds/mutation.js.map +1 -1
- package/lib/resolvers/rds/query.d.ts.map +1 -1
- package/lib/resolvers/rds/query.js +2 -1
- package/lib/resolvers/rds/query.js.map +1 -1
- package/lib/resolvers/rds/resolver.d.ts +2 -2
- package/lib/resolvers/rds/resolver.d.ts.map +1 -1
- package/lib/resolvers/rds/resolver.js +66 -19
- package/lib/resolvers/rds/resolver.js.map +1 -1
- package/lib/resources/rds-model-resource-generator.d.ts.map +1 -1
- package/lib/resources/rds-model-resource-generator.js +1 -2
- package/lib/resources/rds-model-resource-generator.js.map +1 -1
- package/package.json +7 -7
- package/publish-notification-lambda/node_modules/.package-lock.json +35 -14
- package/publish-notification-lambda/node_modules/@types/node/README.md +1 -1
- package/publish-notification-lambda/node_modules/@types/node/package.json +2 -2
- package/publish-notification-lambda/node_modules/compress-commons/CHANGELOG.md +2 -0
- package/publish-notification-lambda/node_modules/compress-commons/package.json +5 -5
- package/publish-notification-lambda/node_modules/crc32-stream/CHANGELOG.md +2 -0
- package/publish-notification-lambda/node_modules/crc32-stream/package.json +3 -3
- package/publish-notification-lambda/node_modules/zip-stream/CHANGELOG.md +2 -0
- package/publish-notification-lambda/node_modules/zip-stream/node_modules/archiver-utils/LICENSE +22 -0
- package/publish-notification-lambda/node_modules/zip-stream/node_modules/archiver-utils/README.md +6 -0
- package/publish-notification-lambda/node_modules/zip-stream/node_modules/archiver-utils/package.json +54 -0
- package/publish-notification-lambda/node_modules/zip-stream/package.json +10 -10
- package/publish-notification-lambda/package-lock.json +35 -14
- package/rds-lambda/handler.ts +5 -1
- package/rds-lambda/node_modules/.package-lock.json +104 -84
- package/rds-lambda/node_modules/@babel/core/package.json +14 -14
- package/rds-lambda/node_modules/@babel/core/src/config/files/index-browser.ts +2 -2
- package/rds-lambda/node_modules/@babel/core/src/config/files/index.ts +4 -4
- package/rds-lambda/node_modules/@babel/core/src/config/resolve-targets-browser.ts +1 -1
- package/rds-lambda/node_modules/@babel/core/src/config/resolve-targets.ts +1 -1
- package/rds-lambda/node_modules/@babel/core/src/transform-file.ts +5 -5
- package/rds-lambda/node_modules/@babel/generator/package.json +4 -4
- package/rds-lambda/node_modules/@babel/helper-compilation-targets/package.json +2 -2
- package/rds-lambda/node_modules/@babel/helper-module-imports/README.md +1 -1
- package/rds-lambda/node_modules/@babel/helper-module-imports/package.json +4 -4
- package/rds-lambda/node_modules/@babel/helper-module-transforms/package.json +5 -5
- package/rds-lambda/node_modules/@babel/helper-validator-identifier/README.md +1 -1
- package/rds-lambda/node_modules/@babel/helper-validator-identifier/package.json +1 -1
- package/rds-lambda/node_modules/@babel/helper-validator-option/README.md +1 -1
- package/rds-lambda/node_modules/@babel/helper-validator-option/package.json +1 -1
- package/rds-lambda/node_modules/@babel/helpers/package.json +6 -6
- package/rds-lambda/node_modules/@babel/parser/package.json +2 -2
- package/rds-lambda/node_modules/@babel/template/README.md +1 -1
- package/rds-lambda/node_modules/@babel/template/package.json +4 -4
- package/rds-lambda/node_modules/@babel/traverse/package.json +6 -6
- package/rds-lambda/node_modules/@babel/types/package.json +4 -4
- package/rds-lambda/node_modules/@types/node/README.md +1 -1
- package/rds-lambda/node_modules/@types/node/package.json +2 -2
- package/rds-lambda/node_modules/caniuse-lite/package.json +1 -1
- package/rds-lambda/node_modules/compress-commons/CHANGELOG.md +2 -0
- package/rds-lambda/node_modules/compress-commons/package.json +5 -5
- package/rds-lambda/node_modules/crc32-stream/CHANGELOG.md +2 -0
- package/rds-lambda/node_modules/crc32-stream/package.json +3 -3
- 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/pure-rand/CHANGELOG.md +6 -0
- package/rds-lambda/node_modules/pure-rand/package.json +20 -15
- package/rds-lambda/node_modules/zip-stream/CHANGELOG.md +2 -0
- package/rds-lambda/node_modules/zip-stream/node_modules/archiver-utils/LICENSE +22 -0
- package/rds-lambda/node_modules/zip-stream/node_modules/archiver-utils/README.md +6 -0
- package/rds-lambda/node_modules/zip-stream/node_modules/archiver-utils/package.json +54 -0
- package/rds-lambda/node_modules/zip-stream/package.json +10 -10
- package/rds-lambda/package-lock.json +104 -84
- package/rds-patching-lambda/node_modules/.package-lock.json +35 -14
- package/rds-patching-lambda/node_modules/@types/node/README.md +1 -1
- package/rds-patching-lambda/node_modules/@types/node/package.json +2 -2
- package/rds-patching-lambda/node_modules/compress-commons/CHANGELOG.md +2 -0
- package/rds-patching-lambda/node_modules/compress-commons/package.json +5 -5
- package/rds-patching-lambda/node_modules/crc32-stream/CHANGELOG.md +2 -0
- package/rds-patching-lambda/node_modules/crc32-stream/package.json +3 -3
- package/rds-patching-lambda/node_modules/zip-stream/CHANGELOG.md +2 -0
- package/rds-patching-lambda/node_modules/zip-stream/node_modules/archiver-utils/LICENSE +22 -0
- package/rds-patching-lambda/node_modules/zip-stream/node_modules/archiver-utils/README.md +6 -0
- package/rds-patching-lambda/node_modules/zip-stream/node_modules/archiver-utils/package.json +54 -0
- package/rds-patching-lambda/node_modules/zip-stream/package.json +10 -10
- package/rds-patching-lambda/package-lock.json +35 -14
- package/src/__tests__/__snapshots__/model-transformer.test.ts.snap +26 -26
- package/src/__tests__/model-transformer.test.ts +60 -2
- package/src/graphql-model-transformer.ts +2 -1
- package/src/resolvers/rds/mutation.ts +15 -9
- package/src/resolvers/rds/query.ts +2 -1
- package/src/resolvers/rds/resolver.ts +73 -7
- package/src/resources/rds-model-resource-generator.ts +1 -2
- package/tsconfig.tsbuildinfo +1 -1
@@ -8,11 +8,12 @@ export const generateLambdaListRequestTemplate = (
|
|
8
8
|
operationName: string,
|
9
9
|
ctx: TransformerContextProvider,
|
10
10
|
): string => {
|
11
|
+
const mappedTableName = ctx.resourceHelper.getModelNameMapping(tableName);
|
11
12
|
return printBlock('Invoke RDS Lambda data source')(
|
12
13
|
compoundExpression([
|
13
14
|
set(ref('lambdaInput'), obj({})),
|
14
15
|
set(ref('lambdaInput.args'), obj({})),
|
15
|
-
set(ref('lambdaInput.table'), str(
|
16
|
+
set(ref('lambdaInput.table'), str(mappedTableName)),
|
16
17
|
set(ref('lambdaInput.operation'), str(operation)),
|
17
18
|
set(ref('lambdaInput.operationName'), str(operationName)),
|
18
19
|
set(ref('lambdaInput.args.metadata'), obj({})),
|
@@ -15,13 +15,20 @@ import {
|
|
15
15
|
} from 'graphql-mapping-template';
|
16
16
|
import { ResourceConstants, isArrayOrObject } from 'graphql-transformer-common';
|
17
17
|
import { RDSConnectionSecrets, setResourceName } from '@aws-amplify/graphql-transformer-core';
|
18
|
-
import {
|
18
|
+
import {
|
19
|
+
GraphQLAPIProvider,
|
20
|
+
RDSLayerMapping,
|
21
|
+
SubnetAvailabilityZone,
|
22
|
+
TransformerContextProvider,
|
23
|
+
VpcSubnetConfig,
|
24
|
+
} from '@aws-amplify/graphql-transformer-interfaces';
|
19
25
|
import { Effect, IRole, Policy, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
|
20
26
|
import { IFunction, LayerVersion, Runtime } from 'aws-cdk-lib/aws-lambda';
|
21
27
|
import { Construct } from 'constructs';
|
22
28
|
import path from 'path';
|
23
29
|
import { VpcConfig } from '@aws-amplify/graphql-transformer-interfaces/src';
|
24
30
|
import { EnumTypeDefinitionNode, FieldDefinitionNode, Kind, ObjectTypeDefinitionNode } from 'graphql';
|
31
|
+
import { CfnVPCEndpoint } from 'aws-cdk-lib/aws-ec2';
|
25
32
|
|
26
33
|
/**
|
27
34
|
* Define RDS Lambda operations
|
@@ -135,9 +142,19 @@ export const createRdsLambda = (
|
|
135
142
|
apiGraphql: GraphQLAPIProvider,
|
136
143
|
lambdaRole: IRole,
|
137
144
|
environment?: { [key: string]: string },
|
138
|
-
sqlLambdaVpcConfig?:
|
145
|
+
sqlLambdaVpcConfig?: VpcSubnetConfig,
|
139
146
|
): IFunction => {
|
140
147
|
const { RDSLambdaLogicalID } = ResourceConstants.RESOURCES;
|
148
|
+
|
149
|
+
let ssmEndpoint = Fn.join('', ['ssm.', Fn.ref('AWS::Region'), '.amazonaws.com']); // Default SSM endpoint
|
150
|
+
if (sqlLambdaVpcConfig && sqlLambdaVpcConfig.vpcConfig) {
|
151
|
+
const endpoints = addVpcEndpointForSecretsManager(scope, sqlLambdaVpcConfig);
|
152
|
+
const ssmEndpointEntries = endpoints.find((endpoint) => endpoint.service === 'ssm')?.endpoint.attrDnsEntries;
|
153
|
+
if (ssmEndpointEntries) {
|
154
|
+
ssmEndpoint = Fn.select(0, ssmEndpointEntries);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
141
158
|
return apiGraphql.host.addLambdaFunction(
|
142
159
|
RDSLambdaLogicalID,
|
143
160
|
`functions/${RDSLambdaLogicalID}.zip`,
|
@@ -152,13 +169,60 @@ export const createRdsLambda = (
|
|
152
169
|
),
|
153
170
|
],
|
154
171
|
lambdaRole,
|
155
|
-
|
172
|
+
{
|
173
|
+
...environment,
|
174
|
+
SSM_ENDPOINT: ssmEndpoint,
|
175
|
+
},
|
156
176
|
Duration.seconds(30),
|
157
177
|
scope,
|
158
|
-
sqlLambdaVpcConfig,
|
178
|
+
sqlLambdaVpcConfig?.vpcConfig,
|
159
179
|
);
|
160
180
|
};
|
161
181
|
|
182
|
+
const addVpcEndpoint = (scope: Construct, sqlLambdaVpcConfig: VpcSubnetConfig, serviceSuffix: string): CfnVPCEndpoint => {
|
183
|
+
const serviceEndpointPrefix = 'com.amazonaws';
|
184
|
+
return new CfnVPCEndpoint(scope, `RDSVpcEndpoint${serviceSuffix}`, {
|
185
|
+
serviceName: Fn.join('', [serviceEndpointPrefix, '.', Fn.ref('AWS::Region'), '.', serviceSuffix]), // Sample: com.amazonaws.us-east-1.ssmmessages
|
186
|
+
vpcEndpointType: 'Interface',
|
187
|
+
vpcId: sqlLambdaVpcConfig.vpcConfig.vpcId,
|
188
|
+
subnetIds: extractSubnetForVpcEndpoint(sqlLambdaVpcConfig.subnetAvailabilityZoneConfig),
|
189
|
+
securityGroupIds: sqlLambdaVpcConfig.vpcConfig.securityGroupIds,
|
190
|
+
privateDnsEnabled: false,
|
191
|
+
});
|
192
|
+
};
|
193
|
+
|
194
|
+
const addVpcEndpointForSecretsManager = (
|
195
|
+
scope: Construct,
|
196
|
+
sqlLambdaVpcConfig: VpcSubnetConfig,
|
197
|
+
): { service: string; endpoint: CfnVPCEndpoint }[] => {
|
198
|
+
const services = ['ssm', 'ssmmessages', 'ec2', 'ec2messages', 'kms'];
|
199
|
+
return services.map((service) => {
|
200
|
+
return {
|
201
|
+
service,
|
202
|
+
endpoint: addVpcEndpoint(scope, sqlLambdaVpcConfig, service),
|
203
|
+
};
|
204
|
+
});
|
205
|
+
};
|
206
|
+
|
207
|
+
/**
|
208
|
+
* Extract subnet ids for VPC endpoint - We only need one subnet per AZ.
|
209
|
+
* This is mandatory requirement for creating VPC endpoint.
|
210
|
+
* CDK Deployment will fail if you provide more than one subnet per AZ.
|
211
|
+
* @param avaliabilityZoneMappings SubnetAvailabilityZone[]
|
212
|
+
* @returns string[]
|
213
|
+
*/
|
214
|
+
const extractSubnetForVpcEndpoint = (avaliabilityZoneMappings: SubnetAvailabilityZone[]): string[] => {
|
215
|
+
const avaliabilityZones = [] as string[];
|
216
|
+
const result = [];
|
217
|
+
for (const subnet of avaliabilityZoneMappings) {
|
218
|
+
if (!avaliabilityZones.includes(subnet.AvailabilityZone)) {
|
219
|
+
avaliabilityZones.push(subnet.AvailabilityZone);
|
220
|
+
result.push(subnet.SubnetId);
|
221
|
+
}
|
222
|
+
}
|
223
|
+
return result;
|
224
|
+
};
|
225
|
+
|
162
226
|
/**
|
163
227
|
* Create RDS Patching Lambda function
|
164
228
|
* @param scope Construct
|
@@ -302,12 +366,13 @@ export const generateLambdaRequestTemplate = (
|
|
302
366
|
operation: string,
|
303
367
|
operationName: string,
|
304
368
|
ctx: TransformerContextProvider,
|
305
|
-
): string =>
|
306
|
-
|
369
|
+
): string => {
|
370
|
+
const mappedTableName = ctx.resourceHelper.getModelNameMapping(tableName);
|
371
|
+
return printBlock('Invoke RDS Lambda data source')(
|
307
372
|
compoundExpression([
|
308
373
|
set(ref('lambdaInput'), obj({})),
|
309
374
|
set(ref('lambdaInput.args'), obj({})),
|
310
|
-
set(ref('lambdaInput.table'), str(
|
375
|
+
set(ref('lambdaInput.table'), str(mappedTableName)),
|
311
376
|
set(ref('lambdaInput.operation'), str(operation)),
|
312
377
|
set(ref('lambdaInput.operationName'), str(operationName)),
|
313
378
|
set(ref('lambdaInput.args.metadata'), obj({})),
|
@@ -325,6 +390,7 @@ export const generateLambdaRequestTemplate = (
|
|
325
390
|
}),
|
326
391
|
]),
|
327
392
|
);
|
393
|
+
};
|
328
394
|
|
329
395
|
/**
|
330
396
|
* Generate RDS Lambda response template
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { MYSQL_DB_TYPE, RDSConnectionSecrets } from '@aws-amplify/graphql-transformer-core';
|
2
2
|
import { TransformerContextProvider } from '@aws-amplify/graphql-transformer-interfaces';
|
3
|
-
import { Topic } from 'aws-cdk-lib/aws-sns';
|
3
|
+
import { Topic, SubscriptionFilter } from 'aws-cdk-lib/aws-sns';
|
4
4
|
import { LambdaSubscription } from 'aws-cdk-lib/aws-sns-subscriptions';
|
5
5
|
import { ResourceConstants } from 'graphql-transformer-common';
|
6
6
|
import { ModelVTLGenerator, RDSModelVTLGenerator } from '../resolvers';
|
@@ -13,7 +13,6 @@ import {
|
|
13
13
|
} from '../resolvers/rds';
|
14
14
|
import { ModelResourceGenerator } from './model-resource-generator';
|
15
15
|
import { Fn } from 'aws-cdk-lib';
|
16
|
-
import { SubscriptionFilter } from 'aws-cdk-lib/aws-sns';
|
17
16
|
|
18
17
|
export const RDS_STACK_NAME = 'RdsApiStack';
|
19
18
|
// Beta SNS topic - 'arn:aws:sns:us-east-1:956468067974:AmplifyRDSLayerNotification'
|