/conf/dev/dev.json
{
"Other_File": "Development environment"
}
serverless.ts
import type { AWS } from '@serverless/typescript';
// 関数間で共通の環境変数はこちらに定義
const commonEnvironmentVariables = {
Other_File: "${self:custom.otherfile.${self:provider.stage}.Other_File}",
};
const serverlessConfiguration: AWS = {
service: "create-category-collections-api",
frameworkVersion: "2",
custom: {
webpack: {
webpackConfig: "./webpack.config.js",
includeModules: true,
},
otherfile: {
dev: "${file(./conf/dev/dev.json)}",
stg: "${file(./conf/stg/stg.json)}",
prd: "${file(./conf/prd/prd.json)}",
},
},
// Add the serverless-webpack plugin
plugins: ["serverless-webpack", "serverless-jest-plugin"],
provider: {
name: "aws",
runtime: "nodejs12.x",
apiGateway: {
minimumCompressionSize: 1024,
},
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1",
...commonEnvironmentVariables,
},
region: "ap-northeast-1",
stage: "${opt:stage, self:custom.defaultStage}",
},
functions: {
hello: {
handler: "handler.hello",
events: [
{
http: {
method: "get",
path: "hello",
},
},
],
},
},
};
module.exports = serverlessConfiguration;
参考
Serverless Frameworkで環境変数を外部ファイルから読み込み、環境毎に自動で切り替えてみる
https://dev.classmethod.jp/articles/serverless-framework-conf-change/