1

I'm trying to compete the Node js amazon start guide with DynamoDB. I'm trying to create a table but here is the error I've :

Unable to create table. Error JSON: {
  "message": "Unexpected token h",
  "code": "SyntaxError",
  "time": "2016-05-06T16:59:50.411Z",
  "statusCode": 200,
  "retryable": false,
  "retryDelay": 0

I'm running the following node (taken directly from amazon start guide) :

var AWS = require("aws-sdk");
AWS.config.loadFromPath('./.aws/credentials.json'); 

AWS.config.update({
  region: "us-west-2",
  endpoint: "http://localhost:8000"
});

var dynamodb = new AWS.DynamoDB();

var params = {
    TableName : "Movies",
    KeySchema: [       
        { AttributeName: "year", KeyType: "HASH"},  //Partition key
        { AttributeName: "title", KeyType: "RANGE" }  //Sort key
    ],
    AttributeDefinitions: [       
        { AttributeName: "year", AttributeType: "N" },
        { AttributeName: "title", AttributeType: "S" }
    ],
    ProvisionedThroughput: {       
        ReadCapacityUnits: 10, 
        WriteCapacityUnits: 10
    }
};

dynamodb.createTable(params, function(err, data) {
    if (err) {
        console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
    } else {
        console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2));
    }
});

I've run a local web server on port 8080 based on this tutorial : https://www.youtube.com/watch?v=pU9Q6oiQNd0. It seems to be working fine.

Thanks.

2
  • I'd check that ./.aws/credentials.json is valid JSON (double quoted property names, etc.) Commented May 6, 2016 at 18:19
  • Thanks. Here is what I have in there : { "accessKeyId": "XXXXXXXXXXXXX", "secretAccessKey": "XXXXXXXXXXXXXXXXXXXXXXX", "region": "us-east-1" } Commented May 6, 2016 at 18:42

1 Answer 1

4

You are setting the AWS endpoint to http://localhost:8000. This makes the AWS SDK send AWS API calls to that URL instead of Amazon's servers. Are you sure that's what you want? Unless you're running a version of DynamoDB locally, that will make a request to your own server for each DynamoDB request and try to interpret the result as JSON.

The SDK will usually set the endpoint correctly based on region, so there's generally no need to set it manually. Try configuring AWS without the endpoint setting:

AWS.config.update({
    region: "us-west-2"
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks ataylor. Yeah I'm running DynamoDB locally on port 8000. I'm following the amazon tutorial step by step... just trying to learn.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.