diff --git a/.changes/next-release/Bug Fix-69d2c958-09df-464d-b3c6-867d6b612a41.json b/.changes/next-release/Bug Fix-69d2c958-09df-464d-b3c6-867d6b612a41.json new file mode 100644 index 00000000..af50da5a --- /dev/null +++ b/.changes/next-release/Bug Fix-69d2c958-09df-464d-b3c6-867d6b612a41.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Fix corrupting lambda invocations with JSON payloads" +} diff --git a/Tasks/LambdaInvokeFunction/TaskOperations.ts b/Tasks/LambdaInvokeFunction/TaskOperations.ts index 2f6ebe8b..bf017565 100644 --- a/Tasks/LambdaInvokeFunction/TaskOperations.ts +++ b/Tasks/LambdaInvokeFunction/TaskOperations.ts @@ -19,7 +19,7 @@ export class TaskOperations { FunctionName: this.taskParameters.functionName } if (this.taskParameters.payload) { - params.Payload = JSON.stringify(this.taskParameters.payload) + params.Payload = Buffer.from(this.taskParameters.payload) } if (this.taskParameters.invocationType) { params.InvocationType = this.taskParameters.invocationType diff --git a/tests/taskTests/lambdaInvoke/lambdaInvoke-test.ts b/tests/taskTests/lambdaInvoke/lambdaInvoke-test.ts index bbb64a97..d98242c4 100644 --- a/tests/taskTests/lambdaInvoke/lambdaInvoke-test.ts +++ b/tests/taskTests/lambdaInvoke/lambdaInvoke-test.ts @@ -82,4 +82,23 @@ describe('Lambda Invoke', () => { expect(lambda.invoke).toBeCalledTimes(2) expect(lambda.getFunctionConfiguration).toBeCalledTimes(2) }) + + test('Handles json property', async () => { + expect.assertions(3) + const taskParameters = { ...baseTaskParameters } + const payload = '{"key": "value"}' + taskParameters.payload = payload + const lambda = new Lambda() as any + lambda.getFunctionConfiguration = jest.fn(() => getFunctionSucceeds) + lambda.invoke = jest.fn(params => { + console.log(params) + expect(params.Payload.toString('utf8')).toBe(payload) + + return invokeLambdaSucceeds + }) + const taskOperations = new TaskOperations(lambda, taskParameters) + await taskOperations.execute() + expect(lambda.invoke).toBeCalledTimes(1) + expect(lambda.getFunctionConfiguration).toBeCalledTimes(1) + }) })