Finalizing your cloud migration in AWS Migration Hub
Learn how to delete obsolete server data collected by Application Discovery Service in AWS Migration Hub with the help of a Python sample code
Dor Shiloni
Amazon Employee
Published Nov 15, 2024
Last Modified Nov 18, 2024
When you take your first steps in the journey of migrating your workload to AWS, I recommend leveraging AWS’s iterative approach to cloud adoption in migration projects, consisting of 3 main phases - assess, mobilize, migrate & modernize.
As soon as you decided to take off on your journey, I’ll recommend that you look into AWS Migration Hub, an AWS service that serves as a one-stop-shop for working through the different phases of your migration.
AWS Migration Hub plays a key role in running workload discovery as part of the mobilize phase — it offers you access to discovery services, such as AWS Application Discovery Service, for discovering your existing servers and the applications that they are running, plan and track the migration.
You then install the Application Discovery Service agent or agentless collectors, and the collected data is populated into AWS Migration Hub for further analysis and planning of the migration, by grouping the servers as applications, or looking into configuration and performance data of the servers in the scope for the migration.
While working with customers through their migration journeys, I’ve seen instances where customers needed to clear data of servers that they no longer had a need or desire to track through AWS Migration Hub.
As soon as you decided to take off on your journey, I’ll recommend that you look into AWS Migration Hub, an AWS service that serves as a one-stop-shop for working through the different phases of your migration.
AWS Migration Hub plays a key role in running workload discovery as part of the mobilize phase — it offers you access to discovery services, such as AWS Application Discovery Service, for discovering your existing servers and the applications that they are running, plan and track the migration.
You then install the Application Discovery Service agent or agentless collectors, and the collected data is populated into AWS Migration Hub for further analysis and planning of the migration, by grouping the servers as applications, or looking into configuration and performance data of the servers in the scope for the migration.
While working with customers through their migration journeys, I’ve seen instances where customers needed to clear data of servers that they no longer had a need or desire to track through AWS Migration Hub.
In 2023 AWS announced a new set of management actions for Application Discovery Service for deleting resources, and today I’ll be showing you how to leverage those actions to clear data from Application Discovery Service - servers and data collectors, using a sample Python code.
To run the sample code, you will need access to an AWS Identity and Access Management (IAM) user or role that can assume permissions for carrying out these Application Discovery related actions on your AWS account:
- ListConfigurations
- BatchDeleteAgents
- StartBatchDeleteConfigurationTask
The script in this sample code supports clearing resources (server and agent entries that are created by Application Discovery Service and used to represent collected data) according to their application grouping, or tag key and value.
You should aim to clear those resources after decommissioning the servers where you had the Application Discovery Service agent installed, or alternatively - had the agent itself uninstalled.
As long as the Application Discovery Service agent continues running and maintaining communication with the service backend, it will report status as “healthy”, and the script will not be able to clear its resources with data still actively being collected.
It takes up to an hour after the server stops communicating with Application Discovery Service backend, for its agent to show as “unhealthy” in the console, allowing the script to run its course.
I’ve kept an option to forcefully clear resources using the script, however if the agent re-establishes connectivity after clearing the resources - it will simply re-register with Application Discovery Service, requiring another run of the script.
You should aim to clear those resources after decommissioning the servers where you had the Application Discovery Service agent installed, or alternatively - had the agent itself uninstalled.
As long as the Application Discovery Service agent continues running and maintaining communication with the service backend, it will report status as “healthy”, and the script will not be able to clear its resources with data still actively being collected.
It takes up to an hour after the server stops communicating with Application Discovery Service backend, for its agent to show as “unhealthy” in the console, allowing the script to run its course.
I’ve kept an option to forcefully clear resources using the script, however if the agent re-establishes connectivity after clearing the resources - it will simply re-register with Application Discovery Service, requiring another run of the script.
I’ll now show you how to use this sample code to clean the resources created by source servers that I’ve grouped as an application named WebApp in Application Discovery Service using AWS CloudShell, a service that offers you a pre-configured shell environment with a Command Line Interface (CLI) for running AWS CLI commands, Node.JS and Python code that interacts with AWS. In my environment, I’m using an IAM user account that has the permissions needed to run the script, and those are assumed by CloudShell.
I begin by accessing the AWS Migration Hub service console, and accessing the Servers dashboard under Discover from the left-hand side navigation menu, and verifying the servers are grouped as expected:
I will now go ahead and launch an AWS CloudShell instance, and then run ‘
git clone
https://github.com/aws-samples/cleanup-ads-resources.git
’ to clone the sample code’s repository from git to my CloudShell instance.I then change into the directory of the repository, and run the script: ‘
python cleanupads.py -a WebApp -f
’:The script detects the resources, and I type ‘
cleanup
’ to confirm before the script takes actions. Note that I’m using the ‘-f
’ flag to force delete the resources. I recommend that in your case you should use the force flag only if you’re certain that the agent will not re-establish communication with AWS.Also, in your case you might want to use a tag key or value to cleanup the resources, or run the script in unattended mode so you don't have to confirm the cleanup. You can run the script with the
'-h'
flag to see all the possible options.The script had cleaned up the Application Discovery Service resources from Migration Hub:
And there you have it! I’ve successfully cleaned up the console, and if you’ve been able to do the same — you are now ready for your next cloud migration to AWS!
I hope you found this post and sample code useful, let me know what you think in the comments or catch me on LinkedIn.
Looking to learn more about cloud migrations? Come and join me for some Migration Adventures on Twitch!
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.