Successfully import an S3 bucket as an AWS CloudFormation stack
Created by Ram Kandaswamy (AWS)
Summary
If you use Amazon Web Services (AWS) resources, such as Amazon Simple Storage Service (Amazon S3) buckets, and want to use an infrastructure as code (IaC) approach, then you can import your resources into AWS CloudFormation and manage them as a stack.
This pattern provides steps to successfully import an S3 bucket as an AWS CloudFormation stack. By using this pattern's approach, you can avoid possible errors that might occur if you import your S3 bucket in a single action.
Prerequisites and limitations
Prerequisites
An active AWS account.
An existing S3 bucket and S3 bucket policy. For more information about this, see What S3 bucket policy should I use to comply with the AWS Config rule s3-bucket-ssl-requests-only
in the AWS Knowledge Center. An existing AWS Key Management Service (AWS KMS) key and its alias. For more information about this, see Working with aliases in the AWS KMS documentation.
The sample
CloudFormation-template-S3-bucket
AWS CloudFormation template (attached), downloaded to your local computer.
Architecture
The diagram shows the following workflow:
The user creates a JSON or YAML-formatted AWS CloudFormation template.
The template creates an AWS CloudFormation stack to import the S3 bucket.
The AWS CloudFormation stack manages the S3 bucket that you specified in the template.
Technology stack
AWS CloudFormation
AWS Identity and Access Management (IAM)
AWS KMS
Amazon S3
Tools
AWS CloudFormation – AWS CloudFormation helps you to create and provision AWS infrastructure deployments predictably and repeatedly.
AWS Identity and Access Management (IAM) – IAM is a web service for securely controlling access to AWS services.
AWS KMS – AWS Key Management Service (AWS KMS) is an encryption and key management service scaled for the cloud.
Amazon S3 – Amazon Simple Storage Service (Amazon S3) is storage for the Internet.
Epics
Task | Description | Skills required |
---|---|---|
Create a template to import the S3 bucket and KMS key. | On your local computer, create a template to import your S3 bucket and KMS key by using the following sample template:
| AWS DevOps |
Create the stack. |
| AWS DevOps |
Create the KMS key alias. |
For more information about this, see AWS CloudFormation stack updates in the AWS CloudFormation documentation. | AWS DevOps |
Update the stack to include the S3 bucket policy. |
NoteThis S3 bucket policy has a deny statement that restricts API calls that are not secure. | AWS DevOps |
Update the key policy. |
For more information, see Key policies in AWS KMS in the AWS KMS documentation. | AWS administrator |
Add resource-level tags. |
| AWS DevOps |
Related resources
Attachments
To access additional content that is associated with this document, unzip the following file: attachment.zip