How can I resolve the "Export EXPORT_NAME cannot be updated as it is in use by STACK_NAME" error?

Last updated: 2019-05-16

I tried to update or delete my AWS CloudFormation stack, but I received an error similar to the following: "Export EXPORT_NAME cannot be updated as it is in use by STACK_NAME." How can I resolve this error?

Short Description

You're getting this error because one or more stacks are importing an exported output value from the stack that you want to update or delete. You can't update or delete your stack if other stacks are importing values from your stack.

To resolve this error, complete the following steps:

  1. Find out what stacks are referencing the exported output value from your stack.
  2. Update the imported values from all stack templates that reference the exported output values from your stack. Then, update or delete the stacks that reference the imported values.

Resolution

Find out what stacks are referencing the exported output value from your stack

To see which stacks are referencing the exported output value, you can use the AWS Command Line Interface (AWS CLI), AWS Tools for PowerShell, or the AWS CloudFormation console.

AWS CLI:

1.    To list all exported output values, run the following command:

aws cloudformation list-exports

2.    To list all stacks that are importing an exported output value, run the following command:

aws cloudformation list-imports --export-name EXPORT_NAME

Note: Replace EXPORT_NAME with the name of your exported output value.

AWS Tools for PowerShell:

1.    To list all exported output values, run the following command:

Get-CFNExport

2.    To list all stacks that are importing an exported output value, run the following command:

Get-CFNImportList -ExportName EXPORT_NAME

Note: Replace EXPORT_NAME with the name of your exported output value.

AWS CloudFormation console:

1.    Open the AWS CloudFormation console.

2.    From the CloudFormation menu, choose Exports.

3.    For Export Name, choose the name of the exported output value from your stack.

4.    For Imports, choose the stacks that are importing the exported output value from your stack.

Update the imported values from all stack templates that reference the exported output value from your stack

1.    In your AWS CloudFormation template, replace intrinsic functions with the imported values for every stack that references the exported output value of your stack.

For example, the intrinsic functions Fn::ImportValue and !ImportValue are both replaced with the imported value arn:aws:s3:::sample in the following JSON and YAML templates.

JSON template with intrinsic function:

{
    "Parameters": {
       "parameterName": {
          "Type": "String"
       }
    },
    "Resources": {
       "testParameter": {
          "Type": "AWS::SSM::Parameter",
          "Properties": {
             "Description": "Test SSM Parameter",
             "Name": { "Ref": "parameterName" },
             "Type": "String",
             "Value": { "Fn::ImportValue": "sample-s3-bucket:Bucket-arn" }
          }
       }
    }
 }

JSON template with imported value:

{
    "Parameters": {
       "parameterName": {
          "Type": "String"
       }
    },
    "Resources": {
       "testParameter": {
          "Type": "AWS::SSM::Parameter",
          "Properties": {
             "Description": "Test SSM Parameter",
             "Name": { "Ref": "parameterName" },
             "Type": "String",
             "Value": "arn:aws:s3:::sample"
          }
       }
    }
 }

YAML template with intrinsic function:

Parameters:
  parameterName:
    Type: String
Resources:
  testParameter:
    Type: AWS::SSM::Parameter
    Properties:
      Description: Test SSM Parameter
      Name: !Ref parameterName
      Type: String
      Value: !ImportValue sample-s3-bucket:Bucket-arn

YAML template with imported value:

Parameters:
  parameterName:
    Type: String
Resources:
  testParameter:
    Type: AWS::SSM::Parameter
    Properties:
      Description: Test SSM Parameter
      Name: !Ref parameterName
      Type: String
      Value: arn:aws:s3:::sample

2.    Update or delete your stack.