Ritu Singh
Does Heroku use AWS? Heruko is a simple and easy to use platform that provide fixed infrastructure which means it is simple to use and deploy. However, it still lack some feature and give you less control over your project. On the other hand, AWS offers more feature and functions, flexibility, and offers wider services. Again for AWS, you need a proper grasp of the basic infrastructure.
If you want to get more control on your infrastructure then you want to migrate from Heruko to AWS. We are assuming that you started off developing infrastructure in Heruko and now want to migrate to AWS.
In this article, we have covered 5 simple steps to migrate from Heruko to AWS.
First and foremost, you need to build serverless AWS application to migrate to. In case, you are looking for PaaS support, Heruko provide similar service. There are few AWS services that you can use. The closes to this is Elastic Beanstalk. After selecting the platform, the EC2 instances will be automatically created without the need of much infrastructure management.
Additionally, AWS Lightsail handles these steps through pre-configured servers which act like virtual private servers. However, you can also develop your EC2 instances. To find the Launch Instance section, head to the dashboard of EC2.
Source: >UseNimbus
Launch your EC2 instance on AWS
This will direct you to the launch page. Here, we have not included details. The default settings is enough if you are not looking for a specific infrastructure. The default Amazon’s AMI is the best way to make a cost-effective system plus the other aspects of the setup will have the application specific. You can create a key pair inside the key pair section and save that key into your machine.
Source: >UseNimbus
Now, you can create a Docker files for the app. Heroku keeps all your code on Github, this means that almost all migration will deal with the configuration and environment. More importantly, Docker make sure that all the work takes place in a stable and consistent environment at the time of migration. Plus, it also helps to setup Docker and do documentation on AWS simpler.
Note that if you’re system is not running on Linux then Docker will run on a virtual machine. Now, this process might take sometime but there are ways to speed up the process.
The following are the points that you need in your Docker:
A Docker file app describing the app
An environment file which includes environment variables as key-value pairs
A web Docker file describing your server
A configuration file for the server.
Source: >UseNimbus
Now, you need to create a Docker Compose file with the name of docker-compose.yml this will help you manage your Docker files. The file will point you towards your database, your environment variables, application, and server containers. All this will depend on your specific stack, however the basic structure will remain the same.
'Db', 'App', and 'Web' services are required. Your "app" service, which in turn depends on your "db" service, will be a prerequisite for your "web" service. While the 'db' simply has to specify the database, the app and web services also need to be constructed from Docker files.
> docker-compose build
Don't forget to read the Docker manual to build for further information on how to set up this Docker file.
The following commands can then be used to start the Docker containers using Docker Compose:
> docker-compose up -d
> docker ps
The best ways to do this is by depending on the stack (for instance, rake for Rails apps). The best way to migrate your database is to easily create a backup along with Heroku CLI, after this change the DATABASE_URL in order to point to your new Database.
Setting up Docker Containers on AWS
We'll be working with the AWS CLI in this section. To set up the CLI, be sure to adhere to the instructions in the manual. After doing that, click Connect and follow the pop-up instructions to SSH into your EC2 instance using the key you already saved on your computer.
Source: >UseNimbus
Connecting to the EC2 instance
Now, run the below given commands in order to set up Docker:
> sudo yum update -y
> sudo yum install git
> sudo amazon-linux-extras install docker
> sudo service docker start
> sudo usermod -a -G docker ec2-user
> sudo curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
> sudo chmod +x /usr/local/bin/docker-compose
> docker-compose --version
Then create your Docker containers:
> cd /var
> sudo mkdir www
> sudo mkdir <app name>
> sudo chown -R ecs-user <app name>
> git clone <source code github repo>
> cd <app name>
Lastly, with the Docker Compose:
> docker-compose build
> docker-compose up -d
You must adjust a few settings before you can enable traffic to the instance. Take notice that this is a fairly simplistic method that will let you get things running and can be supplemented with more specific regulations and best practices. This discusses some security aspects that can get problematic.
Add an inbound rule to your security group that corresponds to the port on your container and permits access from any IP address. The "Security" tab will have this when you click on your instance.
To view your VPCs, click on the VPC ID of your instance. To enable DNS hostnames and enable public DNS names, select Actions > "Edit DNS hostnames" from here.
And that’s it! These are the 5 steps that will help you understand on how to migrate application to AWS.