Can we reference the Imported Resource CFN in other CFN Stack
Okay, so I came across a scenario where we need to reference the already created S3 bucket in Cloudformation. Now I know that we can simply use the name of the bucket and create our Cloudformation template. But I thought that what if I use import bucket CFN template and reference the Output Values of this template in my main CFN template.
So what do you think will this work. I tried to research online but was not getting many references. So I thought of writing this article as I tried it myself.
So the answer is NO presently. We cannot implement this way till the present day on which I am writing this blog. Hope in future some updates may happen. But don’t worry if any update will come, will update my article too.
Attaching the reference template which I was using so some of you can get clear ideas what I was trying to do:
import bucket CFN template:(Named: s3bucketimported.json)
{
“AWSTemplateFormatVersion”: “2010–09–09”,
“Description”: “Import test”,
“Resources”: {
“ImportedBucket”: {
“Type”: “AWS::S3::Bucket”,
“DeletionPolicy”: “Retain”
}
},“Outputs” : {
“ImportedBucketName” : {
“Description” : “Bucket Import”,
“Value” : { “Ref” : “ImportedBucket” },
“Export” : { “Name” : {“Fn::Sub”: “${AWS::StackName}-ImportedBucket” }}
}
}
}
The output Screenshot:
Hence right now you can insert directly the name of your s3 bucket in your template if you have such requirement of using existing s3 bucket in any CFN template.