I am on the " Add a Create Note API" section and am having trouble with testing the API
the command:
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
tableName='notes'
though in the .yml file is says
# These environment variables are made available to our functions
# under process.env.
I’m assuming this means that in the create.js file, under the params object
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."
Does this mean that I don’t have to set it in the .env file that is included? when I rename this file to not be included in the build it also throws an error. 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.