https://serverless-stack.com/ logo
#help
Title
# help
r

Ross Gerbasi

01/20/2022, 6:39 PM
Hey all, how do you do async tasks for a stack?> For example its talked about here https://docs.serverless-stack.com/environment-variables#2-fetch-ssm-values-in-cdk-using-the-aws-sdk that you would go get SSM values at stack creation time. however this is in the stack constructor which is not async. What is the recommended way to deal with that?
f

Frank

01/20/2022, 6:47 PM
Hey @Ross Gerbasi, I created a sample repo here that fetches SSM inside the index file - https://github.com/fwang/sst-load-ssm/blob/main/stacks/index.js
r

Ross Gerbasi

01/20/2022, 7:00 PM
ah interesting so you would put stack creation in the callback. can
main
be async? is there a way we can do all this without callbacks?
a

Adam Fanello

01/20/2022, 7:01 PM
You can .promise() the call and put the logic in a Promise.then() instead. Not any cleaner though.
r

Ross Gerbasi

01/20/2022, 7:54 PM
It does seem to work with setting main to async then you can just use await
@Frank just to be sure i am not getting into any danger, async for main is fine? seems to be working great for us...
f

Frank

01/24/2022, 10:16 PM
@Ross Gerbasi yeah I haven’t come across any issue w/ it.
4 Views