Saturday 15 April 2017

ConfigError when AWS is configured in a different file (using DynamoDB locally)

I'm trying to use DynamoDB with Alexa SDK by configuring AWS in a separate file.

I have tested that my Alexa skill works by configuring AWS within index.js:

const Alexa = require("alexa-sdk");
const AWS   = require("aws-sdk");
setupDynamoDB();

// my code ...

function setupDynamoDB (alexa) {
    AWS.config.update({
        region: 'us-east-1',
        endpoint: 'http://localhost:8000'
    });
}

I thought it would be fancier if I create the setupDynamoDB() function somewhere else and import it, so I tried it.

index.js:

const Alexa = require("alexa-sdk");
const AWS   = require("./dynamodb").setupDynamo();

dynamodb.js:

const AWS = require("aws-sdk");

module.exports = {
    setupDynamo: function (alexa) {
        AWS.config.update({
            region: 'us-east-1',
            endpoint: 'http://localhost:8000'
        });
    }
    return AWS;
};

Even with the return statement my skill doesn't seem to be able to access the table, which is odd because it seems like (to me, at least) I am defining an already configured AWS object instead of running the two step process (define AWS then configure).

I am using bespoken-tools proxy to test the skill and the error message I get is:

get error: {
    "message": "Missing region in config",
    "code": "ConfigError",
    "time": "2017-04-15T08:38:55.858Z"
}

I haven't tried whether this works on Alexa Simulator because my goal is to make it work with bst anyway. I'm also trying to exploit the built-in support for DynamoDB that Alexa SDK has, hence the simplified configuration process (pretty much all other resources I could find were creating a DynamoDB object, which I don't intend to do).

What am I doing wrong here? The only explanation I can come up with is that the AWS object being returned is different from the one that would have been returned had I defined and called setupDynamoDB() within index.js... But I can't figure out why that would be the case.



via Posh_Pumpkin

No comments:

Post a Comment