如何使用CloudFormation从现有RDS实例创建Amazon RDS快照?
Alright, let's walk through exactly how to create an Amazon RDS snapshot from an existing RDS instance using CloudFormation. I’ll break this down into simple, actionable steps with examples so you can follow along easily.
First off, the CloudFormation resource you’ll use for manual RDS snapshots is AWS::RDS::DBSnapshot. This resource lets you define a snapshot tied directly to an existing RDS instance in your account.
Here’s a sample YAML template you can adapt for your use case. I’ll explain each part so you understand what’s going on:
AWSTemplateFormatVersion: '2010-09-09' Description: Creates a manual RDS snapshot from an existing production RDS instance Resources: ProductionRDSManualSnapshot: Type: AWS::RDS::DBSnapshot Properties: DBSnapshotIdentifier: prod-rds-snapshot-20240520 DBInstanceIdentifier: my-production-postgres-instance Tags: - Key: Environment Value: Production - Key: BackupType Value: Manual
Let’s break down the key properties:
- DBSnapshotIdentifier: A unique name for your snapshot (stick to letters, numbers, hyphens, underscores, and dots—no leading hyphens). Make sure it doesn’t clash with any existing snapshots in your region.
- DBInstanceIdentifier: The exact name of your existing RDS instance (this is critical—double-check the instance name in the RDS console to avoid typos). The instance must be in an
availablestate for the snapshot to start. - Tags: Optional but highly recommended—add tags to organize your snapshots by environment, purpose, or team.
You can deploy the template using either the AWS Management Console or the AWS CLI. Let’s cover both methods.
3.1 Using the AWS Console
- Open the CloudFormation console and click Create stack → With new resources (standard).
- Under "Prepare template", select Template is ready, then choose Upload a template file. Upload your YAML file and click Next.
- Give your stack a name (e.g.,
Create-Prod-RDS-Snapshot) and click Next. - On the "Configure stack options" page, you can leave most settings as default (add additional tags if needed) and click Next.
- Review the stack details, check the box acknowledging that CloudFormation might create resources, then click Submit.
- Wait for the stack status to change to
CREATE_COMPLETE—this usually takes a few minutes depending on your RDS instance size.
3.2 Using the AWS CLI
If you prefer command-line tools, run this command (replace placeholders with your details):
aws cloudformation create-stack \ --stack-name Create-Prod-RDS-Snapshot \ --template-body file://path-to-your-template.yaml \ --region us-east-1
To check the stack status later:
aws cloudformation describe-stacks --stack-name Create-Prod-RDS-Snapshot --region us-east-1
Before you dive in, keep these points in mind:
- Snapshot Impact: For single-AZ RDS instances, you’ll see a brief I/O pause during snapshot creation. Multi-AZ instances avoid this because snapshots are taken from the standby instance.
- Permissions: The CloudFormation execution role (or your IAM user if deploying manually) needs the
rds:CreateDBSnapshotpermission, plus access to the target RDS instance. - Encryption: If your RDS instance is encrypted, the snapshot will automatically inherit that encryption (using the same KMS key). You can’t encrypt an unencrypted instance’s snapshot after creation.
- Cross-Region Snapshots: This method creates snapshots in the same region as your instance. To copy a snapshot to another region, you’ll need a separate step (either via the console, CLI, or another CloudFormation resource like
AWS::RDS::DBSnapshotCopy).
Once the stack is complete, confirm the snapshot exists:
- In the RDS console, go to Snapshots → Manual snapshots and look for your snapshot name. It should show a status of
available. - Or use the CLI:
aws rds describe-db-snapshots --db-snapshot-identifier prod-rds-snapshot-20240520 --region us-east-1
内容的提问来源于stack exchange,提问作者Tanuj Chinnu

