functionless: Native Function Serialization can fail when async promises do not complete.
CDK does not officially support async operations however, Functionless’s native Functions (#103) rely on pulumi’s async function serialization.
We first mitigate this issue by:
- starting an async promise and leaving it dangling.
- Registering the dangling promise with a global array of promises behind
Function.promises
- adding
asyncSynth
which awaits onFunction.promises
withPromise.all
This works when 1) asyncSynth is used 2) Function.promises
is manually awaited on and 3) when the cdk
cli and auto-synth is used.
The reason for 3 is that CDK’s auto-synth is called as part of the node process exiting. When node exits, promises are allowed to complete (join).
When one of the above strategies is not used, it is possible that the native functions will not be serialized and output, causing the lambda code to be invalid.
We output the following text into the lambda: "If you are seeing this in your lambda code, ensure generate is called and then consult the README."
Obviously the failure case isn’t user friendly.
This ticket is a placeholder to do one or more of the following:
- Once CDK native has async support, use it (https://github.com/sam-goodwin/aws-cdk/pull/1)
- replace the “if you are seeing” message with a poison pill that fails synth or deployment.
- Use a serialization function that is not async
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 27 (12 by maintainers)
@thantos Glad to make a small contribution. I love what you guys are building. Hope it catches on.
This seems critically important. What if it works locally and then fails during CI/CD, no one would notice.
When I remove that and call
cdk diff
, the CLI tells me there are no differences. And when I deployed it, there was no difference in the lambda. So I assume the decisive factor was removingapp.synth()
.I think
app.synth()
is designed to be idempotent. Usually you should omit theapp.synth()
call though.The first one.
@sam-goodwin
I’m not seeing any error during deployment, but the lambda code only contains the string: