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

3 minute read
1

I tried to update or delete my AWS CloudFormation stack, but I received this error: "Export EXPORT_NAME cannot be updated as it is in use by STACK_NAME."

Short description

You get this error when 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 when other stacks are importing values from your stack.

To resolve this error, complete the following steps:

  1. Find the stacks that are importing the exported output value.
  2. For stacks that you identify as importing the exported value, update the stack template to replace the import statements with the output value.
  3. Use the modified template to update the importing stack.

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

Find the stacks that are importing the exported output value

To determine the stacks that reference the exported output value, use AWS CLI, AWS Tools for PowerShell, or 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 stack template to replace the Import statements with the output value

  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 imported value arn:aws:s3:::sample replaces the intrinsic functions Fn::ImportValue and !ImportValue 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. When the imports are disassociated, update or delete the stack that exported the values.

Related information

Listing stacks that import an exported output value

list-exports

AWS OFFICIAL
AWS OFFICIALUpdated 8 months ago