For SST/Cloudformation best practices, is it bad t...
# sst
d
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
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
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
Yeah, you can add this to the Bucket’s stack:
Copy code
this.exportValue(bucket.bucketArn)
d
Is there a better way? Should we avoid referencing resources in other stacks?
f
Usually the bucket’s ARN is exported automatically behind the scene when you reference it in another stack.
d
🤔 I’ll try
f
And if you remove all the references to it, the export is also removed.
When you deploy, you’d get an error.
d
Ya, it should automatically be exported.
f
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
Yes! That!
Okay, so if I do multiple deploys slowly
f
So by adding
this.exportValue(bucket.bucketArn)
you are telling CDK to always export the ARN, even no one is referencing it.
d
Starting from the downstream…… Oh, just use exportValue()
f
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
Beauty! Frank you’re my hero! I’ve got a plan
f
lol nah we need to document this better
d
ha, you say that all the time too
it’s a complex system it ain’t easy to document all the things