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

4 minute read
1

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."

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 Importstatements with the actual output value.
  3. Update the importing stack using the modified template.

Resolution

Note: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, be sure that you’re using the most recent version of the AWS CLI.

Find the stacks that are importing the exported output value

To see what stacks are referencing the exported output value, use the 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 stack template to replace the Import statements with the actual 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 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.

Now that the imports are disassociated, you can update or delete the stack that exported the values.


Related information

Listing stacks that import an exported output value

list-exports

list-imports

Get-CFNExport Cmdlet

Get-CFNImportList Cmdlet

AWS OFFICIAL
AWS OFFICIALUpdated 2 years ago