-
Notifications
You must be signed in to change notification settings - Fork 457
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 / Promises in Constructs #2516
Comments
Hi @evanstachowiak 👋 Thank you for raising this! Regarding your two points:
While I personally (and the AWS CDK, too) don't think making constructs async is the right way forward, I still think it would be valuable to allow users to e.g. query data using code that they define as part of their CDK application. There are two different existing concepts that could tackle this from another angle:
What is your concrete use-case that requires constructs to support async? |
Hi @ansgarm ! Thank you for your prompt and detailed answer to my issue. I will try to give you as detailed answers to your questions.
Could you also clarify this statement? "Using async code in the top-level of a CDK application works already today". I assume you mean that before declaring the stack & construct, one can use async. Is there something I am missing here? |
Hi @evanstachowiak! Thanks for your detailed answer and insights into your use-case.
Sure! Your assumption is right. You could e.g. change your entrypoint to something along the lines of this: const config = await someFunctionDoingAPIStuff();
const app = new App();
new MyStack(app, "my-stack", config);
app.synth(); (Using the But I agree, that this breaks encapsulation in a way that you'd need to know at a root level, which kind of config your constructs need (and you'd need to pass that down). However, you could write your own base Stack implementation that asserts it has the right config based on the constructs it contains (using e.g. an |
As this whole topic intrigued me, I was wondering whether it would be possible to build my proposed idea in a way that wouldn't break encapsulation and I'd say that is already working today. Here's a link to the prototype. |
@ansgarm , thanks a lot for taking the time to write up such a detailed answer. Nice tip with the top-level wrapped async function. |
One use case for async constructs I have is the need to call async AWS API. The need for that a circular dependency I have otherwise. I need to create a CloudFront distribution with a Lambda@Edge function intercepting viewer requests. Lambda needs to know distribution URL which is only knowable after deployment. And there is no separate resource to create a lambda function association on the distribution. The only way I see is a custom resource that will update the distribution afterwards with the lambda ARN. I know I could specify domain alias for the distribution which is known upfront, but I'd like to avoid that constraint. What I'm considering now is to write a node script and execute it a child process synchronously. @ansgarm 's prototype seems pretty interesting too, though a bit hacky. But if there is a cleaner way to solve my particular issue without async code, I'd be very happy to hear that. |
Howdy! Just stumbling upon this issue. I've run into variations of this issue a lot with the AWS CDK, and I would absolutely advocate for two solutions somewhat outlined in this thread.
|
Hi there! 👋 We haven't heard from you in 30 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days. |
I'm closing this issue because we haven't heard back in 60 days. ⌛️ If you still need help, feel free to comment or reopen the issue! |
I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Community Note
Description
I'd like to re-open this issue: #95.
I would say there are two very important issues with the lack of async support.
Many thanks for all your great work on this project. Looking forward to seeing async support in CDKTF.
References
The text was updated successfully, but these errors were encountered: