Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments: Add a Create Note API #23

Closed
jayair opened this issue Apr 10, 2017 · 162 comments
Closed

Comments: Add a Create Note API #23

jayair opened this issue Apr 10, 2017 · 162 comments

Comments

@jayair
Copy link
Contributor

jayair commented Apr 10, 2017

Link to chapter - http://serverless-stack.com/chapters/add-a-create-note-api.html

@nerdguru
Copy link

The runtime line in the serverless.yml file should read:

runtime: nodejs6.10

Looks like you updated it for the prior page for Serverless 1.10's support of AWS/Node6 but missed this one. Minor thing but thought you'd want to know.

@jayair
Copy link
Contributor Author

jayair commented Apr 10, 2017

Oh yeah you're right. Just fixed it - 8758786

@geirman
Copy link

geirman commented Apr 14, 2017

When testing the code, I'm getting a 500 response. How do I troubleshoot this?
The only thing I've done differently is change all instances of us-east-1 to us-east-2 to match values I see in my pool id, pool arn, identity pool id, etc. Seemed like the right thing to do.

@jayair
Copy link
Contributor Author

jayair commented Apr 15, 2017

@geirman that would be a DynamoDB related error. Can you try printing out the error object in this line - https://github.com/AnomalyInnovations/serverless-stack-com/blame/master/_chapters/add-a-create-note-api.md#L56

That should give you a clue.

@geirman
Copy link

geirman commented Apr 15, 2017

Thanks, that helped. My problem was naming one of the keys notesId instead of noteId

ValidationException: One or more parameter values were invalid: Missing the key notesId in the item

@flocve
Copy link

flocve commented Apr 17, 2017

Hello,
When I run the command : serverless webpack invoke --function create --path event.json
I have this :

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

content of DynamoDB object :

      Config {
        credentials: null,
        credentialProvider: [Object],
        region: 'eu-west-2',
        logger: null,
        apiVersions: {},
        apiVersion: null,
        endpoint: 'dynamodb.eu-west-2.amazonaws.com',
        httpOptions: [Object],
        maxRetries: undefined,
        maxRedirects: 10,
        paramValidation: true,
        sslEnabled: true,
        s3ForcePathStyle: false,
        s3BucketEndpoint: false,
        s3DisableBodySigning: true,
        computeChecksums: true,
        convertResponseTypes: true,
        correctClockSkew: false,
        customUserAgent: null,
        dynamoDbCrc32: true,
        systemClockOffset: 0,
        signatureVersion: 'v4',
        signatureCache: true,
        retryDelayOptions: {},
        useAccelerateEndpoint: false },
     isGlobalEndpoint: false,
     endpoint: 
      Endpoint {
        protocol: 'https:',
        host: 'dynamodb.eu-west-2.amazonaws.com',
        port: 443,
        hostname: 'dynamodb.eu-west-2.amazonaws.com',
        pathname: '/',
        path: '/',
        href: 'https://dynamodb.eu-west-2.amazonaws.com/' },
     _clientId: 1 },
  attrValue: 'S8' }

And the error is :

 CredentialsError: Missing credentials in config
    at ClientRequest.<anonymous> (/Users/flocve/Sites/labs/notes-app-api/node_modules/aws-sdk/lib/http/node.js:83:34)
    at ClientRequest.g (events.js:291:16)
    at emitNone (events.js:86:13)
    at ClientRequest.emit (events.js:185:7)
    at Socket.emitTimeout (_http_client.js:620:10)
    at Socket.g (events.js:291:16)
    at emitNone (events.js:86:13)
    at Socket.emit (events.js:185:7)
    at Socket._onTimeout (net.js:339:8)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
  message: 'Missing credentials in config',
  code: 'CredentialsError',
  time: 2017-04-17T10:06:21.387Z,
  retryable: true,
  originalError: 
   { message: 'Could not load credentials from any providers',
     code: 'CredentialsError',
     time: 2017-04-17T10:06:21.387Z,
     retryable: true,
     originalError: 
      { message: 'Connection timed out after 1000ms',
        code: 'TimeoutError',
        time: 2017-04-17T10:06:21.386Z,
        retryable: true } } }

I Follow the tutorial (2 times :) ), but impossible to understand what is my problem.
I used the region eu-west-2 instead of us-east-1.

Did I forget something ?

@fwang
Copy link
Contributor

fwang commented Apr 18, 2017

@flocve Could you double check if these two files exist ~/.aws/config and ~/.aws/credentials

~/.aws/config should look like

[default]
region = eu-west-2

~/.aws/credentials should look like

[default]
aws_access_key_id = AKIXXXXGMPQAP123XXXX
aws_secret_access_key = JOsGrXxxXl8o8bXxXxbOf1RoDw2guXXxxXXxx123

@eliocapelati
Copy link

Hello,

Following these steps, I have been getting an error on LAMBDA_PROXY function of api gateway.

the response on request also includes the:

 
   statusCode: 200,
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Credentials': true,
    },
    body: ....

and if a error (500) occur, the status code is 200.

@jayair
Copy link
Contributor Author

jayair commented Apr 22, 2017

@eliocapelati can you show me the full response that you are seeing?

@eliocapelati
Copy link

eliocapelati commented Apr 22, 2017

Here a 404 error... I just changed the 500 to 404...

screen shot 2017-04-22 at 19 33 36

Update 1
Here the code of response-lib...

screen shot 2017-04-22 at 20 25 04

Update 2
And here my function (Ok, this is the get... but the same symptom at all):
screen shot 2017-04-22 at 20 28 31

@jayair
Copy link
Contributor Author

jayair commented Apr 24, 2017

@eliocapelati I'm a bit confused here. According to your code you are throwing the 404 error. That is how it should work right? There is no problem then right?

@deivers
Copy link

deivers commented May 10, 2017

I'm getting:

{ ResourceNotFoundException: Requested resource not found
    at Request.extractError (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/protocol/json.js:48:27)
    at Request.callListeners (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/request.js:673:14)
    at Request.transition (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/request.js:675:12)
    at Request.callListeners (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at Request.emit (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/request.js:673:14)
    at Request.transition (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/request.js:675:12)
    at Request.callListeners (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at callNextListener (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at IncomingMessage.onEnd (/Users/dei/Dev-exploration/serverless-stack/notes-app-api/node_modules/aws-sdk/lib/event_listeners.js:254:11)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
  message: 'Requested resource not found',
  code: 'ResourceNotFoundException',
  time: 2017-05-10T12:45:43.839Z,
  requestId: '9AD2PP6137PVQV7O652HGL5JE3VV4KQNSO5AEMVJF66Q9ASUAAJG',
  statusCode: 400,
  retryable: false,
  retryDelay: 15.609907065688 }

It's not clear to me which resource isn't found.

@vfonsecapv
Copy link

Same problem here @deivers

@jayair
Copy link
Contributor Author

jayair commented May 11, 2017

@deivers @vfonsecapv when are you seeing this error?

@ryanjcruz
Copy link
Contributor

ryanjcruz commented May 13, 2017

$ serverless webpack invoke --function create --path event.json
Serverless: Bundling with Webpack...
Time: 679ms
     Asset     Size  Chunks             Chunk Names
 create.js  4.17 kB       0  [emitted]  create
handler.js  2.28 kB       1  [emitted]  handler
Serverless: Run function create...

  Type Error ---------------------------------------------

     Cannot read property 'handler' of undefined

I'm getting the error above when trying to run the test, not sure where to proceed from here.

Update: OK, my bad, turns out 'functions' isn't aligned correctly and was tabbed, making it a property of provider. Untabbed it and works perfectly!

@jayair
Copy link
Contributor Author

jayair commented May 13, 2017

@ryanjcruz Glad you figured it out. Just noticed somebody else is having a similar issue as well.

@ghost
Copy link

ghost commented May 21, 2017

serverless webpack invoke --function create --path event.json
Serverless: Bundling with Webpack...
Time: 1287ms
Asset Size Chunks Chunk Names
create.js 6.35 kB 0 [emitted] create
handler.js 2.28 kB 1 [emitted] handler
Serverless: Run function create...
{ statusCode: 500,
headers:
{ 'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true },
body: '{"status":false}' }

When I invoke the create function I got the above error, I did everything as mentioned in the tutorial, I couldn't able to trace the error, kindly help me to resolve the issue.
If I change the callback function to ES6 promise then I got the 500 error response before that I got 200 response...

UPDATE: I wrongly passed the arguments name in the dynamodb-lib.js, it works fine now.

@go4cas
Copy link

go4cas commented May 21, 2017

When running serverless webpack invoke --function create --path event.json, I get the following:

Unexpected token import

@go4cas
Copy link

go4cas commented May 21, 2017

Okay, I fixed this with:

npm install --save-dev babel-preset-es2015

And then, changed .babelrc file:

{
  "plugins": ["transform-runtime"],
  "presets": ["react-app","es2015"]
}

@martinsaporiti
Copy link

martinsaporiti commented May 21, 2017

Hi, everyone. I need your help, please!!!

When I running serverless webpack invoke --function create --path event.json the result is this:

	**import _JSON$stringify from 'babel-runtime/core-js/json/stringify';**
	^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at ServerlessWebpack.loadHandler (/Users/sapo/Development/notes/notes-app-api/node_modules/serverless-webpack/lib/run.js:21:20)
    at ServerlessWebpack.run (/Users/sapo/Development/notes/notes-app-api/node_modules/serverless-webpack/lib/run.js:61:26)
    at ServerlessWebpack.tryCatcher (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:638:18)
    at Promise._resolveCallback (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:432:57)
    at Promise._settlePromiseFromHandler (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:524:17)
    at Promise._settlePromise (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/Users/sapo/Development/notes/notes-app-api/node_modules/bluebird/js/release/promise.js:638:18)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:234:22)
    at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:253:17)
    at variables.populateService.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:96:33)
From previous event:
    at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:87:74)
    at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless:23:50)

  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       6.9.4
     Serverless Version: 1.13.2

Thanks!!!

@jayair
Copy link
Contributor Author

jayair commented May 21, 2017

@go4cas That's weird, the react-app preset should handle that already. Can I see your package.json just to make sure things are okay?

@jayair
Copy link
Contributor Author

jayair commented May 21, 2017

@martinsaporiti this looks like the same issue as @go4cas. Let me check what is going on.

@jayair
Copy link
Contributor Author

jayair commented May 21, 2017

@martinsaporiti @go4cas You guys are right, there is an issue with the new react-app preset. I just updated the chapter with the proper presets - 201c881

@martinsaporiti
Copy link

Thanks @jayair and @go4cas ! Now work perfectly:

{ statusCode: 200,
  headers: 
   { 'Access-Control-Allow-Origin': '*',
     'Access-Control-Allow-Credentials': true },
  body: '{"userId":"USER-SUB-1234","noteId":"b605af70-3e93-11e7-8117-312305557adf","content":"hello world","attachment":"hello.jpg","createdAt":1495418979303}' }

I will continue with the tutorial. It's very useful.
Thanks again!

@oliv9286
Copy link

oliv9286 commented Jun 2, 2017

@jayair I'm running into the same problem as @deivers and @vfonsecapv when I run the test with event.json. I do have multiple profiles and I'm not using the default profile in this case. I'm using us-west-2 and I believe I already changed that everywhere in the code. Any clue how I can debug?

@oliv9286
Copy link

oliv9286 commented Jun 2, 2017

nevermind, I figured it out. If you're not using your default profile then in your create.js you need to do
const credentials = new AWS.SharedIniFileCredentials({profile: 'profile_name'}); AWS.config.credentials = credentials;

@jayair
Copy link
Contributor Author

jayair commented Jun 3, 2017

@oliv9286 Thanks for reporting back. Are you setting this in the top of your create.js?

@tobyjo
Copy link

tobyjo commented Jun 5, 2017

I also get the same error as @deivers and @vfonsecapv .

When I run

./node_modules/serverless/bin/serverless webpack invoke --function create --path event.json

I get

Serverless: Run function create...
{ ResourceNotFoundException: Requested resource not found
    at Request.extractError (/home/tjones/note-app-api/node_modules/aws-sdk/lib/protocol/json.js:48:27)
    at Request.callListeners (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:682:14)
    at Request.transition (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/tjones/note-app-api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/tjones/note-app-api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:684:12)
    at Request.callListeners (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at Request.emit (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:682:14)
    at Request.transition (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/tjones/note-app-api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/tjones/note-app-api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/tjones/note-app-api/node_modules/aws-sdk/lib/request.js:684:12)
    at Request.callListeners (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at callNextListener (/home/tjones/note-app-api/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at IncomingMessage.onEnd (/home/tjones/note-app-api/node_modules/aws-sdk/lib/event_listeners.js:256:13)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
  message: 'Requested resource not found',
  code: 'ResourceNotFoundException',

Note that I didnt install the serverless module as global.
I do not have multiple profiles as @oliv9286 did.

@fwang
Copy link
Contributor

fwang commented Jun 7, 2017

@tobyjo can I take a look at your serverless.yml?

@jayair
Copy link
Contributor Author

jayair commented Mar 15, 2018

@nelsoftcom I'm not sure if you didn't paste it properly but it needs to be indented exactly like this https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/serverless.yml

@sarahbohr
Copy link

@jayair I'm running 1.26.1

@nelsoftcom
Copy link

nelsoftcom commented Mar 15, 2018

@jayair Thank you. Passed that level - yes indent was the issue. Now I', getting status code 500

serverless invoke local --function create --path mocks/create-event.json
Serverless: Bundling with Webpack...
Time: 1307ms
    Asset     Size  Chunks             Chunk Names
create.js  6.75 kB       0  [emitted]  create
   [0] ./create.js 2.38 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] external "uuid" 42 bytes {0} [not cacheable]
   [4] ./libs/dynamodb-lib.js 483 bytes {0} [built]
   [5] external "aws-sdk" 42 bytes {0} [not cacheable]
   [6] ./libs/response-lib.js 719 bytes {0} [built]
   [7] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"status\":false}"
}

@jayair
Copy link
Contributor Author

jayair commented Mar 15, 2018

@nelsoftcom This is pretty common and we have a little note at the bottom of the chapter for it - https://serverless-stack.com/chapters/add-a-create-note-api.html#common-issues

@sarahbattey That looks okay. I'm not entirely sure what the issue is. Can you share your directory structure and show me where you are running your command from?

@nelsoftcom
Copy link

@jayair thank you :) create-event and get-event works. thanks for the help.

@sarahbohr
Copy link

sarahbohr commented Mar 16, 2018

@jayair here's a screenshot of my file structure and my serverless.yml too, just in case. I can't thank you enough for your help!

screen shot 2018-03-16 at 9 20 24 am

Edit: ...and a shot of my cli:

screen shot 2018-03-16 at 9 27 11 am

@jayair
Copy link
Contributor Author

jayair commented Mar 16, 2018

@sarahbattey Yeah the structure is a bit weird. Compare it to the one we have in the tutorial - https://github.com/AnomalyInnovations/serverless-stack-demo-api.

And you run your serverless commands at the level where your serverless.yml is.

@sarahbohr
Copy link

@jayair Wow...I have NO idea what happened there. I'm going to restart. This will be my third start (the first try was due to Route 53 and not you)...I'm doing this to get more familiar with AWS and React so every error and every weird thing is a learning experience! Thanks again for everything you've done!

@curtisolson
Copy link

Can you comment on why the functions are async? I would think the simpler approach would be to make calls synchronous unless there is a need for async calls. I'm asking because I wanted to try and reuse some of the basic CRUD functions but am having problems with the async sub functions.

@jayair
Copy link
Contributor Author

jayair commented Apr 3, 2018

@curtisolson I'm not sure if there are synchronous versions of the DynamoDB calls but if there are, then you could use them and not have the Lambda function be async.

@TinCharMan
Copy link

TinCharMan commented Apr 18, 2018

I'm running $ serverless invoke local --function create --path mocks/create-event.json

My return is:

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

It appears to be a permissions/IAM issue:
AccessDeniedException: User: arn:aws:iam::123186399999:user/ is not authorized to perform: dynamodb:PutItem on resource: arn:aws:dynamodb:us-east-1:123186399999:table/notes

I don't want to go in and just start changing permissions. I feel like I'm missing some fundamental lesson or item that I should know before moving on.

Any help would be very much appreciated.

@jayair
Copy link
Contributor Author

jayair commented Apr 20, 2018

@TinCharMan This permission is coming from your serverless.yml. Make sure your iamRoleStatements looks exactly like this - https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/serverless.yml#L23. Including the indentation.

@ahammond
Copy link

ahammond commented May 1, 2018

Based on @oliv9286 's comment, I used the following to set non-default credentials.

diff --git a/libs/dynamodb-lib.js b/libs/dynamodb-lib.js
index f08b4d8..de2b4f0 100644
--- a/libs/dynamodb-lib.js
+++ b/libs/dynamodb-lib.js
@@ -1,6 +1,7 @@
 import AWS from "aws-sdk";

-AWS.config.update({ region: "us-east-1" });
+const credentials = new AWS.SharedIniFileCredentials({profile: 'personal'});
+AWS.config.update({ region: "us-east-1", credentials: credentials });

 export function call(action, params) {
   const dynamoDb = new AWS.DynamoDB.DocumentClient();

@jayair
Copy link
Contributor Author

jayair commented May 2, 2018

@ahammond So this would work when invoking locally but when you deploy the Lambda function won't be able to find the personal credentials (AFAIK). We cover this in the tutorial, you can use this command to invoke locally with non-default credentials.

$ AWS_PROFILE=myProfile serverless invoke local --function create --path mocks/create-event.json

Did that not work for you?

@TinCharMan
Copy link

TinCharMan commented May 6, 2018

Thank you @jayair . Worked!

@abhisheksett
Copy link

abhisheksett commented May 9, 2018

@F-Adam-B Is the issue resolved for you? I'm facing the same problem..

@jayair
Copy link
Contributor Author

jayair commented May 9, 2018

@abhisheksett What's the issue?

@abhisheksett
Copy link

abhisheksett commented May 9, 2018

I was facing the same issue mentioned by @F-Adam-B , saying

error: { Error: connect EHOSTUNREACH 169.254.169.254:80 at Object.exports._errnoException (util.js:1024:11) at exports._exceptionWithHostPort (util.js:1047:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1150:14) message: 'Missing credentials in config',

That got resolved by exporting AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Now I'm getting following error:

{ ResourceNotFoundException: Requested resource not found at Request.extractError (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/protocol/json.js:48:27) at Request.callListeners (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/sequential_executor.js:105:20) at Request.emit (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10) at Request.emit (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/request.js:683:14) at Request.transition (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/request.js:22:10) at AcceptorStateMachine.runTo (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/state_machine.js:14:12) at /Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request.<anonymous> (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/request.js:38:9) at Request.<anonymous> (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/request.js:685:12) at Request.callListeners (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/sequential_executor.js:115:18) at Request.emit (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10) at Request.emit (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/request.js:683:14) at Request.transition (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/request.js:22:10) at AcceptorStateMachine.runTo (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/state_machine.js:14:12) at /Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request.<anonymous> (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/request.js:38:9) at Request.<anonymous> (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/request.js:685:12) at Request.callListeners (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/sequential_executor.js:115:18) at callNextListener (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/sequential_executor.js:95:12) at IncomingMessage.onEnd (/Users/absett/Documents/Work/aws/serverless-stack-demo-api/node_modules/aws-sdk/lib/event_listeners.js:269:13) at IncomingMessage.emit (events.js:164:20) at endReadableNT (_stream_readable.js:1054:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickDomainCallback (internal/process/next_tick.js:218:9) message: 'Requested resource not found', code: 'ResourceNotFoundException', time: 2018-05-09T15:12:35.034Z, requestId: 'JP1ST06JJK9ICKBCU0LIRTGE1NVV4KQNSO5AEMVJF66Q9ASUAAJG', statusCode: 400, retryable: false, retryDelay: 26.28053621862381 } { "statusCode": 500, "headers": { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Credentials": true }, "body": "{\"status\":false}" }

Am I missing any configuration?

@jayair
Copy link
Contributor Author

jayair commented May 9, 2018

@abhisheksett When are you seeing this error?

@abhisheksett
Copy link

I'm getting this error when I'm trying to create a note by following command:

serverless invoke local --function create --path mocks/create-event.json

@jayair
Copy link
Contributor Author

jayair commented May 9, 2018

@abhisheksett This seems like it is complaining about not finding your DynamoDB table. Can I see your create.js?

@jayair jayair closed this as completed May 9, 2018
@jayair jayair reopened this May 9, 2018
@jayair
Copy link
Contributor Author

jayair commented May 9, 2018

@jayair jayair closed this as completed May 9, 2018
@tliut
Copy link

tliut commented May 30, 2020

@jayair,
I just started my serverless framework tutorial and found this very useful so far. Thanks a bunch!

I'm running into this issue when I run:
serverless invoke local --function create --path mocks/create-event.json

Serverless: DOTENV: Loading environment variables from .env:

Syntax Error -------------------------------------------

SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at Object.parseJC [as parse] (/Users/tonyliu/.npm-global/lib/node_modules/serverless/node_modules/json-cycle/cycle.js:136:28)
at parse (/Users/tonyliu/.npm-global/lib/node_modules/serverless/lib/utils/fs/parse.js:22:15)
at /Users/tonyliu/.npm-global/lib/node_modules/serverless/lib/utils/fs/readFile.js:7:58

 For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com

Your Environment Information ---------------------------
Operating System: darwin
Node Version: 12.16.3
Framework Version: 1.71.3
Plugin Version: 3.6.12
SDK Version: 2.3.1
Components Version: 2.30.12

@jayair
Copy link
Contributor Author

jayair commented May 30, 2020

Please post this over on our forums!

https://discourse.serverless-stack.com

@tliut
Copy link

tliut commented May 30, 2020

I'm unable to post on the forums as a new user for now so that's why I posted here....

@jayair
Copy link
Contributor Author

jayair commented Jun 13, 2020

Weird. I think it just got caught by the spam detection. I think I allowed it. Can you post in there now?

@mmjosedaniel
Copy link

mmjosedaniel commented Jul 7, 2020

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

I had this error. It was because I forgot to create the table in DynamoDB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests