View a markdown version of this page

Import AWS resources into a CloudFormation stack automatically - AWS CloudFormation

Import AWS resources into a CloudFormation stack automatically

You can now import named resources automatically when creating or updating CloudFormation stacks. A named resource is one with a custom name. For more information, see Name type in the CloudFormation Template Reference.

When you initiate auto-import, CloudFormation checks for existing resources that match your template and imports them during deployment. For nested stacks, create the change set from the root stack.

After the import is complete and before performing subsequent stack operations, we recommend running drift detection on imported resources. Drift detection ensures that the template configuration matches the actual configuration. For more information, see Detect drift on an entire CloudFormation stack.

To import a resource, they need to meet the following requirements:

  • The resource must have a static custom name defined in your template. Dynamic names (using !Ref or other functions) are not currently supported.

  • The resource must have a DeletionPolicy of Retain or RetainExceptOnCreate.

  • The resource must not already belong to another CloudFormation stack.

  • The resource type must support CloudFormation import operations. For more information, see Resource type support.

  • The primary ID or an additional identifier for the resource type must be in the template. Primary IDs or additional identifiers with read only properties aren't supported. To find out what the primary ID or additional identifiers are for a type, look for the primaryIdentifier and additionalIdentifiers properties in the resource schema. For more information on these, see resource type definition schema.

Example auto-import

The following example uses a change set, CreateChangeSet to create a stack called my-stack based on a template file, template.yaml, and imports matching resources automatically.

aws cloudformation create-change-set \ --stack-name my-stack \ --change-set-name CreateChangeSet \ --change-set-type CREATE \ --template-body file://template.yaml \ --import-existing-resources

Troubleshooting

If auto-import fails, do the following to troubleshoot:

  • Verify the resource name in your template matches the name of the resource exactly

  • Verify that the resource isn't already managed by another stack

  • Make sure the resource type supports auto import

  • Verify your template includes all the required properties for the resource type

Supported resource types

The following table lists AWS resource types that currently support auto-import.

Resource

AWS::ACMPCA::CertificateAuthorityActivation

AWS::ACMPCA::Permission

AWS::APS::ResourcePolicy

AWS::ARCZonalShift::ZonalAutoshiftConfiguration

AWS::ApiGateway::BasePathMapping

AWS::ApiGateway::DocumentationVersion

AWS::ApiGateway::DomainName

AWS::ApiGateway::Method

AWS::ApiGateway::Model

AWS::ApiGateway::Stage

AWS::ApiGatewayV2::DomainName

AWS::ApiGatewayV2::Stage

AWS::AppFlow::Connector

AWS::AppFlow::ConnectorProfile

AWS::AppFlow::Flow

AWS::AppIntegrations::EventIntegration

AWS::AppStream::AppBlockBuilder

AWS::AppStream::ApplicationEntitlementAssociation

AWS::AppStream::ApplicationFleetAssociation

AWS::AppStream::DirectoryConfig

AWS::AppStream::Entitlement

AWS::AppStream::ImageBuilder

AWS::AppStream::Stack

AWS::AppStream::StackFleetAssociation

AWS::AppStream::StackUserAssociation

AWS::AppStream::User

AWS::AppSync::DomainName

AWS::AppSync::SourceApiAssociation

AWS::ApplicationAutoScaling::ScalableTarget

AWS::Athena::CapacityReservation

AWS::Athena::DataCatalog

AWS::Athena::PreparedStatement

AWS::Athena::WorkGroup

AWS::AutoScaling::AutoScalingGroup

AWS::AutoScaling::LaunchConfiguration

AWS::AutoScaling::LifecycleHook

AWS::AutoScaling::WarmPool

AWS::Backup::BackupVault

AWS::Backup::LogicallyAirGappedBackupVault

AWS::Backup::RestoreTestingPlan

AWS::Backup::RestoreTestingSelection

AWS::Backup::TieringConfiguration

AWS::Batch::ComputeEnvironment

AWS::Batch::JobDefinition

AWS::Batch::QuotaShare

AWS::Batch::ServiceEnvironment

AWS::Bedrock::ResourcePolicy

AWS::BedrockAgentCore::ResourcePolicy

AWS::BedrockAgentCore::WorkloadIdentity

AWS::CUR::ReportDefinition

AWS::Cases::Field

AWS::Cassandra::Keyspace

AWS::Cassandra::Table

AWS::Cassandra::Type

AWS::CloudFormation::ModuleDefaultVersion

AWS::CloudFormation::Stack

AWS::CloudFormation::StackSet

AWS::CloudFront::ConnectionFunction

AWS::CloudFront::KeyValueStore

AWS::CloudFront::MonitoringSubscription

AWS::CloudFront::TrustStore

AWS::CloudTrail::ResourcePolicy

AWS::CloudTrail::Trail

AWS::CloudWatch::Alarm

AWS::CloudWatch::CompositeAlarm

AWS::CloudWatch::Dashboard

AWS::CloudWatch::LogAlarm

AWS::CloudWatch::MetricStream

AWS::CodeDeploy::Application

AWS::CodeDeploy::DeploymentConfig

AWS::CodeDeploy::DeploymentGroup

AWS::CodeGuruProfiler::ProfilingGroup

AWS::CodePipeline::CustomActionType

AWS::CodePipeline::Pipeline

AWS::CodeStarConnections::SyncConfiguration

AWS::Cognito::IdentityPoolPrincipalTag

AWS::Cognito::IdentityPoolRoleAttachment

AWS::Cognito::UserPoolDomain

AWS::Cognito::UserPoolGroup

AWS::Cognito::UserPoolIdentityProvider

AWS::Cognito::UserPoolResourceServer

AWS::Cognito::UserPoolRiskConfigurationAttachment

AWS::Cognito::UserPoolUICustomizationAttachment

AWS::Cognito::UserPoolUser

AWS::Cognito::UserPoolUserToGroupAttachment

AWS::Config::AggregationAuthorization

AWS::Config::ConfigRule

AWS::Config::ConfigurationAggregator

AWS::Config::ConformancePack

AWS::Config::OrganizationConformancePack

AWS::Config::StoredQuery

AWS::Connect::ApprovedOrigin

AWS::Connect::DataTableAttribute