我想在handler.js
serverless.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}`
}
}
}
答案 0 :(得分:1)
如果您的集成方法是“ Lambda代理集成”,则您应该能够通过event.requestContext.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}`
}
}
}