How to Migrate DataSunrise CloudFormation Template from Launch Configuration (LC) to Launch Template (LT) Resource in Auto Scaling Group
Migrating from an AWS Launch Configuration (LC based Auto Scaling Group (ASG) to a Launch Template (LT) resource offers significant advantages for managing DataSunrise deployments, such as increased flexibility and support for modern AWS and OS features. In many cases, the migration can be performed simply by replacing the existing stack with a template from GitHub, provided the necessary precautions are taken to prevent disruption, especially with AWS RDS Instances (DSDictionaryDB and DSAuditDB).
This guide outlines the key steps and considerations for migrating the CloudFormation template, including how to handle RDS instances and customizations, ensuring a smooth and seamless transition.
Key Considerations for Migration
- Launch Template Advantages:
- Versioning. Multiple versions of a Launch Template can be maintained, providing flexibility for future updates or rollbacks.
- Feature Support. New features such as T2 Unlimited, advanced networking, and IPv6 are supported.
- OS Compatibility. LT supports newer OS distributions such as RHEL8 and Amazon Linux 2023, which are required for running Python 3 scripts in DataSunrise.
- Simplified Stack Update with Pre-Built Template:
- If no custom scripts or tools are in use, the migration can be performed by simply replacing the existing CloudFormation stack with the pre-built template from GitHub.
- Ensure that the necessary steps are taken to prevent RDS Instances used by DataSunrise from being replaced or recreated, as this could result in data loss.
Steps for Migrating the CloudFormation Template
- Backup and Review Existing Stack
- Backup the current CloudFormation template and create snapshots of your RDS Instances (DSDictionaryDB and DSAuditDB) to safeguard against data loss.
- Review any custom scripts or third-party tools tied to your existing Launch Configuration to assess whether additional steps will be required beyond using the GitHub template.
- Download the New Template from GitHub
- Download the new Launch Template (LT)-based CloudFormation template from the official DataSunrise GitHub repository.
- This template is ready for use if your current setup does not involve custom scripts or tools, simplifying the process.
- Ensure RDS Instances Are Not Updated
- The most critical step in this migration is ensuring that AWS RDS Instances (DSDictionaryDB and DSAuditDB) are not recreated or replaced during the stack update. Accidental replacement could lead to data loss.
- Consts Mapping Review:
- EngineVersionPg, EngineVersionMs, EngineVersionMy;
- AuditAuroraEngineVersionPg, AuditAuroraEngineVersionMy;
- ParameterGroupFamilyPg, ParameterGroupFamilyMy, DictionaryParameterGroupFamilyMs;
- AuditParameterGroupFamilyMs, ParameterGroupFamilyPgCluster, ParameterGroupFamilyMyCluster.
- Apply Retention Policies:
- Perform the Stack Update
- Replace the existing CloudFormation stack with the new LT-based template from GitHub.
- Validate the template using AWS CloudFormation’s built-in validation tools to catch any syntax or configuration errors.
- Proceed with the stack update and monitor it closely to ensure that no unintended updates to the RDS Instances occur.
- Migrate Custom Scripts (If Necessary)
- Update Python Scripts for Compatibility (If Necessary)
- Verify Compatibility of Third-Party Tools (If Necessary)
- If third-party tools are installed via User Data scripts, verify with the vendors that these tools are compatible with the new operating systems (RHEL8 or AL2023).
- Install any necessary updates to ensure compatibility with the newer environments.
- Monitor the Stack Update
- After initiating the stack update, monitor the status of the EC2 instances and RDS Instances to ensure that they are not being replaced or recreated.
- Verify that the new instances based on the Launch Template are functioning as expected.
- Perform Post-Migration Testing
- Conduct functional testing to confirm that the DataSunrise application and associated services are working properly.
- Check that the RDS instances (DSDictionaryDB and DSAuditDB) retain their data and are not recreated.
- Ensure that any custom scripts or third-party tools migrated are working correctly on the new instances.
- Terminate Instances Launched Using the Old Launch Configuration (LC)
- Once the new EC2 instances launched from the Launch Template (LT) are confirmed to be running correctly, terminate any EC2 instances still using the old Launch Configuration (LC) resource.
- This final step ensures that the Auto Scaling Group only manages instances created using the new Launch Template, which supports modern features and configurations.
- Rollback Plan
- If any issues arise during the update, initiate a rollback using CloudFormation’s rollback feature to restore the previous stack.
- In case of RDS-related issues, restore data from the snapshots taken before the update.
In the template, the Consts mapping section defines the engine versions and parameter groups for the RDS instances. These parameters include:
Ensure that these values match the actual settings of your existing RDS Instances. Any discrepancies could trigger the replacement of the RDS Instances during the update.
Use the Retain policy for the RDS Instances by specifying DeletionPolicy: Retain in the CloudFormation template. This ensures that the databases are not deleted if the stack attempts to recreate them.
Configure UpdatePolicy to prevent simultaneous replacement of critical resources.
If your current deployment includes custom scripts in the AWS::CloudFormation::Init metadata key, you need to migrate these scripts to the new Launch Template.
For this, review the existing scripts and copy the necessary of them to the corresponding sections of the new Launch Template.
With the new Launch Template, your DataSunrise instances will be running on RHEL8 or Amazon Linux 2023, which use Python 3 by default. If your custom scripts were written in Python 2, they need to be updated for compatibility with Python 3.
Update print statements, replace xrange() with range(), and address other Python 2-specific syntax. Test your updated scripts in a non-production environment to confirm compatibility with Python 3.
Conclusion
Migrating from Launch Configuration (LC) to Launch Template (LT) in DataSunrise can often be a straightforward process if there are no customizations to the stack. In most cases, you can simply replace the existing CloudFormation stack with the pre-built template from GitHub. However, attention must be paid to the RDS Instances (DSDictionaryDB and DSAuditDB), as syncing the Consts mapping section in the template with actual values and applying retention policies is crucial to preventing data loss.
If custom scripts or third-party tools are involved, ensure they are properly migrated and compatible with the new environments. The final step is to terminate any EC2 instances launched using the old Launch Configuration, ensuring a fully up-to-date Auto Scaling Group managed by the Launch Template.
By following these steps and precautions, you can successfully migrate to the new template, leveraging enhanced AWS features while maintaining the integrity of your DataSunrise deployment.