I’d like to setup my configuration so that I have a single config.json file with different stages in it, like this:
{
"local": {
"username": "abc123",
"password": "mypass",
"database": "localdb",
"host": "localhost",
"dialect": "mysql",
"redishost": "localhost",
"redisport": "46379"
},
"dev": {
"username": "devuser",
"password": "devpass",
"database": "devdb",
"host": "localhost",
"dialect": "mysql",
"redishost": "localhost",
"redisport": "6379"
}
}
The problem I have is how to reference this within serverless.yml. I’ve tried this:
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'dev'}
region: us-west-2
environment:
DB_NAME: ${file(config/config.json):${self:provider.stage}.database}
DB_USER: ${file(config/config.json):${self:provider.stage}.username}
DB_PASS: ${file(config/config.json):${self:provider.stage}.password}
DB_HOST: ${file(config/config.json)${self:provider.stage}.host}
REDIS_HOST: ${file(config/config.json):${self:provider.stage}.redishost}
REDIS_PORT: ${file(config/config.json):${self:provider.stage}.redisport}
But I get an error Invalid variable syntax when referencing file “config/config.json” sub properties Please use “:” to reference sub properties.
I also tried using the “:” instead of “.” to no avail.
Any help would be appreciated. Thanks!
Jon