AWS Mobile Blog

Setting up Parse Server and MongoDB on AWS using CloudFormation

by Akshad Viswanathan | on | Permalink | Comments |  Share

As you may already know, Parse announced it will retire its operations by January 28, 2017. We recently published a step-by-step guide on how to migrate to the Parse Server using AWS Elastic Beanstalk with MongoLab (now mLab). In this blog we cover how to deploy both Parse Server (using Elastic Beanstalk) and a MongoDB instance (with Amazon EC2) within your own VPC on AWS. This solution includes a pre-configured AWS CloudFormation template that is used to build all of the necessary resources for you. Parse is available from https://www.parse.com/​ (LICENSE/PATENTS) and MongoDB is available from https://www.mongodb.org/ (GNU AGPL 3.0 or Commercial)

AWS CloudFormation uses text-based templates to help you model and set up your AWS resources. You can use the CloudFormation template provided in this quickstart to launch a complete stack of AWS resources to run your Parse-based application on AWS. This application can be scaled to meet your requirements. This template offers a “Dev” mode in which the Parse Server and MongoDB are installed on separate EC2 instances with no load balancing or autoscaling. The other (non dev) options build your Parse Server and MongoDB on EC2 instances with load balancing and auto-scaling. In addition, you can choose to build your Parse Server but host your MongoDB using a third-party service like mLab.

Let’s begin with a basic single instance setup with a stand-alone Parse Server on Elastic Beanstalk and a MongoDB instance running on a stand-alone EC2 instance. We call this a Dev mode.

BEFORE YOU START

You need an AWS account with permissions. If you don’t have an AWS account, use the following procedure to create one.

1.Open http://aws.amazon.com/, and then choose Create an AWS Account.

2. Follow the online instructions. Part of the sign-up procedure involves receiving a phone call and entering a PIN using the phone keypad.

You also need an EC2 key pair in the region in which you intend to launch this stack. You’ll provide this key pair name to the CloudFormation stack as a parameter so you can later connect to the instances by using SSH.

 

STEP 1: Launch the CloudFormation stack for a Dev environment

To deploy Parse Server and MongoDB, click the following button 

This brings up the deployment console. Click Next on the Select Template screen.

 It’s time to specify the details of your stack. Begin by providing a name for this stack and for your application.  

For Scale, select Dev. In Database, select MongoDB, and then in MongoDBVolumeSize, select 10GB. In KeyName, select your EC2 key pair. In YourIP, enter your IP address. You use this IP address to connect to your MongoDB instance by using SSH. You can find your IP address at checkip.amazonaws.com or whatsmyip.org. Remember to add /32 to any single domain or use the proper CIDR block notation if you are representing a larger IP address space.


 

Click Next on the Specify Details page. Leave all default settings and click Next on the Options page.

On the next page, review everything you’ve selected, select the acknowledgement checkbox, and click Create.


It will take approximately 5-10 minutes for CloudFormation to provision all of the resources. When all of the resources have been provisioned, you will see two stacks in the CloudFormation console.

Select the Outputs tab for one of the stacks. Here you will find the information required to connect your Parse Sever to your MongoDB database instance. For this final connection, you’ll use the value in MongoDBInstanceDNS for the DATABASE_URI environment parameter within your Parse Server Elastic Beanstalk environment.
 

Note that if you selected Dev for Scale on the Specify Details page of the CloudFormation stack, you’ll see just an IP address as the value for ApplicationEndpoint because only a single stand-alone instance was created. If you selected any scale other than Dev, you’ll see an ELB load balancer HTTP endpoint. This endpoint will be used as your application endpoint. For the MongoDB instance, we are just showing its internal IP Address within the VPC. If you need to access the MongoDB instance externally, you can find the external IP address for this instance in the EC2 console.

STEP 2: Configure your MongoDB instance

At a minimum, you’ll want to connect to your MongoDB instance by using SSH, create a database, and add a new user. You’ll then provide the database name and user credentials in the MongoDB Database_URI application parameter. This parameter is passed to your Parse Server application, which is running on Elastic Beanstalk.

 

STEP 3: Validate

Let’s validate that the Parse Server web application and API are working properly.When the Parse Server is running, you should be able to type the application endpoint into a browser and see the following expected results.

Testing Application

http://<your-parse-environment-name>.elasticbeanstalk.com

Expected Result: “I dream of being a web site.”

Testing Parse API Endpoint

http://<your-parse-environment-name>.elasticbeanstalk.com/parse/

Expected Result: {"error":"unauthorized"}

The typical Parse Server GET test using cURL

curl -X GET -H "X-Parse-Application-Id: <your-appid>" 
http://<your-parse-environment-name>.elasticbeanstalk.com/parse/classes/GameScore 
Expected Result: {“results”:[]}
 

ADVANCED: Modify your stack

If you want to make changes to the resources generated by this stack, you must modify the parent stack (ParseAppTest01 here).

As the load on your application grows, so will the number of instances needed to power it.

You can use the Scale parameter to increase the size of the instance used by your application. You can modify the template or update the running stack and change the selected value for Scale to change the value used by the Elastic Beanstalk environment. Be aware that updating the value in the stack will also impact the database instance. This will cause downtime for your application. If you are testing different scale options, we suggest that you first build up a parallel stack, sync the database data between new and old, and then configure DNS to point to the new application endpoint.

If you choose to use the MongoDB instance built by this stack, there are a few key things you need to be aware of. The first is that, just like any database software, MongoDB is both sophisticated and complex with many configurations and capabilities. For production uses you’ll want to think about securing the instance further, backing up your database’s data, and potentially creating a High Availability (HA) cluster. The MongoDB on the AWS Cloud Quick Start Guide describes some of the ins and outs of managing MongoDB on AWS.

RESOURCES:

The Parse Server application is an EC2 instance (with an ELB load balancer and Auto Scaling, if configured) that is managed by Elastic Beanstalk. You can manage your Parse Server using the Elastic Beanstalk console or Elastic Beanstalk CLI.

Your MongoDB (if you integrated it into your solution) is a stand-alone EC2 instance but it is not managed by Elastic Beanstalk. The MongoDB instance is in the same VPC as your Elastic Beanstalk Parse Server application and is not accessible from the internet, except for the IP address that you whitelisted via the CloudFormation stack.

You can manage the MongoDB EC2 instance with the Amazon EC2 console. To manage the MongoDB database itself, you should log in to the instance directly by using SSH.