66import path from 'path' ;
77import { AttributeType } from 'aws-cdk-lib/aws-dynamodb' ;
88import { App , Stack , Aspects } from 'aws-cdk-lib' ;
9- import { DynamoDBClient , PutItemCommand } from '@aws-sdk/client-dynamodb' ;
10- import { marshall } from '@aws-sdk/util-dynamodb' ;
119import { v4 } from 'uuid' ;
1210import {
1311 generateUniqueName ,
@@ -24,7 +22,7 @@ import {
2422 TEARDOWN_TIMEOUT ,
2523 TEST_CASE_TIMEOUT
2624} from './constants' ;
27- import { createDynamoDBTable } from '../helpers/parametersUtils' ;
25+ import { createDynamoDBTable , putDynamoDBItem } from '../helpers/parametersUtils' ;
2826
2927const runtime : string = process . env . RUNTIME || 'nodejs18x' ;
3028
@@ -37,8 +35,6 @@ const stackName = generateUniqueName(RESOURCE_NAME_PREFIX, uuid, runtime, 'dynam
3735const functionName = generateUniqueName ( RESOURCE_NAME_PREFIX , uuid , runtime , 'dynamoDBProvider' ) ;
3836const lambdaFunctionCodeFile = 'dynamoDBProvider.class.test.functionCode.ts' ;
3937
40- const dynamoDBClient = new DynamoDBClient ( { } ) ;
41-
4238const invocationCount = 1 ;
4339
4440// Parameters to be used by Parameters in the Lambda function
@@ -209,102 +205,122 @@ describe(`parameters E2E tests (dynamoDBProvider) for runtime: ${runtime}`, () =
209205 ddbTabelGetMultipleCustomKeys ,
210206 ] ) ) ;
211207
212- // Deploy the stack
213- await deployStack ( integTestApp , stack ) ;
214-
215208 // Seed tables with test data
216209 // 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 : {
220215 id : 'my-param' ,
221216 value : 'foo' ,
222- } ) ,
223- } ) ) ;
217+ } ,
218+ } ) ;
224219
225220 // 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 : {
229226 id : 'my-params' ,
230227 sk : 'config' ,
231228 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 : {
237236 id : 'my-params' ,
238237 sk : 'key' ,
239238 value : 'baz' ,
240- } ) ,
241- } ) ) ;
239+ } ,
240+ } ) ;
242241
243242 // 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 : {
247248 [ keyAttr ] : 'my-param' ,
248249 [ valueAttr ] : 'foo' ,
249- } ) ,
250- } ) ) ;
250+ } ,
251+ } ) ;
251252
252253 // 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 : {
256259 [ keyAttr ] : 'my-params' ,
257260 [ sortAttr ] : 'config' ,
258261 [ 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 : {
264269 [ keyAttr ] : 'my-params' ,
265270 [ sortAttr ] : 'key' ,
266271 [ valueAttr ] : 'baz' ,
267- } ) ,
268- } ) ) ;
272+ } ,
273+ } ) ;
269274
270275 // 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 : {
274281 id : 'my-param-json' ,
275282 value : JSON . stringify ( { foo : 'bar' } ) ,
276- } ) ,
277- } ) ) ;
283+ } ,
284+ } ) ;
278285
279286 // 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 : {
283292 id : 'my-param-binary' ,
284293 value : 'YmF6' , // base64 encoded 'baz'
285- } ) ,
286- } ) ) ;
287-
294+ } ,
295+ } ) ;
296+
288297 // 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 : {
292303 id : 'my-encoded-params' ,
293304 sk : 'config.json' ,
294305 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 : {
300313 id : 'my-encoded-params' ,
301314 sk : 'key.binary' ,
302315 value : 'YmF6' , // base64 encoded 'baz'
303- } ) ,
304- } ) ) ;
316+ } ,
317+ } ) ;
305318
306319 // Test 8 & 9 use the same items as Test 1
307320
321+ // Deploy the stack
322+ await deployStack ( integTestApp , stack ) ;
323+
308324 // and invoke the Lambda function
309325 invocationLogs = await invokeFunction ( functionName , invocationCount , 'SEQUENTIAL' ) ;
310326
0 commit comments