6
6
import path from 'path' ;
7
7
import { AttributeType } from 'aws-cdk-lib/aws-dynamodb' ;
8
8
import { App , Stack , Aspects } from 'aws-cdk-lib' ;
9
- import { DynamoDBClient , PutItemCommand } from '@aws-sdk/client-dynamodb' ;
10
- import { marshall } from '@aws-sdk/util-dynamodb' ;
11
9
import { v4 } from 'uuid' ;
12
10
import {
13
11
generateUniqueName ,
@@ -24,7 +22,7 @@ import {
24
22
TEARDOWN_TIMEOUT ,
25
23
TEST_CASE_TIMEOUT
26
24
} from './constants' ;
27
- import { createDynamoDBTable } from '../helpers/parametersUtils' ;
25
+ import { createDynamoDBTable , putDynamoDBItem } from '../helpers/parametersUtils' ;
28
26
29
27
const runtime : string = process . env . RUNTIME || 'nodejs18x' ;
30
28
@@ -37,8 +35,6 @@ const stackName = generateUniqueName(RESOURCE_NAME_PREFIX, uuid, runtime, 'dynam
37
35
const functionName = generateUniqueName ( RESOURCE_NAME_PREFIX , uuid , runtime , 'dynamoDBProvider' ) ;
38
36
const lambdaFunctionCodeFile = 'dynamoDBProvider.class.test.functionCode.ts' ;
39
37
40
- const dynamoDBClient = new DynamoDBClient ( { } ) ;
41
-
42
38
const invocationCount = 1 ;
43
39
44
40
// Parameters to be used by Parameters in the Lambda function
@@ -209,102 +205,122 @@ describe(`parameters E2E tests (dynamoDBProvider) for runtime: ${runtime}`, () =
209
205
ddbTabelGetMultipleCustomKeys ,
210
206
] ) ) ;
211
207
212
- // Deploy the stack
213
- await deployStack ( integTestApp , stack ) ;
214
-
215
208
// Seed tables with test data
216
209
// Test 1
217
- await dynamoDBClient . send ( new PutItemCommand ( {
218
- TableName : tableGet ,
219
- Item : marshall ( {
210
+ putDynamoDBItem ( {
211
+ stack,
212
+ id : 'my-param-test1' ,
213
+ table : ddbTableGet ,
214
+ item : {
220
215
id : 'my-param' ,
221
216
value : 'foo' ,
222
- } ) ,
223
- } ) ) ;
217
+ } ,
218
+ } ) ;
224
219
225
220
// Test 2
226
- await dynamoDBClient . send ( new PutItemCommand ( {
227
- TableName : tableGetMultiple ,
228
- Item : marshall ( {
221
+ putDynamoDBItem ( {
222
+ stack,
223
+ id : 'my-param-test2-a' ,
224
+ table : ddbTableGetMultiple ,
225
+ item : {
229
226
id : 'my-params' ,
230
227
sk : 'config' ,
231
228
value : 'bar' ,
232
- } ) ,
233
- } ) ) ;
234
- await dynamoDBClient . send ( new PutItemCommand ( {
235
- TableName : tableGetMultiple ,
236
- Item : marshall ( {
229
+ } ,
230
+ } ) ;
231
+ putDynamoDBItem ( {
232
+ stack,
233
+ id : 'my-param-test2-b' ,
234
+ table : ddbTableGetMultiple ,
235
+ item : {
237
236
id : 'my-params' ,
238
237
sk : 'key' ,
239
238
value : 'baz' ,
240
- } ) ,
241
- } ) ) ;
239
+ } ,
240
+ } ) ;
242
241
243
242
// Test 3
244
- await dynamoDBClient . send ( new PutItemCommand ( {
245
- TableName : tableGetCustomkeys ,
246
- Item : marshall ( {
243
+ putDynamoDBItem ( {
244
+ stack,
245
+ id : 'my-param-test3' ,
246
+ table : ddbTableGetCustomKeys ,
247
+ item : {
247
248
[ keyAttr ] : 'my-param' ,
248
249
[ valueAttr ] : 'foo' ,
249
- } ) ,
250
- } ) ) ;
250
+ } ,
251
+ } ) ;
251
252
252
253
// Test 4
253
- await dynamoDBClient . send ( new PutItemCommand ( {
254
- TableName : tableGetMultipleCustomkeys ,
255
- Item : marshall ( {
254
+ putDynamoDBItem ( {
255
+ stack,
256
+ id : 'my-param-test4-a' ,
257
+ table : ddbTabelGetMultipleCustomKeys ,
258
+ item : {
256
259
[ keyAttr ] : 'my-params' ,
257
260
[ sortAttr ] : 'config' ,
258
261
[ valueAttr ] : 'bar' ,
259
- } ) ,
260
- } ) ) ;
261
- await dynamoDBClient . send ( new PutItemCommand ( {
262
- TableName : tableGetMultipleCustomkeys ,
263
- Item : marshall ( {
262
+ } ,
263
+ } ) ;
264
+ putDynamoDBItem ( {
265
+ stack,
266
+ id : 'my-param-test4-b' ,
267
+ table : ddbTabelGetMultipleCustomKeys ,
268
+ item : {
264
269
[ keyAttr ] : 'my-params' ,
265
270
[ sortAttr ] : 'key' ,
266
271
[ valueAttr ] : 'baz' ,
267
- } ) ,
268
- } ) ) ;
272
+ } ,
273
+ } ) ;
269
274
270
275
// Test 5
271
- await dynamoDBClient . send ( new PutItemCommand ( {
272
- TableName : tableGet ,
273
- Item : marshall ( {
276
+ putDynamoDBItem ( {
277
+ stack,
278
+ id : 'my-param-test5' ,
279
+ table : ddbTableGet ,
280
+ item : {
274
281
id : 'my-param-json' ,
275
282
value : JSON . stringify ( { foo : 'bar' } ) ,
276
- } ) ,
277
- } ) ) ;
283
+ } ,
284
+ } ) ;
278
285
279
286
// Test 6
280
- await dynamoDBClient . send ( new PutItemCommand ( {
281
- TableName : tableGet ,
282
- Item : marshall ( {
287
+ putDynamoDBItem ( {
288
+ stack,
289
+ id : 'my-param-test6' ,
290
+ table : ddbTableGet ,
291
+ item : {
283
292
id : 'my-param-binary' ,
284
293
value : 'YmF6' , // base64 encoded 'baz'
285
- } ) ,
286
- } ) ) ;
287
-
294
+ } ,
295
+ } ) ;
296
+
288
297
// Test 7
289
- await dynamoDBClient . send ( new PutItemCommand ( {
290
- TableName : tableGetMultiple ,
291
- Item : marshall ( {
298
+ putDynamoDBItem ( {
299
+ stack,
300
+ id : 'my-param-test7-a' ,
301
+ table : ddbTableGetMultiple ,
302
+ item : {
292
303
id : 'my-encoded-params' ,
293
304
sk : 'config.json' ,
294
305
value : JSON . stringify ( { foo : 'bar' } ) ,
295
- } ) ,
296
- } ) ) ;
297
- await dynamoDBClient . send ( new PutItemCommand ( {
298
- TableName : tableGetMultiple ,
299
- Item : marshall ( {
306
+ } ,
307
+ } ) ;
308
+ putDynamoDBItem ( {
309
+ stack,
310
+ id : 'my-param-test7-b' ,
311
+ table : ddbTableGetMultiple ,
312
+ item : {
300
313
id : 'my-encoded-params' ,
301
314
sk : 'key.binary' ,
302
315
value : 'YmF6' , // base64 encoded 'baz'
303
- } ) ,
304
- } ) ) ;
316
+ } ,
317
+ } ) ;
305
318
306
319
// Test 8 & 9 use the same items as Test 1
307
320
321
+ // Deploy the stack
322
+ await deployStack ( integTestApp , stack ) ;
323
+
308
324
// and invoke the Lambda function
309
325
invocationLogs = await invokeFunction ( functionName , invocationCount , 'SEQUENTIAL' ) ;
310
326
0 commit comments