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
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:
promising the Request will result in two invocations). Also, https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property describes callback argument as Called when a response from the service is returned. If a callback is not supplied, you must call AWS.Request.send() on the returned request object to initiate the request., which is confusing, because the request _will be_ initiated if I call promise() instead of send().