serverless.yml
ํ์ผ์์ site_config: ${file(./config/${opt:stage}/site.yml)}
๊ตฌ๋ฌธ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋์ค์ ์๋ฒ๋ฆฌ์ค ํ์ผ (์ : site_secret_key: ${self:site_config.site_secret_key}
)์์ ์ฐธ์กฐ๋๋ ๋ณ์๊ฐ process.env.site_secret_key
์์ [Object object]
./config/${opt:stage}/site.yml
ํ์ผ์ site_secret_key
๊ฐ๊ณผ ์ฐ๊ด๋ ๋ฌธ์์ด ๊ฐ์ด์ด์ผํฉ๋๋ค.
๋ค์ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ๋ฉด ์ฌ๋ฐ๋ฅด๊ฒ ์๋ํฉ๋๋ค.
${file(./config/${opt:stage}/site.yml):site_secret_key}
๋ฌธ์ ๋ฅผ ๋ณด์ฌ์ฃผ๋ ๋ด ๊ตฌ์ฑ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
service: test-service
plugins:
- debug-plugin
config: ${file(config.json)}
configEnv: ${file(config.json):env}
configEnvProp: ${file(config.json):env.development}
provider:
name: aws
stage: development
runtime: nodejs4.3
environment:
NODE_ENV: ${self:provider.stage}
fileConfig: ${file(config.json)}
fileConfigEnv: ${file(config.json):env}
fileConfigEnvProp: ${file(config.json):env.development}
selfConfig: ${self:config}
selfConfigEnv: ${self:configEnv}
selfConfigEnvProp: ${self:configEnvProp}
selfConfigDotEnv: ${self:config.env}
selfConfigDotEnvDotProp: ${self:config.env.development}
functions:
hello:
handler: handler.hello
serverless
parent prop์์ด serverless.service
๋คํํ๋ ํ๋ฌ๊ทธ์ธ์ ์์ฑํ์ต๋๋ค.
% sls debug config
{ service: 'test-service',
provider:
{ name: 'aws',
stage: 'development',
runtime: 'nodejs4.3',
environment:
{ NODE_ENV: 'development',
fileConfig:
{ env:
{ development: { region: 'ap-northeast-2' },
production: { region: 'us-west-1' } },
assets: { bucket: 'some-bucket' } },
fileConfigEnv:
{ development: { region: 'ap-northeast-2' },
production: { region: 'us-west-1' } },
fileConfigEnvProp: { region: 'ap-northeast-2' },
selfConfig: undefined,
selfConfigEnv: undefined,
selfConfigEnvProp: undefined,
selfConfigDotEnv: {},
selfConfigDotEnvDotProp: undefined },
region: 'us-east-1',
variableSyntax: '\\${([ :a-zA-Z0-9._,\\-\\/\\(\\)]+?)}' },
defaults:
{ stage: 'development',
region: 'us-east-1',
variableSyntax: '\\${([ :a-zA-Z0-9._,\\-\\/\\(\\)]+?)}' },
custom: undefined,
plugins: [ 'debug-plugin' ],
functions:
{ hello:
{ handler: 'handler.hello',
events: [],
name: 'test-service-development-hello' } },
resources: undefined,
package: {} }
๊ทธ ๊ฒฐ๊ณผ์ ์์ธ์ด ๋ฌด์์ธ์ง ํ์คํ์ง ์์ต๋๋ค!
์ฐธ์กฐ ์ฉ ํ๋ฌ๊ทธ์ธ ์์ค :
class Debug {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.commands = {
debug: {
usage: 'Debugging',
commands: {
config: {
usage: 'Show configuration value',
lifecycleEvents: [
'print'
]
}
}
}
};
this.hooks = {
'debug:config:print': () => this.printConfig(),
};
}
printConfig() {
const config = Object.assign({}, this.serverless.service);
delete config.serverless;
const output = require('util').inspect(config, { colors: true, depth: null });
console.log(output.substring(0, 100000)); // Paranoia: can't kill node sync output on Ubuntu on Windows?
}
}
module.exports = Debug;
@simonbuchan ๋ฌธ์ ๊ฐ ๋ณ์ ์ฐธ์กฐ์ ๋ํด ์ ์๋์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ ์ด์ ๋ config
, configEnv
& configEnvProb
์์ฑ์ด ํจ์ ๋ฐ ๋ฆฌ์์ค ๋ฐ๋ก ์์ serverless.yml
์ ์ฒซ ๋ฒ์งธ ๋ถ๋ชจ๋ก ์ ์๋์ด ์๊ธฐ ๋๋ฌธ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. . ์ ํํ ๊ธฐ์ตํ๋ค๋ฉด serverless.yml
์ฌ์ฉ์ ์ง์ ์์ฑ์ ์ ํ์ ๋์ด custom
์์ฑ ๋ด์์๋ง๋ก๋๋๋๋กํฉ๋๋ค. ๋ฐ๋ผ์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉ์ ์ง์ ์์ฑ์ custom
๊ฐ์ฒด๋ก ์ด๋ํ ์ ์์ต๋๋ค.
custom:
config:
configEnv:
...
๊ทธ๋ฆฌ๊ณ ์ฐธ์กฐ๋ฅผ ์ ๋ฐ์ดํธํ๋ ๊ฒ์ ์์ง ๋ง์ญ์์ค
@eahefnawy ๊ฐ ์์์ ์ ์ํ๋๋ก ๋ณ์๋ฅผ custom
์ค์ฒฉํด์ผํ๋ฏ๋ก ์ข
๋ฃ
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ฌธ์ ๋ฅผ ๋ณด์ฌ์ฃผ๋ ๋ด ๊ตฌ์ฑ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
serverless
parent prop์์ดserverless.service
๋คํํ๋ ํ๋ฌ๊ทธ์ธ์ ์์ฑํ์ต๋๋ค.๊ทธ ๊ฒฐ๊ณผ์ ์์ธ์ด ๋ฌด์์ธ์ง ํ์คํ์ง ์์ต๋๋ค!
์ฐธ์กฐ ์ฉ ํ๋ฌ๊ทธ์ธ ์์ค :