This guide comprises a CloudFormation template and demo instructions on how to migrate a web server to a new EC2 instance using Application Migration Service (MGN).
We will deploy a 'source server', then install the Application Migration Service agent on the source server and configure MGN to launch and cutover to a new instance.
While this template does deploy an instance (our source server) to AWS, it is also representative of having a server hosted in any number of other manners, including on-premise.
- Ensure you have an AWS account to deploy into. Configure your terminal so you can run AWS CLI commands in this account.
- Create an EC2 key pair (
RSA
and.pem
) in the console with the namemgn_demo
. If you use a different name, pass this as theEc2KeyPairName
parameter in step 6.While we do not intend to SSH to the instance in this guide, it can be useful to have SSH access for debugging purposes. System Manager is also configured to gain access to the EC2 terminal using Session Manager.
- Set up a user for the MGN agent. Follow this guide and get your access key ID and secret access key: https://docs.aws.amazon.com/mgn/latest/ug/credentials.html
- Pass in key ID and secret access key values using the supplied
MgnUserAccessKeyId
andMgnUserSecretAccessKey
parameters in step 6. - Configure the Application Migration Service in the console:
- Staging area subnet: Select the VPC and Subnet prefixed
TargetVpc*
in your account. - Leave all other settings as default values
- Staging area subnet: Select the VPC and Subnet prefixed
- Deploy the stack:
aws cloudformation create-stack \ --stack-name mgn-demo \ --capabilities CAPABILITY_NAMED_IAM \ --template-body file://mgn_demo.yml \ --parameters \ ParameterKey=Ec2KeyPairName,ParameterValue=<keypair-name> \ ParameterKey=MgnUserAccessKeyId,ParameterValue=<AccessKeyId> \ ParameterKey=MgnUserSecretAccessKey,ParameterValue=<SecretAccessKey>
- Wait for the instance to appear as a source server in the Application Migration Service console and complete the initialization. You'll know it's completed once the
Next step
isLaunch test instance
. MGN can take 20-30 minutes to get to this stage.You can look at the user data in the CloudFormation template to see how this happens automatically. We install and start Apache to simulate a web server, and then we install the MGN agent and pass AWS credentials to it in order to connect to the MGN console in our account.
- Once the source server has
Next step
asLaunch test instance
in the MGN console, modify the launch template for the source server in the MGN console (select source server >Launch settings
>EC2 Launch Template
>Modify
):
- Amazon machine image (AMI): Don't include in launch template
- Instance type:
t2.micro
(change this from the defaultc4.large
) - Key pair (login): Don't include in launch template
- Network settings (Networking platform): Virtual Private Cloud (VPC)
- Network settings (Security groups): leave blank (we will select the security group in the
Network interfaces
section) - Storage (volumes): leave as default
Volume 1
- Resource tags: leave as default (MGN adds some tags)
- Network interfaces (subnet):
TargetVPC-subnet
- Network interfaces (security groups):
mgn-demo-TargetEc2SecurityGroup
- Network interfaces (Auto-assign public IP):
Enable
- Advanced details: No changes
- Set the launch template's default version to be the new version you just created (creating a new version of a launch template does not automatically set that new version to be the default version; you need to do this manually after creating the new version).
- Back in the MGN console, you should see the launch template for your source server automatically update to show the new instance type, security group and subnet. Choose
Test and Cutover
>Launch test instances
>Launch
to create a new test instance. This step can take a while (10-20 minutes). You can click on the "job" to view the job log as the instance launches. - You will eventually see the test instance has been launched. Head to
http://<new instance IP address>
and check that you can see the Apache welcome page. This shows that the server has successfully replicated. - On the source server page in the MGN console, head to
Test and Cutover
>Mark as "Ready for cutover"
. Leave the checkbox checked (to terminate the test instance) and pressContinue
to mark the instance asReady for cutover
. - You may need to modify the launch template again at this point. Change the version back to the version that you created earlier, where the instance type was
t2.micro
. - When you are ready to complete the cutover, click on
Test and Cutover
>Launch cutover instances
>Launch
.You may receive the error
One or more of the Source Servers included in API call are currently being processed by a Job
. This means that the instance is not yet ready for cutover as the test instance is still being terminated. Wait a couple of minutes, then try again. You can click on the cutover job ID to view the progress of launching the cutover instance. - Once the instance is launched, finalize the cutover by heading to
Test and Cutover
>Finalize cutover
>Finalize
. - The final step is to terminate the old instance and check the website hosted by the new instance. We can now say we have successfully migrated an instance using the Application Migration Service!
aws cloudformation create-stack \
--stack-name mgn-demo \
--capabilities CAPABILITY_NAMED_IAM \
--template-body file://mgn_demo.yml \
--parameters \
ParameterKey=Ec2KeyPairName,ParameterValue=<keypair-name> \
ParameterKey=MgnUserAccessKeyId,ParameterValue=<AccessKeyId> \
ParameterKey=MgnUserSecretAccessKey,ParameterValue=<SecretAccessKey>
aws cloudformation update-stack \
--stack-name mgn-demo \
--capabilities CAPABILITY_NAMED_IAM \
--template-body file://mgn_demo.yml \
--parameters \
ParameterKey=Ec2KeyPairName,ParameterValue=<keypair-name> \
ParameterKey=MgnUserAccessKeyId,ParameterValue=<AccessKeyId> \
ParameterKey=MgnUserSecretAccessKey,ParameterValue=<SecretAccessKey>
aws cloudformation delete-stack --stack-name mgn-demo
aws cloudformation create-stack --stack-name mgn-demo --capabilities CAPABILITY_NAMED_IAM --template-body file://mgn_demo.yml ParameterKey=theparametername,ParameterValue=theparametervalue