Hi all! I'm trying to set an environment variable ...
# help
v
Hi all! I'm trying to set an environment variable for a S3 bucket notification based on another stack and getting a cyclic reference. Is there a way to add the notifications after everything else has been created or another way of doing this? Thanks in advance
t
you'll need to refactor your stacks so the shared items are lifted into a third stack
I can't provide anything more specific without seeing your stacks though
You can't have circular dependencies so first step would be to identify what is circular in your setup
v
Thanks for the reply! I've got a content stack (S3, Queue), an auth stack (that requires the content stack queue), and a websocket API stack (that relies on the auth stack). The content stack needs the websocket queue url to push data to it on S3 create object
t
why does the auth stack need the content stack?
if you can break that dependency you can fix this
v
it needs the queue url from it to store the users profile picture on cognito post confirmation trigger
t
Can you set that function up in a different stack?
Another option (which is what I do personally) is to store these values in SSM so there aren't direct dependencies between the stacks as it gets messy
then the function can just load those values on start
v
not sure how to go about it. Create a stack containing cognito triggers and then pass them into the auth stack to set them as Auth.cognito.triggers props?
I'll look into SSM, thanks! Does it add noticeable latency to the lambda boot?
t
a bit but I haven't run into any practical issues, we're going to be releasing some first class SST constructs + libraries to store and load things from there
v
ok thanks! Im guessing that if I store the CDK reference to the URL on build in SSM it will get updated in SSM with the proper URL after build? Are there any examples / docs? I can only find retrieving values:
_const_ apiKey = StringParameter.valueFromLookup(_this_, "my_api_key");
t
You don't want to look it up in the stack
You can decouple the auth stack from the queue stack by telling the function to look up the value at runtime
there are a few steps to this so idk if you want to jump down the SSM path right away
Another way to maybe solve your problem is import the auth construct where your queue is created and do auth.getFunction("<trigger").addEnvironment on it
actually not sure if that'll solve it either, circular deps are really rare but tricky when they happen
v
yeah, I call ssm.getParameter in the trigger but I need to save that url at build time right?
t
no you just tell the function the ssm key
v
yeah I've tried reorganising everything a couple of times now 😅
t
Maybe the queue needs to be created inside the auth stack
seems like auth + queue are very coupled
v
yeah, the queue links up the auth stack and the content stack
I think you're onto something! Let me try moving the queue to the auth stack and get back to you!
It works! No more cyclic reference
Thank you so much!