Front-End Web & Mobile

How to set up Parse Server on AWS using AWS Elastic Beanstalk

Facebook recently announced that they are shutting down Parse and that users have one year to migrate their apps to alternative infrastructures. We are working closely with Parse to provide a migration path.  AWS offers a variety of features for building and running mobile apps, including user identity, push notifications, storage, content delivery, app testing and mobile analytics.

The purpose of this blog is to show how to set up Parse Server on AWS using AWS Elastic Beanstalk and MongoLab.

Before you begin, you should refer to the Parse migration guide.

STEP 1: Run a Parse Server using AWS Elastic Beanstalk

AWS Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Node.JS, which the Parse Server runs on. You can simply upload your code and Elastic Beanstalk automatically handles the deployment. At the same time, you retain full control over the AWS resources powering your application and access the underlying resources at any time. There is no additional charge for AWS Elastic Beanstalk – you pay only for the AWS resources needed to store and run your applications.

To launch Parse Server on AWS Elastic Beanstalk click on the button below
Deploy to AWS

This will launch the AWS Elastic Beanstalk deployment flow. Please note that the default instance type will be a t2.small as this is the minimum instance type determined to run Parse Server. See here for more info on EC2 pricing.

 

Name your application.

Now click the Review and Launch button. 

If you have not used Elastic Beanstalk before, you may see the following 2 screens requesting permission to setup the Identity and Access Management (IAM) roles, 

 

Click Allow on the pop-up dialog. This step creates an Identity and Access Management Role (IAM Role) that the AWS Elastic Beanstalk service uses to create AWS resources on your behalf.

 

 

Click Next to proceed to the deployment screen. This step creates an instance profile (another IAM Role) for use with EC2 instances. The Parse Server EC2 instances in your AWS Elastic Beanstalk use the credentials provided by the instance profile to communicate with AWS.

 

Click Launch. Your Parse Server is now configured and ready

STEP 2: Set up a Mongo Instance

As suggested by the Parse Migration guide, you’ll need to first migrate your data to MongoDB. You have a number of options on where or how to run your MongoDB, including hosting your own instance on AWS either manually or using a service such as, MongoLab to create a setup for you. Sign up for a MongoLab account if you do not have one already. You will be prompted to verify your account using an email message. After you verify your account, click Create new to create a new database.

Choose AWS as your cloud provider and pick your storage size requirement.  Mongo Lab offers up to 500 MB in its free tier. Name your database and click Create. This will take you back to the dashboard with a success message.

Click on the new database in the menu. You will see a notification in the Mongo lab page asking you to add a user. Add a user and then navigate back to the database page.

Important: Do not select the read only option when adding a user.

You now have the MongoDB URI which you will need to configure your setup. Replace the dbuser and db password parameters with the username and password you just created.

If you face any challenges with your setup, you can email support@mongolab.com

STEP 3: Configure your AWS and MongoLab setup

Within the AWS Elastic Beanstalk console, choose the Software Configuration card in the Configuration tab and scroll down to the environment variables.

In the Property Value text boxes, add your APP_ID and MASTER_KEY values from the Parse Dashboard, and add the MongoLab database URI you generated in the last step.

STEP 4: Check your setup

Post a sample object to the newly deployed setup. Replace the APP_ID with the APP_ID on your Parse Dashboard setup. Replace the hostname in the URL with the URL that is at the top of your Elastic Beanstalk Dashboard.

curl -X POST
-H “X-Parse-Application-Id: APP_ID”
-H “Content-Type: application/json”
-d ‘{“score”:1337,”playerName”:”John Doe”,”cheatMode”:false}’
http://YOUR_EB_PARSE_SERVER_URL/parse/classes/GameScore

Now, fetch the sample object to the newly deployed setup using a GET command. Replace the APP_ID and MASTER_KEY with the APP_ID and MASTER_KEY from your Parse Dashboard setup. Replace the hostname in the URL with the URL that is at the top of your Elastic Beanstalk Dashboard.

curl -X GET
-H “X-Parse-Application-Id: APP_ID”
-H “X-Parse-Master-Key: MASTER_KEY”
http://YOUR_EB_PARSE_SERVER_URL/parse/classes/GameScore

You can use the MongoLab console to verify that the record was created in your new database.

ADVANCED: Updating and Deploying your code

You can use the AWS Elastic Beanstalk Command Line Interface (EB CLI) to deploy and manage code changes.

Follow the set-up instructions for the EB CLI if you do not have it installed already

Follow these steps:

– Create a directory for your project and change your working directory into that directory.

– Run ‘eb init’ to log in and select the application you created through the quick launch link.

– Run ‘eb labs download’. This  will download the code that is running on the AWS Elastic Beanstalk environment to your local folder.

– Make necessary changes to the code.

– Run ‘eb deploy’ to deploy the code to AWS Elastic Beanstalk.

OTHER RESOURCES

If you are interested in migrating from Parse Push to AWS, refer to this tutorial.

To migrate your Mobile Analytics, refer to this guide