Amazon AWS

Amazon AWS is perfect for the Enterprise customers who wish to have a very robust platform with high availability. It is used and trusted by some of the largest companies in the world to serve as their Cloud infrastructure.

Prerequisites

We assume in this that you already have a MongoDB instance available. We recommend services provided by MongoDB Cloud or Compose which integrates into AWS cloud. A Redis server can be provided by AWS ElasticCache service or through Compose.

Authentication Configuration

The first step in creating an AWS Deployment is to establish an authentication mechanism from your AWS Account into your Docker Hub profile. They way to accomplish this is outlined within the AWS Documentation found @ http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html#docker-images-private.

The steps to get started are as follows.

  • Login to your Docker Hub account via command prompt.
    docker login https://hub.docker.com/r/formio/formio-server
  • Next you will need to copy the contents of the “auths” section of the ~/.docker/config.json file to create a special AWS Authentication file which will look something similar to the following.

    formio.dockercfg

    {
      "https://index.docker.io/v1/": {
        "auth": "[YOUR AUTH KEY GOES HERE]",
        "email": "travis@form.io"
      }
    }
    
  • Next you will find the S3 bucket that Elastic Beanstalk created within your AWS Account. This typically looks like the following when you go to S3 section of your AWS Account.

    If this bucket does not exist, then you may need to create a default Elastic Beanstalk deployment so that it will automatically create this bucket and configure it for Elastic Beanstalk use.

  • Once you get this bucket created, you will now need to add your formio.dockercfg to this bucket and take note of the name of this bucket to configure the Dockerrun.aws.json

Elastic Beanstalk

Now that you have the authentication file in place, you are ready to create your Elastic Beanstalk deployment.

  • Create your Docker deployment file - Within your local machine, create a new file called Dockerrun.aws.json with the contents as follows. The Authentication Bucket and Key should be the bucket name and the file name you uploaded to that bucket with your docker hub configuration.

    Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": "1",
  "Authentication": {
    "Bucket": "elasticbeanstalk-us-east-1-385952297805",
    "Key": "formio.dockercfg"
  },
  "Image": {
    "Name": "formio/formio-server:latest",
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": "80"
    }
  ],
  "Logging": "/var/log/nodejs"
}
  • Create a new Elastic Beanstalk deployment by clicking on the icon in the AWS Dashboard.

  • Next click on “New Application”

  • Next provide the Application name.

  • Now that you have an application created, you will now create a new Environment by clicking on the Actions tab and select New Environment

  • Next select a new “Web Server environment”.

  • Now select the Docker predefined configuration, and then upload your Dockerrun.aws.json file for the Application code, and then select Configure more options.

  • First thing you will want to ensure is that this deployment is configured as a High Availaibility deployment. This will create the Elastic Load Balancers which we will use later.
  • After you have done that, you will now click on the Modify next to Software Settings

  • Next provide the following Environment Variables to configure your instance.

Setting Description Example
MONGO The MongoDB connection string to connect to your remote database. mongodb://:@aws-us-east-1-portal.234.dblayer.com:23423/formio?ssl=true
MONGO_HIGH_AVAILABILITY If your database is high availability (like from Mongo Cloud or Compose), then this needs to be set. 1
ADMIN_EMAIL The default administrator email admin@example.com
ADMIN_PASS The default administrator password [YOUR PASSWORD]
DB_SECRET The database encryption secret [DB SECRET]
JWT_SECRET The secret password for JWT token encryption. [TOKEN SECRET]
PROTOCOL Only use this if you are not behind https (for test environments only) http
  • When you are done, you can now press the Create Environment button at the bottom of the page to build your environment.
  • This will now create a new Environment within AWS for your deployment. You are now ready to attach your Domains to the deployment.

Domain Routing (Route 53)

Now that your Environment is up and running, the next task is to attach a Domain to the Elastic Beanstalk deployment. If you configured the Elastic Beanstalk deployment to use High Availability, then it will have created some Elastic Load Balancers in front of the deployment which you can link the DNS records against.

  • To get started, we will click on Route 53

  • Next, you will need to created a Hosted Zone

  • You will now provide your domain name and then press Create
  • Next, you will create a new Record Set and then provide the following record.
    • *.yourdomain.com
    • Type - A Record
    • Alias - Yes
    • Then select the Elastic Load Balancer as the target.
    • Now press Create
  • When you are done, your routes should look something like the following.

  • Now, you set your domain Nameservers to point to the ones provided by Route 53. Once the domains evaluate, then you should be able to see the deployed API within that domain.