By Hyuntaek Park
Senior full-stack engineer at Twigfarm
At Twigfarm, we wanted to host the Label Studio on the AWS Elastic Beanstalk. I googled it for how and found only one article: https://medium.com/@KerleIndia/how-to-host-label-studio-on-aws-elastic-beanstalk-41abcbcced4
It provides a simple method to host the Label Studio on the AWS Elastic Beanstalk but with data persistence problems. The storage is only temporary; login status and files are gone within a few hours.
An alternative solution is to use Heroku. With just a few clicks you can easily deploy the Label Studio application on Heroku. However, we want to control the database and files directly. Thus, we could not give AWS Elastic Beanstalk option.
In this tutorial, I go over how to deploy the Label Studio application on AWS Elastic Beanstalk while keeping persistent storage and separating the database. Custom domains and HTTPs settings are beyond the scope of this tutorial. You can refer to this link for some hints: https://io.twigfarm.net/aws/https-ec2/
Here is a simple diagram of how we host the Label Studio is deployed on AWS Elastic Beanstalk setup.
One thing to note is that here I am using the instances that are as small as possible for the demo purpose. You might need to set up with larger instances and load balancers correctly if you are trying to do the production deployment.
Let us start by setting up the RDS Postgres first.
Go to RDS and create a PostgreSQL database. Leave the settings as default except for the followings:
Then wait for a while until the database creation gets finished.
Go ahead and clone the Label Studio GitHub Repository.
git clone https://github.com/heartexlabs/label-studio.git label-studio-eb
Now that your docker image is ready. Now it is time for the repository setup for the docker image.
Go to “Amazon Elastic Container Services (ECS)”, then choose Repositories under Amazon ECR on your left panel in the AWS console.
Click “Create repository”.
Click “Create repository”.
Once the repository is created, click on “View push commands” and type in the commands as the following:
The following are done sequentially.
After the successful push, you should be able to see the image that was just pushed.
Go to “IAM” in AWS console. Choose “aws-elasticbeanstalk-ec2-role” under Access mangement > Roles. Add “AWSAppRunnerServicePolicyForECRAccess” policy.
Go to EFS (Elastic File System) in the AWS console. Create a file system by clicking the “Create file system” button. Leave all the settings as they were. We create one with the “Standard” storage class.
Make a note of the “File system ID”, which we will need in the next section.
We need to create four files:
Persistent storage is very important since we upload source files and create output files that they should be retained over time and across the users. I chose EFS is pretty consistent and automatically scales.
First of all, create the following directory and a file.
We often deal with large files with more than 10 mb in the Label Studio. We manually need to override default nginx settings so that we can upload large-size files. We need two files to achieve the goal.
You can consult more details about Elastic Beanstalk platform extensions in this link: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
Now that our Elastic Beanstalk configuration files are ready. Let zip them into one file: deploy.zip
Almost done. Let us create an Elastic Beanstalk application to deploy the system.
Go to Amazon Elastic Beanstalk Environments in the AWS console. Start by clicking “Create a new environment”.
It is not over yet. Click the “Configure more options” button to set environment variables for the database. Find the “Software” section and click the “Edit” button. Then scroll down to input environment variables under “Environment properties”
Choose the same VPC as the one That EFS is in.
Choose the default security group since the default security group allows all the incoming traffic. To be more specific, you should choose the security group that opens the 2049 port to connect with the EFS.
Click the “Save” button then “Create environment” button. This will take a few minutes.
Now the environment is ready. Click the “Go to environment” button to see if the application works well.