2

I have a nodejs project with multiple services, web and workers. All these services are in the same repo with only difference being the script used to invoke them.

I want different config for each service but I also want to keep them under 1 repo. I could use environments, but then It would mess my real environments like production, staging etc. How can I use elastic beanstalk for this kind of architecture? Is compose Environments the best solution?

sidoshi
  • 2,040
  • 2
  • 15
  • 30

1 Answers1

1

There are a lot of ways to handle this, each with their pros and cons. What I did in the past was upload my configs to a particular S3 bucket that was normally unreadable by public. I would then create a signed URL (good for the next couple years, or whatever) and set it as an environment variable in the Beanstalk config. Then, in my .ebextensions/01-setup.config (or somewhere similar), I have this:

{
  "container_commands": {
    "copy_config": {
      "command": "curl $CONFIG_URL > conf/config.json"
    }
  }
}

On startup, the container would snag a copy of the config from the S3 bucket, copy it locally, and then the application would start up with this config.

Very simple to maintain.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • What would the architecture be like in beanstalk? Would there be multiple environments for each service? If so how would you handle environments like staging, prod etc? – sidoshi Sep 04 '17 at 07:48
  • @sidoshi Yes, I'd create a separate Beanstalk application for each environment. When you configure it in beanstalk, you specify that `CONFIG_URL` environment variable. That URL will be a signed URL pointing to the config appropriate for that environment. In your S3 bucket, you'll have something like `appname-config-prod.json`, `appname-config-dev.json`, etc. – Brad Sep 04 '17 at 20:00