https://serverless-stack.com/ logo
#sst
Title
# sst
d

Drew

09/15/2021, 1:59 AM
For SST/Cloudformation best practices, is it bad to build multiple stacks that depend upon each other? eg. The ARN of an S3 bucket is export into our Lambdas, and now we cannot make modifications to the S3 bucket
f

Frank

09/15/2021, 3:51 AM
Hey @Drew, if you export the Bucket ARN and imports it into the Lambda, you won’t be able to remove the Bucket directly, you’d have to break the dependency first. But you can make changes to it, ie. updating permission, life cycle policy, setup static site, etc.
Is that what you mean?
d

Drew

09/15/2021, 3:51 AM
Yep, I think that’s exactly it
So, I did that
Now I want to rename that bucket
It has a lovely long name with lotsa numbers and letters at the moment
It’s okay, but I was hoping to rename it to something simple
I was wondering if I could remove all references to the bucket Then rename Then reference it again
f

Frank

09/15/2021, 3:54 AM
Yeah, you can add this to the Bucket’s stack:
Copy code
this.exportValue(bucket.bucketArn)
d

Drew

09/15/2021, 3:54 AM
Is there a better way? Should we avoid referencing resources in other stacks?
f

Frank

09/15/2021, 3:55 AM
Usually the bucket’s ARN is exported automatically behind the scene when you reference it in another stack.
d

Drew

09/15/2021, 3:55 AM
🤔 I’ll try
f

Frank

09/15/2021, 3:55 AM
And if you remove all the references to it, the export is also removed.
When you deploy, you’d get an error.
d

Drew

09/15/2021, 3:56 AM
Ya, it should automatically be exported.
f

Frank

09/15/2021, 3:56 AM
Because CFN will deploy the stack with the bucket first, and tries to remove the export. But the export is still in use, b/c other stacks are still referencing it (u haven’t deployed the other stacks yet).
d

Drew

09/15/2021, 3:57 AM
Yes! That!
Okay, so if I do multiple deploys slowly
f

Frank

09/15/2021, 3:57 AM
So by adding
this.exportValue(bucket.bucketArn)
you are telling CDK to always export the ARN, even no one is referencing it.
d

Drew

09/15/2021, 3:58 AM
Starting from the downstream…… Oh, just use exportValue()
f

Frank

09/15/2021, 3:58 AM
1. add
this.exportValue(bucket.bucketArn)
and remove all references to the ARN 2. deploy 3. rename s3 bucket, add the references back 4. deploy
so 2 deploys required
d

Drew

09/15/2021, 3:59 AM
Beauty! Frank you’re my hero! I’ve got a plan
f

Frank

09/15/2021, 3:59 AM
lol nah we need to document this better
d

Drew

09/15/2021, 4:01 AM
ha, you say that all the time too
it’s a complex system it ain’t easy to document all the things