对于以下AWS SAM模板,process.env是一个空对象。我希望它包含定义为dbURL的模板中的环境变量。
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: "An example RESTful service"
Resources:
ExampleFunction:
Type: "AWS::Serverless::Function"
Properties:
Runtime: "nodejs6.10"
Handler: "/dist/getTickets/index.handler"
Events:
RootDeveloperHub:
Type: "Api"
Properties:
Path: "/new"
Method: "any"
Environment:
Variables:
dbURL: "dbURL_Value"
处理程序
exports.handler = (event, context, callback) => {
// logs {}
console.log(process.env)
}
我排除的事物:
答案 0 :(得分:1)
我应该已经测试了我发布的代码...
设置为时处理程序可以工作
exports.handler = (event, context, callback) => {
// logs {}
console.log(process.env)
}
我的代码的解决方法是将以下内容添加到我的webpack配置中。
{
...
target: 'node'
}