Export name with XYZ is already exported by stack ABC
Creating unique export names for CloudFormation templates using variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
⚙️ Check out my series on Automating Cybersecurity Metrics. The Code.
🔒 Related Stories: AWS Security | Application Security | CloudFormation
💻 Free Content on Jobs in Cybersecurity | ✉️ Sign up for the Email List
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
While writing my latest blog post series on automating security metrics I noticed I had a bug that I somehow overlooked previously. If you weren’t aware of how to overcome this issue you might think that you need to create separate CloudFormation templates when you need the exports from the same template to have a different name each time it gets deployed, but that is not the case.

The error above is telling me that I have two CloudFormation stacks trying to use the same export the same name.

If I look at the details of both those stacks I can see that they are using the same template:


Let’s say you wrote your outputs to look like this:
Outputs:
batchjobroleoutput:
Value: !Ref BatchJobRole
Export:
Name: batchjobrole
batchjobrolearnoutput:
Value: !GetAtt BatchJobRole.Arn
Export:
Name: batchjobrolearnWhich every template is run first will succeed and create your outputs. The second will fail.
In my case I had created a parameter and was correctly using it in the output to create a unique name for each template, and that’s how you can fix this problem. I tried to post the code here but apparently Medium has an issue with my code at the moment so here’s are a couple of screenshots.
The parameter gives the role a unique name:

The outputs use that name to create a unique export name:

My bug was that I failed added another parameter that needs to be added to the export name now to ensure it is unique. Alternatively I could change the name I am passing into the templates. I used POC for the job name in both cases.
Here’s another tip. When you need to deploy the same resources in multiple regions, use the AWS::Region pseudo parameter in the name to keep the names the same with the exception of current region where the resource gets deployed.
Follow for updates.
Teri Radichel | © 2nd Sight Lab 2022
About Teri Radichel:
~~~~~~~~~~~~~~~~~~~~
⭐️ Author: Cybersecurity Books
⭐️ Presentations: Presentations by Teri Radichel
⭐️ Recognition: SANS Award, AWS Security Hero, IANS Faculty
⭐️ Certifications: SANS ~ GSE 240
⭐️ Education: BA Business, Master of Software Engineering, Master of Infosec
⭐️ Company: Penetration Tests, Assessments, Phone Consulting ~ 2nd Sight LabNeed Help With Cybersecurity, Cloud, or Application Security?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
🔒 Request a penetration test or security assessment
🔒 Schedule a consulting call
🔒 Cybersecurity Speaker for PresentationFollow for more stories like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
❤️ Sign Up my Medium Email List
❤️ Twitter: @teriradichel
❤️ LinkedIn: https://www.linkedin.com/in/teriradichel
❤️ Mastodon: @teriradichel@infosec.exchange
❤️ Facebook: 2nd Sight Lab
❤️ YouTube: @2ndsightlab
