- Newest
- Most votes
- Most comments
Deploying DynamoDB Global Secondary Indexes (GSIs) and their autoscaling configurations via CloudFormation when they already exist manually can indeed be challenging. Here's how you can approach this situation:
-
Existing GSIs: CloudFormation can manage existing GSIs without recreating them. You can include the existing GSI definitions in your CloudFormation template, and CloudFormation will recognize them as already existing resources. This way, you won't need to delete the manually created indexes.
-
Autoscaling Configurations: The error message you're encountering suggests that the issue is primarily with the autoscaling configurations rather than the GSIs themselves. CloudFormation doesn't have a direct way to "adopt" existing autoscaling configurations. You'll need to define these in your CloudFormation template.
-
Deployment Strategy: a. First, include the existing GSI definitions in your CloudFormation template without any changes to their structure. b. Then, add the autoscaling configurations for these GSIs in the same template. c. When you deploy, CloudFormation should recognize the existing GSIs and attempt to add the new autoscaling configurations.
-
Potential Issues: If the autoscaling resources (like ScalableTargets and ScalingPolicies) already exist due to manual creation, CloudFormation might fail to create them as new resources. In this case, you have two options: a. Temporarily remove the existing autoscaling configurations manually before deploying the CloudFormation stack. b. Use a custom resource in CloudFormation to check if the autoscaling configurations exist and update them instead of creating new ones.
-
Best Practices: a. Always test your CloudFormation changes in a non-production environment first. b. Use CloudFormation drift detection to identify any manual changes made outside of CloudFormation. c. Consider using the DynamoDB
UpdateTable
API through a custom resource if you need more fine-grained control over the update process. -
Gradual Approach: If you're concerned about potential disruptions, consider a gradual approach: a. Start by including just the GSI definitions in CloudFormation without autoscaling. b. Once that's successful, add autoscaling for one GSI at a time. c. Monitor closely and be prepared to rollback if issues occur.
Remember, while CloudFormation is updating the table, it doesn't wait for index creation to complete because the backfilling phase can take a long time. You can track the index status using the DynamoDB DescribeTable command.
By following these steps and best practices, you should be able to bring your manually created GSIs and their autoscaling configurations under CloudFormation management without deleting existing indexes or causing significant disruptions to your production environment.
Sources
AWS::DynamoDB::Table - AWS CloudFormation
AWS::DynamoDB::GlobalTable - AWS CloudFormation
Amazon DynamoDB template snippets - AWS CloudFormation
My suggestion here would be to convert the table to on-demand mode. This will remove any autoscaling settings. Then add the GSI's to the CFN template and it should complete. Then flip back to provisioned with your autoscaling settings in place. Of course, this needs tested thoroughly in a lower environment.
Relevant content
- asked 2 years ago
- asked 5 years ago
- asked 3 years ago
- asked 10 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 6 months ago