Getting Youtube REST API example to run

Hi folks,

I’ve been following the serverless youtube tutorial trying to get the todos example working. I get stuck at the point where I should be able to create a dynamoDB table and save an item by POSTing to the endpoint. The tutorial sets up a DynamoDB table in the YAML as well as the permissions to use it, and also adds a create handler and script to update the table when the end point is hit using the aws-sdk.

It just isn’t working.

This is the tutorial I’m attempting: https://www.youtube.com/watch?v=sAiAK-DmPbs

When I try and use curl to post some data I am getting {“message”: “Internal server error”}.

Viewing the log gives me:
module initialization error: TypeError
at require (internal/module.js:12:17)

I’ve tried to run it locally using serverless invoke (I’m not sure if this should work or not, I’d expect it to get further than it does). It gives me an errorMessage of “Cannot read property ‘DocumentClient’ of undefined”, errorType “TypeError”.

This seems to say that it’s not instantiating the aws-sdk dynamodb object, but I see no reason why it wouldn’t be? I’ve installed it with npm install --save aws-sdk. I’ve included require(‘aws-sdk’) and have done new AWS.DynamoDb.DocumentClient() (which must not be working).

Please help :slight_smile:

Mike

Did you solve this? I had the same problem. The tutorial has a few typos in create.js

Line 5 should be:
const dynamoDb = new AWS.DynamoDB.DocumentClient();

The author wrote “AWS.DynamoDb” with a lowercase “b”
…and around line 37 you need to pass JSON.stringify() the same argument you called dynamoDb.put() with around line 28. They should both be result or results

Hope that helps!