Skip to content

Commit

Permalink
Fix Lambda invoke with JSON payloads (#331)
Browse files Browse the repository at this point in the history
Lambda payloads were getting JSON.stringified which broke lambda invoke of a json payload without workarounds. The Javascript SDK supports using a buffer, so use that mechanism instead.
  • Loading branch information
hunterwerlla authored Mar 5, 2020
1 parent 166a964 commit 97b81a7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Fix corrupting lambda invocations with JSON payloads"
}
2 changes: 1 addition & 1 deletion Tasks/LambdaInvokeFunction/TaskOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/taskTests/lambdaInvoke/lambdaInvoke-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit 97b81a7

Please sign in to comment.