aws cloudformation importing existing resources
In this demo, i am going to import an existing storage called "appjerwo-demo-test" and once i have done that I will create another s3 bucket called "myjerwo-new-bucket-2026".
To get started, I will need to have to prepare my import s3 template.
import-template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: Import existing S3 bucket
Resources:
ImportedAppBucket: # ← ONLY the resource being imported
Type: AWS::S3::Bucket
DeletionPolicy: Retain # ← REQUIRED for imports
Properties:
BucketName: appjerwo-demo-test
And then I will proceed to run the following command to create import changeset. My stack name is called my-app-stack.
aws cloudformation create-change-set \
--stack-name my-app-stack \
--change-set-name import-bucket \
--change-set-type IMPORT \
--template-body file://import-template.yaml \
--resources-to-import '[{
"ResourceType": "AWS::S3::Bucket",
"LogicalResourceId": "ImportedAppBucket",
"ResourceIdentifier": {"BucketName": "appjerwo-demo-test"}
}]' \
--capabilities CAPABILITY_NAMED_IAM --region ap-southeast-2
Next we will update specify our change set name
aws cloudformation execute-change-set \
--stack-name my-app-stack \
--change-set-name import-bucket --region ap-southeast-2
Once we have imported our existing resource, next we will need to add more resources to it. In this case, we are creating another s3 instance.
full-stack.yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: Stack with imported bucket + new resources
Resources:
ImportedAppBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain # ← Keep this!
Properties:
BucketName: appjerwo-demo-test
NewS3Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete # ← Optional (default is Delete)
Properties:
BucketName: myjerwo-new-bucket-2026
And now it is time for us to deploy our stack
aws cloudformation wait stack-import-complete
--stack-name my-app-stack --region ap-southeast-2
We can see that 1 new s3 instance has been created
And you can also see our stack has 2 resources
Comments