From a21cc62fcac4702869c4355df61b5158e7c216c3 Mon Sep 17 00:00:00 2001 From: Neil Niu Date: Thu, 1 May 2025 10:37:53 +1000 Subject: [PATCH] Fixes JSON parsing errors in the DynamoDB seeder Fixes JSON parsing errors in the DynamoDB seeder by: - Replacing `body.toString()` with `transformToString('utf-8')` for proper S3 stream handling --- .../src/lambdas/dynamodb-seeder/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/cdk-dynamodb-seeder/src/lambdas/dynamodb-seeder/index.ts b/packages/cdk-dynamodb-seeder/src/lambdas/dynamodb-seeder/index.ts index f4c0c67f8..8e440d650 100644 --- a/packages/cdk-dynamodb-seeder/src/lambdas/dynamodb-seeder/index.ts +++ b/packages/cdk-dynamodb-seeder/src/lambdas/dynamodb-seeder/index.ts @@ -63,11 +63,15 @@ const getSeedsFromS3 = async (s3Location: { s3Bucket?: string; s3Key?: string; s }) .promise(); - if (!body) { - throw new Error(`Cannot load seeds from bucket ${s3Bucket} with key ${s3Key}`); + const bodyContents = await body.transformToString("utf-8"); + + if (!bodyContents) { + throw new Error( + `Cannot load seeds from bucket ${s3Bucket} with key ${s3Key}` + ); } - return JSON.parse(body.toString()) as Seeds; + return JSON.parse(bodyContents) as Seeds; }; const writeSeeds = async (tableName: string, seeds: Seeds): Promise => {