Deployment on Elastic Beanstalk
For production deployment, we recommend using Amazon Elastic Beanstalk. This allows auto-scaling based on demand, and easy deployment of multiple version (e.g. from different git branches). Some initial setup is necessary, but it is less complicated than it might look at first. Elastic Beanstalk itself works almost automatically; the main thing needed for it are access credentials. Additionally, we will create a database instance, set up user credentials there, and create an empty CrowdPlay database.
You will need an Amazon AWS account for the following. We will use us-east-1 as the AWS region in these instructions, but you can choose any other region if you prefer.
- Create an IAM user and secret access key. We will first add credentials to allow Elastic Beanstalk deployment, and initialize EB.
- In the AWS web console, go to IAM > Users > Add a user.
- Give the user the AdministratorAccess-AWSElasticBeanstalk, AWSCodeCommitFullAccess, AmazonEC2FullAccess, AmazonS3FullAccess permissions.
- Click the Securiy Credentials tab, and create an access key.
- Save both the key ID and the key itself, you will need them.
- On your local machine, run
pip install awsebcli
and theneb init
in your local repository folder. Enter the key ID and key when asked. When asked, select your chosen AWS region, select Docker, select the latest Amazon Linux, do NOT select CodeCommit, and create an ssh keypair if you’d like (it is easier to create this now than later).
- Create a database instance. Next, we create a database instance.
- In the AWS web console, go to RDS, and click Create Database.
- Select MySQL.
- Put “crowdplay” or another identifier of your choice as the DB instance identifier.
- Put “root” as the master username.
- Tick “Auto Generate Password” or put a secure password of your choice.
- Choose an instance type that fits your expected workload. You could select
db.t2.micro
and choose “Free Tier” for testing. We useddb.r6g.large
in production, but it may be sufficient to use a smaller instance type. - The minimum 20GB provisioned storage should be sufficient for at least 100 hours of stored trajectories. We recommend you enable storage auto-scaling.
- For now, select public availability.
- Once the instance is creating, click “View credential details” and note down the root password, if you had it autogenerated.
- Set up the database. We now create user credentials and an empty database structure for CrowdPlay.
- Edit the database instance’s security group rule to temporarily allow outside access to the DB: In DB details, scroll down to Security Rules, click the inbound one. On the new page, in the lower half pane click Inbound Rules, select the rule, click edit. Note down the current source value, then put
0.0.0.0/0
instead and click Save. - In MySQL Workbench or your SQL client of choice, connect to the new database as root. You’ll find the hostname as “endpoint” in the DB instance details on AWS, and you noted down the root password earlier.
- Click Server > Users and Privilages > Add Account, and add an account named
crowdplay
. Save the password you use. - Then, copy-paste the entire contents of
storage/crowdplaydb.sql
into a new query tab and select Query > Execute All. - You could now disable public access. If you do this, you may need to specifically allow access from your EB application to the database.
- Edit the database instance’s security group rule to temporarily allow outside access to the DB: In DB details, scroll down to Security Rules, click the inbound one. On the new page, in the lower half pane click Inbound Rules, select the rule, click edit. Note down the current source value, then put
- Store credentials. We will now store credentials so they are accessible to the application when it is being deployed.
- On your local machine, create a file named .env in the root directory of the repository and fill credentials in as follows:
MYSQL_ROOT_PASSWORD=mysqlrootpw MYSQL_DATABASE=crowdplaydb MYSQL_USER=crowdplayuser MYSQL_PASSWORD=mysqluserpw MYSQL_HOST=hostname.us-east-1.rds.amazonaws.com
- Deploy your application. We are now ready to deploy the application!
- On your local machine, run
eb create crowdplay --instance_type t2.xlarge --elb-type application
. - If you later make changes and would like to update your running CrowdPlay instance, run
eb deloy
.
- On your local machine, run
- Done! You should now be done, and you should see your environment in the Elastic Beanstalk page on the AWS website. There it will also tell you the URL to access the deployed application.
Further Elastic Beanstalk configuration settings can be found in .ebextensions/options.config
. For instance, you can set the instance types you want CrowdPlay to use. By default, CrowdPlay uses spot instances, which provide significant cost savings at the expense of occasional interruptions for users. This can also be disabled in options.config
.