Search code examples
amazon-web-servicesparse-platformamazon-ec2amazon-elastic-beanstalkparse-server

Run a lot of similar parse servers on AWS Elastic Beanstalk


I have been running a lot of similar parse server apps on AWS Elastic Beanstock. I do not need a lot of computing power just a way to run a lot of parse servers on AWS without having to pay for a separate server for each one. Would there be a way to run multiple apps on one of the parse servers or would there be a way to put multiple parse servers on one instance somehow in Elastic Beanstock? An example of the kind of server I am running can be found at the Parse GitHub page. Thanks!


Solution

  • The way I do it is by putting each parse-server app into its own docker container and then deploying a bunch of different containers on a single "beanstalk" each running on their own port.

    In some cases I use the same code base for multiple apps and in some the code is different. I use https://www.npmjs.com/package/config to manage configuration in all cases, but in cases where the code is the same, I use the env var NODE_APP_INSTANCE to have different config value for different apps.

    simple Dockerfile

    FROM node
    
    # Create app directory
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    
    COPY package.json /usr/src/app/
    RUN npm install
    
    # Bundle app source
    COPY . /usr/src/app
    
    EXPOSE 5000
    
    CMD [ "npm", "start" ]
    

    and a simple Dockerrun.aws.json

    {
      "AWSEBDockerrunVersion": 2,
      "volumes": [ ],
      "containerDefinitions":
        [
          {
            "name": "app1",
            "image": "xxx.dkr.ecr.us-east-1.amazonaws.com/boo/app1:latest",
            "essential": true,
            "memory": 1536,
            "entryPoint": ["node", "index.js"],
            "portMappings":
              [
                {
                  "hostPort": 9091,
                  "containerPort": 9091
                }
              ],
            "environment":
            [
              {
                "name": "NODE_ENV",
                "value": "production"
              }
            ]
         },
         {
            "name": "app2",
            "image": "xxx.dkr.ecr.us-east-1.amazonaws.com/boo/app2:latest",
            "essential": true,
            "memory": 512,
            "entryPoint": ["node", "index.js"],
            "portMappings":
              [
                {
                  "hostPort": 9092,
                  "containerPort": 9092
                }
              ],
            "environment":
            [
              {
                "name": "NODE_ENV",
                "value": "production"
              },
              { "name": "NODE_APP_INSTANCE",
                "value": "app2"
              }
            ]
         },
        ...
    }