Aws-sdk-js: Having callback in lambda.invoke(params, callback).promise() results in double invocation

Created on 14 Jul 2020  路  3Comments  路  Source: aws/aws-sdk-js

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
The following code results in 2 invocations instead of 1:

let invocationParams = {
  FunctionName: 'someFunction',
  InvocationType: 'Event',
  Payload: JSON.stringify(payload)
};
let callback = function(err, data){};
await lambda.invoke(invocationParams, callback).promise()

Without callback argument it does only 1 invocation, as expected:

let invocationParams = {
  FunctionName: 'someFunction',
  InvocationType: 'Event',
  Payload: JSON.stringify(payload)
};
await lambda.invoke(invocationParams).promise()

This issue was originally reported in https://github.com/aws/aws-sdk-js/issues/1665 but was closed because reporter has found a workaround to de-duplicate invocations.
Here is stackoverflow question with correct answer how to resolve the issue: https://stackoverflow.com/questions/59260401/aws-lambda-direct-invocation-sends-two-immediate-responses

Is the issue in the browser/Node.js?
Node.js

If on Node.js, are you running this on AWS Lambda?
Yes

Details of the browser/Node.js version
Node.js 12 runtime in AWS Lambda

SDK version number
v2.709.0

bug needs-triage

All 3 comments

Similar to https://github.com/aws/aws-sdk-js/issues/3215

Callbacks and promises are mutually exclusive though - I agree it would be better it threw an error instead of duplicating the invocation (I guess that's what you're suggesting?)

@arogulin Thank-you for reaching out to us, I agree with the stackOverflow as callbacks and promises should not be mixed together. I am a little confused about your request as you already provided an answer in your original request. Is there anything I am missing?

Closing this now, please feel free to reach out if you have any other questions.

Thank you @philipwigg and @ajredniwja for looking into the issue and linking it with another duplicate. I think the resolution for it could be either:

Was this page helpful?
0 / 5 - 0 ratings