Tutorial

How to Migrate a Live Application from AWS EC2 to DigitalOcean

How to Migrate a Live Application from AWS EC2 to DigitalOcean

Introduction

Running a project on AWS EC2 and thinking about making the move to DigitalOcean? Whether you’re looking to reduce infrastructure costs, simplify server management, or gain more control over your environment, this tutorial walks you through a complete migration from EC2 to a DigitalOcean Droplet.

DigitalOcean is known for its developer-friendly approach, offering an intuitive UI, predictable pricing, and powerful features like one-click apps, managed databases, and built-in monitoring. These qualities make it an attractive option for startups, solo developers, and growing teams who want more focus on building and less on managing infrastructure.

This tutorial ensures you can replicate your environment, move files and data securely, and switch your production traffic with confidence, all while minimizing downtime.

This tutorial is particularly useful for developers, IT professionals, and businesses looking to optimize their cloud infrastructure. By migrating from AWS EC2 to a DigitalOcean Droplet, users can benefit from:

  • Cost Efficiency: DigitalOcean offers predictable and often lower pricing compared to AWS, which can significantly reduce infrastructure costs.
  • Simplicity and Ease of Use: DigitalOcean’s user-friendly interface and straightforward setup process make it easier for developers to manage their environments without extensive cloud expertise.
  • Developer-Friendly Features: With features like one-click apps, managed databases, and built-in monitoring, DigitalOcean provides tools that streamline development and deployment processes.
  • Scalability: DigitalOcean’s infrastructure is designed to scale with your needs, allowing you to easily adjust resources as your application grows.
  • Community and Support: Access to a vast community of developers and comprehensive documentation can help troubleshoot issues and optimize your setup.
  • Focus on Development: By reducing the complexity of infrastructure management, developers can spend more time focusing on building and improving their applications.

Prerequisites

Before starting, ensure you have the following:

Optional, but recommended:

  • A staging environment to test the migration.
  • rsync installed on both servers (most are pre-installed)

How to migrate from AWS EC2 to Droplet

Cloud migrations can be complex, but they don’t have to be chaotic. This step-by-step approach gives you a clear, repeatable process for moving a live application from AWS to DigitalOcean.

Historically, developers and businesses have managed migrations using custom scripts, vendor-specific tools, or manual backups, each with trade-offs in complexity, downtime, and risk. This method focuses on simplicity and reliability, using widely supported tools like SSH, rsync, and mysqldump to streamline the process.

And because the migration lands on DigitalOcean, users benefit from a clean, modern infrastructure experience, designed to get you from deployment to scaling faster and with fewer roadblocks.

Step 1 - Assess Your AWS EC2 Setup

Before anything else, identify what you’re running:

  • Check Installed OS: Connect to your EC2 instance via SSH and run the command cat /etc/os-release to display the operating system details.
  • Verify Active Services: Use the command systemctl list-units --type=service --state=running to list all active services. Look for services like Apache, MySQL, or Node.js in the output.
  • Locate Application Files and Configuration: Identify where your application files are stored by checking common directories such as /var/www/html for web applications. Use find / -name 'your-app-name' to locate specific files or directories. Check configuration files in /etc or within your application’s directory.
  • Review Firewall and Security Group Settings: Access the AWS Management Console, navigate to the EC2 Dashboard, and select your instance. Under the “Security” tab, review the security groups associated with your instance. Check inbound and outbound rules to understand the firewall settings. Use sudo iptables -L on the instance to view any local firewall rules.

This helps replicate the environment accurately on DigitalOcean.

Step 2 - Create Your DigitalOcean Droplet

Head to your DigitalOcean Cloud Panel and:

  1. Click Create > Droplets.
  2. Choose your required OS image.
  3. Select a plan that matches your EC2 instance size.
  4. Choose your required datacenter region (typically closest to your users).
  5. Add a login method - either a strong root password or your SSH key (SSH keys are recommended for secure, password-less access).
  6. Set your Droplet’s hostname, add tags if needed, and choose any optional features like Monitoring or Volumes, then create the Droplet.

Once created, note your Droplet’s IP address from the Cloud Panel.

Step 3 - Configure the Droplet

Access your new Droplet using one of the following methods:

  • Using SSH key (recommended for security): If your private key is in the default location (~/.ssh/id_rsa), use:
ssh root@your_droplet_ip
  • If you’re using a key from a non-default location, specify it like this:
ssh -i /path/to/private-key root@your_droplet_ip
  • Using a root password: If you chose password authentication during setup, use that to log in via:
ssh root@your_droplet_ip

After you SSH, install necessary packages, for example:

sudo apt update && sudo apt install nginx mysql-server php -y

(or your specific stack: Node.js, Docker, etc.)

Make sure you replicate any system configurations from your EC2 instance.

Step 4 - Transfer Your Application Files

Use rsync to copy files from EC2 to Droplet:

rsync -avz -e "ssh -i /path/to/aws-key.pem" ubuntu@your_ec2_ip:/var/www/html/ root@your_droplet_ip:/var/www/html/

Why rsync? It’s fast, secure, and preserves permissions.

Step 5 - Export and Import Your Database (if applicable)

If your application uses a database, you’ll need to migrate it from your EC2 instance to your DigitalOcean Droplet. This ensures your application functions correctly in the new environment.

Option 1: Run the Database on Your Droplet

This method is great if you want full control and prefer keeping everything on one server. Just be sure to configure security, backups, and resource limits accordingly. If you choose this route, then follow these steps:

1. Export your database:

For most databases, you’ll first need to create a backup (dump) of your database. Common tools include:

  • MySQL/MariaDB: Use mysqldump to export your database.
  • PostgreSQL: Use pg_dump for PostgreSQL backups.
  • MongoDB: Use mongodump for MongoDB backups.
  • Redis: Use redis-cli to create a snapshot of your Redis data.

2. Transfer the database dump to your Droplet:

After exporting the database, use scp or rsync to securely transfer the backup file from your EC2 instance to your new Droplet:

rsync -avz -e "ssh -i /path/to/aws-key.pem" ubuntu@your_ec2_ip:/path/to/backup.sql root@your_droplet_ip:/root/

3. Import the Database on the Droplet:

Once the file is transferred, follow the same DigitalOcean tutorials above to restore the database into your Droplet’s environment.

As an alternative to self-hosting the database on your Droplet, you can offload that responsibility by using DigitalOcean’s Managed Databases. These are production-ready, fully managed database clusters that offer:

  • Free Daily Backups & Point-in-Time Recovery
  • High Availability with Automated Failover
  • End-to-end security
  • Scaling with Zero Downtime
  • Performance Monitoring & Metrics

To migrate to a Managed Database:

  1. Create a Managed Database: In the DigitalOcean Control Panel, spin up a new Managed Database.
  2. Export & Import Your Data: Use the same backup process as above, then import into your new Managed Database using the provided credentials.
  3. Update Your App’s Config: Change your application’s database connection string to use the connection details from your Managed DB cluster.

Choose the path that best fits your use case. If you’re just testing or running a small project, hosting the DB on your Droplet may be fine. But for anything production-facing, Managed Databases offer serious long-term advantages.

Pro tip: Managed Databases are especially helpful if you’re planning to scale, want better uptime guarantees, or prefer not to worry about backups, patches, or performance tuning.

Step 6 - Update Configuration Files

With your application and database now hosted on DigitalOcean, you’ll need to update your configuration files to reflect the new environment.

1. Web Server Configuration

If you are using Nginx, Apache, or any other web server, make sure that the server block or virtual host files are properly configured. You’ll need to update paths, server names, and possibly SSL certificates. For example, with Nginx, you would edit the configuration file like so:

sudo nano /etc/nginx/sites-available/default

Make necessary changes, such as updating the document root or server name. After updating the configuration, don’t forget to reload or restart Nginx to apply the changes:

sudo systemctl restart nginx

2. Database Connection Strings

Update your application’s database connection strings to point to the correct database host and credentials on the DigitalOcean Droplet. This will involve modifying environment variables or configuration files that store your database connection information.

For example, if your connection string was previously pointing to your EC2 instance, you will now need to update it to point to localhost or the appropriate IP of your Droplet or Managed Database.

3. Environment Variables

If your application relies on environment variables (such as API keys, database credentials, or other configuration settings), make sure these are set on your DigitalOcean Droplet. You can set them directly in your shell profile (~/.bashrc, ~/.bash_profile, or /etc/environment) or in .env files used by your application.

For example, to set a MySQL password environment variable:

export MYSQL_ROOT_PASSWORD='your_password'

Then, load the variables with:

source ~/.bashrc

Step 7 - Test the Application on the Droplet

Before you make your Droplet live, it’s crucial to test your application thoroughly to ensure it works as expected in the new environment. Here are some steps to test:

1. Check File Integrity

Ensure that all your application files were successfully transferred to the Droplet. Check that file permissions are intact and that no files were corrupted during the transfer.

2. Test Database Connectivity

Make sure your application can connect to the new database. If you’re using a web framework, it may be helpful to check for any database errors by examining your application logs or testing database queries directly from the command line.

3. Perform Functional Tests

Test all aspects of your application (front-end, back-end, API, etc.). You can either manually perform these tests or use automated testing tools like Selenium, Postman, or cURL to ensure everything is functioning as expected.

4. Review Logs

Look at system and application logs to check for any errors. You can check system logs with:

sudo journalctl -xe

For application-specific logs, check the log files (e.g., /var/log/nginx/error.log, /var/log/mysql/error.log) or wherever your application stores logs.

Step 8 - Update DNS Settings

Now that you’ve verified your application works on the Droplet, it’s time to update your DNS settings to point to your new server.

1. Access Your Domain Management Portal

Login to the control panel of your domain registrar or where you manage the DNS.

2. Update DNS Records

Modify the A record for your domain to point to your Droplet’s IP address. For example, you would update:

@    A    your_droplet_ip

3. TTL Settings

Set the TTL (Time to Live) value to a low value (e.g., 300 seconds) to ensure DNS changes propagate quickly.

4. Wait for Propagation

DNS changes can take anywhere from a few minutes to 24 hours to fully propagate across the web. In most cases, you’ll start seeing traffic directed to the Droplet within an hour.

Step 9 - Switch Production Traffic to DigitalOcean

Once DNS propagation is complete, and you’re confident everything is working on your new Droplet, you can fully transition your production traffic. Make sure to monitor your application for any potential issues during the transition.

  • Monitor Traffic: Keep an eye on your site’s traffic, especially during the first few hours after the DNS change.
  • Check Performance: Make sure the application performs as expected with live traffic.
  • Optimize Performance: Use DigitalOcean’s monitoring tools and adjust resources (e.g., resizing Droplets, adding backups) as necessary.

Step 10 - Final Clean-Up

Once you’ve confirmed everything is running smoothly on DigitalOcean, it’s time for some final maintenance:

  • Terminate Your EC2 Instance: If you’re no longer using your EC2 instance, shut it down or terminate it to avoid additional costs.
  • Review Security Settings: Double-check your firewall settings and ensure that only necessary ports are open (e.g., 80, 443, and 22 for SSH).
  • Backup Your Data: Consider setting up automatic weekly or daily backups on your new Droplet. You can also take manual Snapshots or use backup services like SnapShooter to secure your data.
  • Plan for Scaling: As your app grows, you may want to scale vertically or horizontally. DigitalOcean provides options for resizing Droplets or adding load balancers to distribute traffic efficiently.

FAQs

1. Why should I migrate from AWS EC2 to DigitalOcean Droplets?

Migrating from AWS EC2 to DigitalOcean Droplets can offer several advantages. DigitalOcean is known for its cost-effective pricing model, which can significantly reduce your cloud expenses. Unlike AWS, which has a complex pricing structure, DigitalOcean provides transparent and predictable pricing, making it easier to manage your budget. Additionally, DigitalOcean’s platform is designed with developers in mind, offering a user-friendly interface and a range of tools that simplify infrastructure management. This can lead to more efficient deployment processes and greater control over your environment, allowing you to focus more on development and less on managing infrastructure.

2. How long does DNS propagation take after updating the DNS settings?

DNS propagation refers to the time it takes for changes to DNS records to be updated across the internet. This process can vary, typically taking anywhere from a few minutes to 24 hours. The duration depends on several factors, including the TTL (Time to Live) settings of your DNS records and the caching policies of ISPs around the world. In most cases, you can expect traffic to start being directed to the new server within an hour, but it’s advisable to monitor the changes to ensure they have fully propagated.

3. What should I do if I encounter issues during the migration?

Encountering issues during migration is not uncommon, but there are several steps you can take to troubleshoot and resolve them. First, examine system and application logs for any error messages that might indicate the source of the problem. These logs can provide valuable insights into what might be going wrong. If you’re unable to resolve the issues on your own, DigitalOcean offers robust support services. You can contact their support team for assistance or utilize their free migration service for qualifying projects, which can help ensure a smooth transition.

4. How can I ensure my application performs well on DigitalOcean?

To ensure optimal performance of your application on DigitalOcean, it’s important to actively monitor its performance using DigitalOcean’s built-in monitoring tools. These tools can help you track resource usage and identify potential bottlenecks. To further enhance performance, consider resizing your Droplets to better match your application’s needs, adding backups to safeguard your data, and implementing load balancers to distribute traffic evenly. These strategies can help maintain high performance levels and ensure your application runs smoothly under varying loads.

5. Is there a way to back up my data on DigitalOcean?

Yes, DigitalOcean provides several options for backing up your data to ensure its safety and availability. You can set up automatic weekly or daily backups, which provide a reliable way to restore your system in case of data loss. Additionally, you can take manual Snapshots of your Droplets, allowing you to capture the current state of your system at any time. For more comprehensive backup solutions, consider using services like SnapShooter, which offer additional features and flexibility in managing your backups on DigitalOcean.

Conclusion

In this guide, you’ve learned how to migrate a live application from AWS EC2 to a DigitalOcean Droplet - from assessing your EC2 setup, creating and configuring your new Droplet, transferring files and databases, to testing and switching over DNS with minimal downtime.

This process helps solve real-world challenges like reducing cloud costs, simplifying infrastructure management, and gaining more control over your deployment environment. Whether you’re running a solo project or scaling a production app, moving to DigitalOcean puts you on a platform that’s built for developers, with straightforward pricing and a streamlined experience.

That said, every application stack is different. Depending on what you’re running - whether it’s a LAMP stack, Node.js app, containerized workloads, or something more complex - there may be additional steps needed to tailor the migration to your specific setup.

Need help? You don’t have to do it alone. If you’d like assistance with your migration, DigitalOcean offers a free migration service for qualifying projects. Our team can help ensure a seamless transition, so you can get up and running on DigitalOcean faster and with confidence.

Good luck with your migration, and welcome to the DigitalOcean community!

Continue building with DigitalOcean Gen AI Platform.

About the author(s)

Shamim Raashid
Shamim RaashidSenior Solutions Architect
See author profile
Category:
Tutorial

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.