Add a Create Note API

Hey,
I have the issue that some other people have, where I run the two commands and nothing happens. I know that serverless is installed correctly. I have my dynamodb table connected in my serverless.yml file. Any ideas of what could be wrong?
I also made sure that I had the correct version of node written into my serverless.yml file
There may be something wrong with how I set up serverless, since when i try typing in “aws s3 ls” the response i get is ‘Connection was closed before we received a valid response from endpoint URL: “https://s3.amazonaws.com/”.’

Oh that’s not good. If your aws commands don’t work then a lot of the other commands aren’t going to work either. Are you not connected to the internet or are you using a proxy?

I was connected to the internet, and for some reason I couldn’t connect to AWS at all. The commands kept on timing out before they had a chance to run. I uninstalled everything and am trying to totally reinstall everything from scratch, and I will see what happens. The only issue that I could think of was that there was something wrong with how python was set up, but I am not sure.

I ended up figuring it out. I am not sure exactly what the issue was, but I think part of the issue was a permissions issue. I had created and done everything in SUDO ( in admin) and so when I tried running it, it just didn’t let me do it. There may have been other things that were the issue along the way, but I think that was the biggest one.

1 Like

Is there a best practice for how to access the DynamoDB table’s region name from outside of the Lambda function in the create.js file?

My question was triggered by this comment:

  • The AWS JS SDK assumes the region based on the current region of the Lambda function. So if your DynamoDB table is in a different region, make sure to set it by calling AWS.config.update({ region: "my-region" }); before initilizing the DynamoDB client.

Hmm I’m not entirely sure what the best practice here is. Typically, you keep your Lambdas in the same region as your Tables. Setting the region in the config is required to use the AWS SDK.

Thank you for this comment! I decided to just move on too and found the updated format much easier to troubleshoot.

In my case I named my DynamoDB table differently than the tutorial - deviating is always risky (case in point) but I wanted the name to be recognizable down the road. For me my TableName in ‘params’ needed to be changed to my edited name

1 Like

I started to follow this tutorial and found myself stuck with 500 error on mocking DynamoDB insert test.

Serverless: Bundling with Webpack...
Time: 439ms
Built at: 04/05/2019 01:33:42
    Asset      Size  Chunks             Chunk Names
create.js  10.1 KiB  create  [emitted]  create
create.js.map  7.14 KiB  create  [emitted]  create
Entrypoint create = create.js create.js.map
[./create.js] 2.36 KiB {create} [built]
[./libs/dynamodb-lib.js] 468 bytes {create} [built]
[./libs/response-lib.js] 762 bytes {create} [built]
[aws-sdk] external "aws-sdk" 42 bytes {create} [built]
[babel-runtime/core-js/json/stringify] external "babel-runtime/core-js/json/stringify" 42 bytes {create} [built]
[babel-runtime/helpers/asyncToGenerator] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {create} [built]
[babel-runtime/regenerator] external "babel-runtime/regenerator" 42 bytes {create} [built]
[source-map-support/register] external "source-map-support/register" 42 bytes {create} [built]
[uuid] external "uuid" 42 bytes {create} [built]


Error: connect ETIMEDOUT 169.254.169.254:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1054:14) {
  message: 'Missing credentials in config',
  errno: 'ETIMEDOUT',
  code: 'CredentialsError',
  syscall: 'connect',
  address: '169.254.169.254',
  port: 80,
  time: 2019-05-03T23:34:57.762Z,
  originalError: {
message: 'Could not load credentials from any providers',
errno: 'ETIMEDOUT',
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2019-05-03T23:34:57.762Z,
originalError: {
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '169.254.169.254',
  port: 80,
  message: 'connect ETIMEDOUT 169.254.169.254:80'
}
  }
}
{
"statusCode": 500,
"headers": {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Credentials": true
},
"body": "{\"status\":false}"
}

I spent a lot of time asking why I was stucked and finally found that AWS-SDK did not read AWS config profiles by default… So I asked it to do so…

export AWS_SDK_LOAD_CONFIG=1; serverless invoke local --function create --path mocks/create-event.json                                                                                       <aws:lab-philippe_philippe_sk5>
Serverless: Bundling with Webpack...
Time: 419ms
Built at: 04/05/2019 01:36:33
    Asset      Size  Chunks             Chunk Names
create.js  10.1 KiB  create  [emitted]  create
create.js.map  7.14 KiB  create  [emitted]  create
Entrypoint create = create.js create.js.map
[./create.js] 2.36 KiB {create} [built]
[./libs/dynamodb-lib.js] 468 bytes {create} [built]
[./libs/response-lib.js] 762 bytes {create} [built]
[aws-sdk] external "aws-sdk" 42 bytes {create} [built]
[babel-runtime/core-js/json/stringify] external "babel-runtime/core-js/json/stringify" 42 bytes {create} [built]
[babel-runtime/helpers/asyncToGenerator] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {create} [built]
[babel-runtime/regenerator] external "babel-runtime/regenerator" 42 bytes {create} [built]
[source-map-support/register] external "source-map-support/register" 42 bytes {create} [built]
[uuid] external "uuid" 42 bytes {create} [built]
{
"statusCode": 200,
"headers": {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Credentials": true
},
"body": "{\"userId\":\"b0cec536-c920-470a-a5fe-6f87089cf634\",\"noteId\":\"49503450-6dfc-11e9-9f07-3fdeebad08db\",\"content\":\"hello world\",\"attachment\":\"hello.jpg\",\"createdAt\":1556926594069}"
}

Hope this can help other guys.

1 Like

Thanks for sharing the details!

When I try to test the create function by invoking it localy, I get this message:

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

  Function "create" doesn't exist in this Service

.....

  Your Environment Information ---------------------------
     OS:                     win32
     Node Version:           10.16.0
     Serverless Version:     1.45.1

I created the create.js file exactly as described in the tutorial. Please, can you help me.

My webpack.config.js contains this:

module.exports = {
  entry: slsw.lib.entries,


But my lib. directory doesn't contain a entries file. When I try to deploy serverless, I get this message:

  Webpack Options Validation Error -----------------------

  Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
   object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function

Your first error is usually related to your serverless.yml, make sure it is properly formatted.

For the second error, make sure this line is at the top of your config const slsw = require("serverless-webpack");. The entries object comes from that.

Hello Jayair and thanks for your reply. For the second hint: I’ve the exact line in my config. I assume my first error is maye driven by the second, since I can’t deploay anything because of that?

Any other idea why I keep getting this error message?

For all the people having problems with credentials:

In create.js add:

import credentials from "./credentials.json"

AWS.config.credentials = credentials;

Add additional file credentials.json

{ "accessKeyId": "aaa", "secretAccessKey": "bbb", "region": "us-east-1" }

I am having an issue where the serverless invoke local command returns empty (not any error code, just returns a command prompt on the next line). I’ve completely reinstalled NPM and Serverless, and reinstalled the starter package to get back to a blank slate with no luck. I noticed that the files default to reference an earlier version of node (8.10) so after getting an empty result from the serverless invoke local command, I tried updating the serverless.yaml and the babelrc file to reference node 8.11.4. I still get an empty response running the invoke local command.

I’m sort of a loss now, with no real next step to fix this. Anyone have any idea of where I can start trouble shooting this?

I’m actually not sure what the issue is. Was it working for you before and it stopped working?

Which version of Node are you using on your machine? And do any serverless commands work for you?

Hi everyone i keep getting this error when i invoke the function , i have double checked my credentials and all is well but for some reason i keep getting this error

Hi everyone i keep getting this error when i invoke the function , i have double checked my credentials and all is well but for some reason i keep getting this error

$ AWS_PROFILE=user1 serverless invoke local --function create --path mocks/create-event.json
Serverless: Bundling with Webpack...
Time: 1011ms
Built at: 07/03/2019 4:55:42 PM
        Asset      Size  Chunks             Chunk Names
    create.js  7.16 KiB  create  [emitted]  create
create.js.map  6.98 KiB  create  [emitted]  create
Entrypoint create = create.js create.js.map
[./create.js] 2.08 KiB {create} [built]
[aws-sdk] external "aws-sdk" 42 bytes {create} [built]
[babel-runtime/core-js/json/stringify] external "babel-runtime/core-js/json/stringify" 42 bytes {create} [built]
[source-map-support/register] external "source-map-support/register" 42 bytes {create} [built]
[uuid] external "uuid" 42 bytes {create} [built]
{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":false}"
}

I am getting error when running ‘AWS_PROFILE’ is not recognised when I run AWS_PROFIKE=myProfile serverless invoke local --function create --path mocks/create-event.json

The status: false response is sent by our code. So you could simply add a console.log in your code to debug which line is causing the error.