Skip to content

Import Resources to Existing Stack Fails

0

I want to import an existing Role into an existing stack. There is a problem with logical Ids that prevents this from happening.

  1. I has a role in stack A and want to move it to stack B
  2. I use command
aws cloudformation create-change-set \
    --stack-name api-develop-v2 --change-set-name ImportChangeSet \
    --change-set-type IMPORT \
    --parameter ParameterKey=Env,UsePreviousValue=true
    --template-url https://{BUCKET_NAME}.s3.ap-northeast-1.amazonaws.com/template.yml \
    --capabilities CAPABILITY_NAMED_IAM \
    --resources-to-import file://ResourcesToImport.json

with ResourcesToImport.json is

{
  "Resources": [
    {
      "ResourceType": "AWS::IAM::Role",
      "LogicalResourceId": "ImportingRole",
      "ResourceIdentifier": {
        "RoleName": "importing-role-develop"
      }
    }
  ]
}

But the change set created fails. It said There was an error creating this change set Resources [ApiDeploymentd640287df3] is missing from ResourceToImport list. It look like my AWS::Serverless::Api re-deploy again when importing my role. When I add "DeletionPolicy": "Retain" to all resource in the template, It still fail, it look like all of my AWS::Serverless::Function update its version

asked 2 years ago445 views

1 Answer
0

Hello,

From the description, I understand that you tried to import an existing IAM role into another existing stack. However, change set creation failed.

I would like to inform you that by design, when you try to import existing resources into another existing stack there are few prerequisites.

  • All imported resources must have a DeletionPolicy attribute set to Retain.
  • No additional resources can be created, deleted, or modified in any way during the import process.
  • Make sure that the imported resource defined in your template match the properties of the existing resource.
  • Check the generated change set for your update to verify that only the expected imports are being made.

It is important to note that DeletionPolicy is only added to resource that is being imported into the stack and all other resource configurations are not changed. Hence, I would suggest you to check the above prerequisites and retry import operation.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.