[英]serverless .yml environment variable issues
I am on this page of a serverless with Lambdas and Dynamo DB exercise.我对这个有lambda表达式和迪纳摩DB锻炼无服务器的页面。
I am on the " Add a Create Note API" section and am having trouble with testing the API the command:我在“添加创建注释 API”部分并且在测试 API 命令时遇到问题:
serverless invoke local --function create --path mocks/create-event.json
produces this error产生这个错误
Serverless: DOTENV: Loading environment variables from .env:
Serverless: - tableName
Serverless: Bundling with Webpack...
error is : ResourceNotFoundException: Requested resource not found
at Request.extractError (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/protocol/json.js:51:27)
at Request.callListeners (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
at Request.emit (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
at callNextListener (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:96:12)
at IncomingMessage.onEnd (/Users/dannybyrne/notes-app-api/node_modules/aws-sdk/lib/event_listeners.js:307:13)
at IncomingMessage.emit (events.js:215:7)
at IncomingMessage.EventEmitter.emit (domain.js:476:20)
at endReadableNT (_stream_readable.js:1183:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
message: 'Requested resource not found',
code: 'ResourceNotFoundException',
time: 2019-12-10T18:33:00.494Z,
requestId: '4D2O3VOI437AE9MTH1M4UPGDUVVV4KQNSO5AEMVJF66Q9ASUAAJG',
statusCode: 400,
retryable: false,
retryDelay: 28.999931507407407
}
{
"statusCode": 500,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true
},
"body": "{\"status\":false}"
}
I have edited the .env file to have我已经编辑了 .env 文件
tableName='notes'
though in the .yml file is says虽然在 .yml 文件中说
# These environment variables are made available to our functions
# under process.env.
environment:
tableName: notes
I'm assuming this means that in the create.js file, under the params object我假设这意味着在 create.js 文件中,在 params 对象下
TableName: process.env.tableName,
In the instructions it says " We read the name of our DynamoDB table from the environment variable using process.env.tableName
. We'll be setting this in our serverless.yml
below. We do this so we won't have to hardcode it in every function."在它说的说明“我们阅读使用环境变量我们DynamoDB表的名称
process.env.tableName
。我们将在我们的可设置该serverless.yml
下面,我们做到这一点,所以我们就不必硬编码在每个功能中。”
Does this mean that I don't have to set it in the .env file that is included?这是否意味着我不必在包含的 .env 文件中设置它? when I rename this file to not be included in the build it also throws an error asking for it.
当我将此文件重命名为不包含在构建中时,它也会抛出一个错误要求它。 When I define tableName in .env and set it to 'notes', as is defined in the .yml file and is the name of the dynamoDB table, it throws the above error.
当我在 .env 中定义 tableName 并将其设置为 'notes' 时,如 .yml 文件中所定义并且是 dynamoDB 表的名称,它会引发上述错误。
I'm basically trying to figure out hoew .yml pull from .env (or not)我基本上是想弄清楚 .yml 从 .env 中拉出(或不)
是的,如果您在提供程序下定义变量,它将可用于所有功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.