Trying to set up a Meteor on an AWS/EBS (Amazon Web Services, Elastic Beanstalk) environment.
A Meteor dev-run can be passed a command line flag: --settings s
After discussing this issue with AWS support I realized that AWS/EBS does not support storing JSON in environment variables. This is because the environment variables are stored as key/value strings in unencoded JSON (apparently, in CloudFormation). The bottom line here a bit disappointing:
This is indeed unfortunate, however there are a couple of workarounds.
Move the json configs into an s3 bucket and place the following content in a .ebextensions/app.config file:
container_commands:
01_setvariable:
command: "aws s3 cp s3:///nodejs.conf /tmp/deployment/config/#etc#init#nodejs.conf
This will entirely override /etc/init/nodejs.conf with content retrieved from your s3 bucket. Naturally there's an opportunity to set/override individual settings using fine-tuned/fancy bash scripting.
I ended up not choosing this method, because it involves another entity (an S3 bucket) and the dev iteration requires a new version deploy, which isn't terribly fast.
Note: this is a simple code-hack I came up with. It seems to put all this mess behind while not requiring much effort.
My original need was to propagate AWS/EBS env vars to the client, so I decided to bypass the METEOR_SETTINGS variable and populate Meteor.settings.public directly with env vars from node's process.env space. The whitelisting is managed by a simple list. Add a server/lib/config.js file with:
Meteor.startup(function () {
// public settings that need to be exposed to the client can be added here
var publicEnvs = {
S3_PATH: 's3path'
};
var modified;
_.each(publicEnvs, (value, key) => {
let envValue = process.env[key];
if (envValue) {
Meteor.settings.public[value] = envValue;
modified = true;
}
});
if (modified) {
__meteor_runtime_config__.PUBLIC_SETTINGS = Meteor.settings.public;
}
});
Hurray, your client can access the env vars of your choice!
For example with this change, an S3_PATH environment variable defined in the EBS console can be accessed as Meteor.settings.public.s3path on the client. Quite simple, and without many moving parts :)