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.

  • Generate your docker auth token. To do this, use a base64 encoding tool like https://www.base64encode.net/ or your command line by typing echo -n 'myusername:mypassword' | openssl base64.

  • Enter your docker username, a colon, and your password and press the encode button. For example: ‘myusername:mypassword’.

  • Next you will need to copy the bas64 encoding of your username and password 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.

  • First create a new folder where you will store your deployment files, and call it formio-server
  • Within this folder, 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"
}
  • Now that this is done, you will want to create a new folder within this folder called .ebextensions, within this folder, you will need to create a new file called 01_files.config with the following contents.

    files:
        "/etc/nginx/conf.d/proxy.conf" :
            mode: "000755"
            owner: root
            group: root
            content: |
               client_max_body_size 20M;
    
  • When you are done, your folder should look like the following.

  • Next, select the files within this folder, and then create a new ZIP file with those files. Make sure you create a ZIP of the files, and not the formio-server folder that we created at the beginning of this intro. Rename this file to formio-server.zip. Your folder should look like the following.

  • Next, 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 formio-server.zip 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.

Upgrading Versions

To upgrade the server version running in your AWS elastic beantalk environment, do the following.

  • Update your Docker deployment file - Within your local machine, update the file called Dockerrun.aws.json. You’ll want to change the Image Name field. Leave everything else the same unless you intend to change it. Change out “latest” for the server version you want to run.

    Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": "1",
  "Authentication": {
    "Bucket": "elasticbeanstalk-us-east-1-385952297805",
    "Key": "formio.dockercfg"
  },
  "Image": {
    "Name": "formio/formio-server:5.5.0",
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": "80"
    }
  ],
  "Logging": "/var/log/nodejs"
}
  • Next, in Elastic Beanstalk go to Application versions and click the Upload button.

  • By convention enter the server version number in the Version label (i.e. 5.5.0) that matches the server version in the Dockerrun.aws.json file. Then upload the Dockerrun.aws.json file and click “Upload”.

  • Finally, select the checkbox next to your new version (5.5.0 in this example) and select the Deploy button. Select the environment you want to deploy to and press the Deploy button.

Elastic Beanstalk will now deploy the new server version to your environment. You can roll back to a previous version by selecting it and clicking Deploy again.