How do I resolve the "No Export named XYZ found" error in AWS CloudFormation?

Last updated: 2020-06-12

I receive the "No Export named XYZ found" error in AWS CloudFormation when I use Fn::ImportValue in my stack. How can I resolve this error?

Short description

If you create a stack reference in AWS CloudFormation that uses import or export values, then you must do the following:

  • In the stack where you're exporting a value, use the Export: flag in the Outputs section of your AWS CloudFormation template.
  • In the stack where you want to reference the exported value, use Fn::ImportValue.

You can receive the error in the following scenarios:

  • You're using Fn::ImportValue in nested stacks.
  • The exported value isn't in the same AWS Region or same account where you're importing the value.
  • The exported value isn't created or published before it's imported by the stack.
  • You used an incorrect export name in the importing stack.

Choose one of the following resolutions based on the scenario that you're experiencing.

Resolution

You're using Fn::ImportValue in nested stacks

With nested stacks, AWS CloudFormation creates child stacks in parallel, by default. If one child stack is importing an output from the other child stack, then stack creation can fail. If AWS CloudFormation creates the child stacks in parallel, then the export value is at risk of not being available in time to be imported by the other child stack.

To resolve the error, use the DependsOn attribute to create an explicit dependency for the stack that's using Fn::ImportValue on the stack with the exported output.

For example, see the following nested stack. ChildStack01 exports a value in the Outputs section, and ChildStack02 uses Fn::ImportValue to import the value from ChildStack01. You can use DependsOn for ChildStack02 based on the following example:

{
   "AWSTemplateFormatVersion": "2010-09-09",
   "Resources": {
       "ChildStack01": {
           "Type": "AWS::CloudFormation::Stack",
           "Properties": {
               "TemplateURL": "https://s3.amazonaws.com/cloudformation-templates-us-east-1/VPC.template",
               "TimeoutInMinutes": "60"
           }
       },
       "ChildStack02": {
           "Type": "AWS::CloudFormation::Stack",
           "DependsOn": "ChildStack01",
           "Properties": {
               "TemplateURL": "https://s3.amazonaws.com/cloudformation-templates-us-east-1/Subnet.template",
               "TimeoutInMinutes": "60"
           }
       }
   }
}

Tip: For cross-stack references, use Fn::ImportValue to import a value from another template. For nested stacks, use Fn::Ref and Fn::GetAtt to reference the value in your current template.

The exported value isn't in the same AWS Region or same account where you're importing the value

Cross-stack references apply only within a single AWS account and Region. Other stacks that are in the same AWS account and Region can import only the exported values.

To resolve this issue, complete the steps in the Verify the stack configuration of the export and import stacks section before you create the stack with Fn::ImportValue.

The exported value isn't created or published before it's imported by the stack

For non-nested stacks, you must deploy the stack that's exporting a value. The stack should be in the Create_Complete or Update_Complete state before creating the stack that's being imported.

To resolve this issue, complete the steps in the Verify the stack configuration of the export and import stacks section before you create the stack with Fn::ImportValue.

You used the incorrect export name in the importing stack

1.    Confirm that the export name is listed in your AWS account.

2.    When you import an export name from one stack to another stack, confirm that you're using the exact same export name in both stacks.

3.    Complete the steps in the Verify the stack configuration of the export and import stacks section before you create the stack with Fn::ImportValue.

Verify the stack configuration of the export and import stacks

You can use either the AWS CloudFormation console or the AWS Command Line Interface (AWS CLI) to verify that the export value exists in the same Region and account.

Using the AWS CloudFormation console:

1.    Open the AWS CloudFormation console.

2.    From the navigation pane, choose Exports.

3.    Confirm that the export value is listed in the console.

Using the AWS CLI:

1.    To list the available exports, run the following command:

aws cloudformation list-exports --region us-east-1

Note: Replace us-east-1 with your Region.

2.    In the output, verify that the Name property is exactly the same for both the importing and exporting stack. The output is similar to the following:

{
    "Exports": [
        {
            "ExportingStackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/private-vpc/99764070-b56c-xmpl-bee8-062a88d1d800",
            "Name": "private-vpc-subnet-a",
            "Value": "subnet-01a234bcdefghij56"
        }
}

Important: When you use import and export values in your stacks, consider the following:

  • Once a stack imports an output value, you can't delete the stack that's exporting that output value or modify the exported output value. You must remove all the imports before you can delete the exporting stack or modify the output value.
  • The export name must be unique within the Region.

Did this article help you?

Anything we could improve?


Need more help?