Add a Create Note API

Thank you, that was extremely helpful!

I also found that my environment section was incorrectly indented, and was at the root level of the serverless.yml file instead of under the provider section. Try checking your indentation against this document to see if you need to change the indentation for your environment section.

1 Like

Hi,

Iā€™m having this exact same issue. Iā€™m a complete newbie and I followed the tutorial but did not come across creating these two files. Where am I creating them? In the root directory?
Also, is the folder they are contained in named ā€œ.awsā€? folder name starting with a [dot]?
What is the file extension for both ā€œconfigā€ and ā€œcredentialsā€?

What I did (no joy) is in the attached image.Screenshot 2020-04-20 at 12.33.26

Also, hereā€™s a screenshot of the results when I run ā€œserverless invoke local --function create --path mocks/create-event.jsonā€:

Hi, Help to below error for invoke local

C:\notes-app-api>serverless invoke local --function create --path mocks/create-event.json
Serverless: DOTENV: Could not find .env file.
Serverless: Bundling with Webpack...
SERVERLESS_ENTERPRISE {"origin":"sls-agent","schemaVersion":"0.0","timestamp":"2020-04-25T03:13:39.374Z","requestId":"id","type":"transaction","payload":{"schemaType":"s-span","schemaVersion":"0.0","operationName":"s-transaction-function","startTime":"2020-04-25T03:13:38.071Z","endTime":"2020-04-25T03:13:39.374Z","duration":1297.1348,"spanContext":{"traceId":"id","spanId":"1b947e52-5403-4bd2-8c36-39228743a328","xTraceId":null},"tags":{"schemaType":"s-transaction-function","schemaVersion":"0.0","timestamp":"2020-04-25T03:13:38.071Z","orgId":null,"applicationName":"my-first-app","serviceName":"notes-app-api","stageName":"prod","functionName":"notes-app-api-prod-create","timeout":6,"computeType":"aws.lambda","computeRuntime":"aws.lambda.nodejs.12.16.2","computeRegion":"us-east-2","computeMemorySize":"1024","computeMemoryUsed":"{\"rss\":149118976,\"heapTotal\":113909760,\"heapUsed\":88833080,\"external\":84150790}","computeMemoryPercentageUsed":8.30078125,"computeContainerUptime":11.251332601,"computeIsColdStart":true,"computeInstanceInvocationCount":1,"computeCustomSchemaType":"s-compute-aws-lambda","computeCustomSchemaVersion":"0.0","computeCustomFunctionName":"notes-app-api-prod-create","computeCustomFunctionVersion":"$LATEST","computeCustomArn":null,"computeCustomRegion":"us-east-2","computeCustomMemorySize":"1024","computeCustomInvokeId":null,"computeCustomAwsRequestId":"id","computeCustomXTraceId":null,"computeCustomLogGroupName":"/aws/lambda/notes-app-api-prod-create","computeCustomLogStreamName":"2016/12/02/[$LATEST]f77ff5e4026c45bda9a9ebcec6bc9cad","computeCustomEnvPlatform":"win32","computeCustomEnvArch":"x64","computeCustomEnvMemoryTotal":8507469824,"computeCustomEnvMemoryFree":1743896576,"computeCustomEnvCpus":"[{\"model\":\"Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz\",\"speed\":2712,\"times\":{\"user\":6473656,\"nice\":0,\"sys\":9330437,\"idle\":180784859,\"irq\":619046}},{\"model\":\"Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz\",\"speed\":2712,\"times\":{\"user\":6962109,\"nice\":0,\"sys\":6239781,\"idle\":183386781,\"irq\":146562}},{\"model\":\"Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz\",\"speed\":2712,\"times\":{\"user\":7431953,\"nice\":0,\"sys\":7153453,\"idle\":182003281,\"irq\":125062}},{\"model\":\"Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz\",\"speed\":2712,\"times\":{\"user\":7980078,\"nice\":0,\"sys\":5703531,\"idle\":182905062,\"irq\":106218}}]","eventType":"unknown","eventTimestamp":"2020-04-25T03:13:38.072Z","eventSource":null,"eventCustomStage":"prod","errorId":null,"errorFatal":null,"errorCulprit":null,"errorExceptionType":null,"errorExceptionMessage":null,"errorExceptionStacktrace":null,"transactionId":"1b947e52-5403-4bd2-8c36-39228743a328","tenantId":"jmaws","appUid":"000000000000000000","tenantUid":"000000000000000000","pluginVersion":"3.6.6","totalSpans":1,"traceId":"id"},"logs":{},"spans":[{"tags":{"type":"aws","requestHostname":"dynamodb.us-east-2.amazonaws.com","aws":{"region":"us-east-2","service":"dynamodb","operation":"putItem","requestId":"V0K47BK1OTAJNR2EH4DDUMCFI7VV4KQNSO5AEMVJF66Q9ASUAAJG","errorCode":"ResourceNotFoundException"}},"startTime":"2020-04-25T03:13:38.075Z","endTime":"2020-04-25T03:13:39.366Z","duration":1291}],"eventTags":[]}}
{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":false}"
}

C:\notes-app-api>

I receive the following error message when running serverless invoke local --function create --path mocks/create-event.json . I believe my .env file is setup correctly and I have double checked the dynamoDb region and table name. I am perplexed

Serverless: DOTENV: Loading environment variables from .env:
Serverless:      - SAMPLE_ENV_VAR
Serverless:      - tableName
Serverless: Bundling with Webpack...
{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":false}"
}

.env file

SAMPLE_ENV_VAR=i-am-an-environment-variable
tableName=notes

I figured out the issue. I had my AWS CLI configured to a different user than what I had set up for this tutorial. If you are getting 500s one possible debug path is to go back to the ā€œConfigure the AWS CLIā€ step"

1 Like

Have check path for both fines are verified. But still getting error.
.ENV also updatedā€¦

C:\notes-app-api>serverless invoke local --function create --path mocks/create-event.json
Serverless: DOTENV: Loading environment variables from .env:
Serverless:      - SAMPLE_ENV_VAR
Serverless:      - tableName
Serverless: Bundling with Webpack...
SERVERLESS_ENTERPRISE {"origin":"sls-agent","schemaVersion":"0.0","timestamp":"2020-04-25T12:27:39.879Z","requestId":"id","type":"transaction","payload":{"schemaType":"s-span","schemaVersion":"0.0","operationName":"s-transaction-function","startTime":"2020-04-25T12:27:38.615Z","endTime":"2020-04-25T12:27:39.879Z","duration":1259.5803,"spanContext":{"traceId":"id","spanId":"559188f3-9030-4017-9191-d390b4b35730","xTraceId":null},"tags":{"schemaType":"s-transaction-function","schemaVersion":"0.0","timestamp":"2020-04-25T12:27:38.615Z","orgId":null,"applicationName":"my-first-app","serviceName":"notes-app-api","stageName":"prod","functionName":"notes-app-api-prod-create","timeout":6,"computeType":"aws.lambda","computeRuntime":"aws.lambda.nodejs.12.16.2","computeRegion":"us-east-2","computeMemorySize":"1024","computeMemoryUsed":"{\"rss\":150020096,\"heapTotal\":114569216,\"heapUsed\":89173240,\"external\":81507950}","computeMemoryPercentageUsed":8.30078125,"computeContainerUptime":10.7241707,"computeIsColdStart":true,"computeInstanceInvocationCount":1,"computeCustomSchemaType":"s-compute-aws-lambda","computeCustomSchemaVersion":"0.0","computeCustomFunctionName":"notes-app-api-prod-create","computeCustomFunctionVersion":"$LATEST","computeCustomArn":null,"computeCustomRegion":"us-east-2","computeCustomMemorySize":"1024","computeCustomInvokeId":null,"computeCustomAwsRequestId":"id","computeCustomXTraceId":null,"computeCustomLogGroupName":"/aws/lambda/notes-app-api-prod-create","computeCustomLogStreamName":"2016/12/02/[$LATEST]f77ff5e4026c45bda9a9ebcec6bc9cad","computeCustomEnvPlatform":"win32","computeCustomEnvArch":"x64","computeCustomEnvMemoryTotal":8507469824,"computeCustomEnvMemoryFree":1537216512,"computeCustomEnvCpus":"[{\"model\":\"Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz\",\"speed\":2712,\"times\":{\"user\":6850453,\"nice\":0,\"sys\":9858140,\"idle\":213120906,\"irq\":652796}},{\"model\":\"Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz\",\"speed\":2712,\"times\":{\"user\":7444703,\"nice\":0,\"sys\":6596875,\"idle\":215787640,\"irq\":153593}},{\"model\":\"Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz\",\"speed\":2712,\"times\":{\"user\":7946515,\"nice\":0,\"sys\":7556468,\"idle\":214326250,\"irq\":132828}},{\"model\":\"Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz\",\"speed\":2712,\"times\":{\"user\":8551468,\"nice\":0,\"sys\":6023968,\"idle\":215253796,\"irq\":111187}}]","eventType":"unknown","eventTimestamp":"2020-04-25T12:27:38.615Z","eventSource":null,"eventCustomStage":"prod","errorId":null,"errorFatal":null,"errorCulprit":null,"errorExceptionType":null,"errorExceptionMessage":null,"errorExceptionStacktrace":null,"transactionId":"559188f3-9030-4017-9191-d390b4b35730","tenantId":"jmaws","appUid":"000000000000000000","tenantUid":"000000000000000000","pluginVersion":"3.6.6","totalSpans":1,"traceId":"id"},"logs":{},"spans":[{"tags":{"type":"aws","requestHostname":"dynamodb.us-east-2.amazonaws.com","aws":{"region":"us-east-2","service":"dynamodb","operation":"putItem","requestId":"CJIJ5C8S30ILF9BB99OD3HIBTJVV4KQNSO5AEMVJF66Q9ASUAAJG","errorCode":"ResourceNotFoundException"}},"startTime":"2020-04-25T12:27:38.619Z","endTime":"2020-04-25T12:27:39.872Z","duration":1253}],"eventTags":[]}}
{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":false}"
}

The AWS CLI creates those files. In macOS those files are created in the ~/.aws. Iā€™m not sure why those are getting created inside your app directory. Are you on Windows?

Glad you figured it out.

500 errors are usually from your own code. So you can add a console.log in your code to see whatā€™s going.

1 Like

When I run serverless invoke local --function create --path mocks/create-event.json I get the error below

Serverless: DOTENV: Could not find .env file.

  Serverless Error ---------------------------------------

  Events for "create" must be an array, not an object

Can you post the full error and whatā€™s in mocks/create-event.json?

Hey Jay,

Thanks for the response, I actually figured it out. I had made a mistake in the code. I am going to delete th post.

1 Like

@jayair - Thanks for helpā€¦

// Return status code 500 on error

if (error) {

# By putting this line in create.js will able to get the actual problem
console.log(error);
const response = {
statusCode: 500,
headers: headers,
body: JSON.stringify({ status: false })
};
callback(null, response);
return;

So did you find what the error is?

The table in the DynamoDB was missing and was not created for some reason. The solution was to check that part of the tutorial and create the table again VERY IMPORTANT WHILE LOGGED IN, and it was fixed

1 Like
{
"statusCode": 500,
"headers": {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Credentials": true
},
"body": "{\"status\":false}"
}

I had this error as well, with the message: 'Requested resource not found' even though my DynamoDB table was created and working.

How I fixed it was by going to the serverless.yml file and changing the region from us-east-1 (the default region in the document) to us-east-2, (the region my personal DynamoDB table is from - I got this from the DynamoDB tableā€™s ARN).
provider:

  name: aws

  runtime: nodejs12.x

  stage: prod

  region: us-east-2

Hope this helps.

1 Like

Glad you figured it out.

Looks like this small step is missing:
npm install eslint eslint-plugin-import eslint-plugin-react