-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async/await syntax in lambda not working #100
Comments
Huh, I'm facing a similar issue right now, in a different context. The call to In essence, this works: const app = express()
app.listen(port, () => {
console.log(`Server is up at port ${port}`)
connection.connect().then(() => console.log('connected!'))
}); while this does not: const app = express()
connection.connect().then(() => {
console.log('connected!')
app.listen(port, () => {
console.log(`Server is up at port ${port}`)
});
}) In the latter case the promise returned from I'm working on my local environment: |
I think the issue is most likely because connection.connect() does not take a reference to the V8 event-loop and when the line app.listen is executed asynchronously all references are gone and the application completes before the connection.connect() has had a chance to run. You see the reverse behavior in the 2nd option, because app.listen takes a reference to the event-loop when the closure is created, and thus it keeps the application alive until after the connection completes. One easy work around is to throw a timer into the application (or a loop or something) |
@JonathanHenson |
@fredericbarthelet when using the latest version of the sdk are you still not able the use async/await in lambdas? |
Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one. |
I found a similar issue but the symptoms look different #58
Known Issue
<prefix>-ats.iot.<region>.amazonaws.com
Describe the bug
Using
aws-iot-device-sdk-js-v2
within the context of an AWS lambda withasync/await
syntax does not work.await
statements forconnection.connect()
,identity.subscribeToCreateCertificateFromCsrAccepted
,identity.subscribeToCreateCertificateFromCsrRejected
andidentity.publishCreateCertificateFromCsr
seems ineffective.SDK version number
1.3.1
Platform/OS/Hardware/Device
AWS lambda on nodejs12.x runtime, no custom layer
To Reproduce (observed behavior)
Deploying the following code to a lambda :
Running the lambda with response of
createProvisioningClaim
as input event prints thewaited 3 seconds
statement - showing async/await does seems to work, no syntax error there - but not theconnected
statement. A few info statement are shown, showing execution of connect did in fact started. However, the lambda runs just over 3s (the timeout period) and then resolve. Nosuccess
string is returned from the lambda execution.Running the same code on my machine nodejs runtime shows no problem at all.
Expected behavior
Resolving promises from
connection.connect()
and other asynchronous calls.Logs/output

Additional context
The reason for executing this code in an lambda environment is for integration testing purposes.
Currently developing iot fleet provisioning pre-provision lambda hook as part of Serverless framework feature.
Lambda aims to simulate a device requesting provisioning via template provisioning feature (CSR) on a freshly deployed CloudFormation stack.
Current state of the PR : serverless/serverless#8324
The text was updated successfully, but these errors were encountered: