[英]use the stage variable in serverless.yml at handler.js
I'd like to use the variable stage in handler.js
我想在
handler.js
使用变量 stage
serverless.yml无服务器.yml
provider:
name: aws
runtime: nodejs10.x
region: ap-northeast-2
stage: ${opt:stage, "dev"}
...
handler.js处理程序
export const hello = () => {
// I'd like to use the stage in here,
const isDev = stage === 'dev';
return {
statusCode: 200,
body: {
message: `isDev ${isDev}`
}
}
}
If your method of integration is "Lambda Proxy Integration", You should be able to access stage via event.requestContext.stage
.如果您的集成方法是“Lambda 代理集成”,您应该能够通过
event.requestContext.stage
访问 stage。
export const hello = (event) => {
// I'd like to use the stage in here,
console.log('stage is: ', event.context.stage)
const isDev = stage === 'dev';
return {
statusCode: 200,
body: {
message: `isDev ${isDev}`
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.