Hi all. I am relatively new in SST. I have some si...
# help
m
Hi all. I am relatively new in SST. I have some situation. In my Stack constructor needs to execute some async functions. For example, I am working with MediaConvert and first I need to get media convert api endpoint. That function is promise and I need to use AWAIT in constructor to wait while info is get from the API. Of course Stack constructor cannot be async so I cannot use await. Is there any approach for this. That is not the only function where I need to use await. The only thing that come up in my mind that I will need to put all in .then(..... and have lot of nested functions on that way, which looks ugly to me. Is there any better solution. Maybe I am missing something
t
You can put async code in your main function and pass it into the stack constructor as an argument
we are considering reworking how stack definitions work to allow async code
f
@Milos Glavinic here’s an sample repo we put together that shows what @thdxr meant https://github.com/fwang/sst-load-ssm/blob/main/stacks/index.js
The
ssm.getParameter
is an async call.
m
Thank you so much. That is exactly what I needed. I have a few really complex stacks, so my main function become flooded. However, I sorted everything inside separate files, and looks amazing. And working as expected finally 🙂