I'm trying to setup a local development instance of my nodeJs application with a local DynamoDB. I've been following the guide from http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.NodeJs.01.html
The project is using typescript so I'm relying on the typescript definitions included with aws-sdk. Unfortunately when I try and update the config to direct to the local dynamoDB I'm getting a transpiler error when running tsc.
Here is a minimal code example to produce the problem.
import AWS = require('aws-sdk');
AWS.config.update({
region: "us-west-2",
endpoint: "http://localhost:8000"
});
let dynamoDb = new AWS.DynamoDB();
which results in this tsc error:
error TS2345: Argument of type '{ region: string; endpoint: string; }' is not assignable to parameter of type 'ConfigurationOptions & ConfigurationServicePlaceholders & APIVersions'.
Object literal may only specify known properties, and 'endpoint' does not exist in type 'ConfigurationOptions & ConfigurationServicePlaceholders & APIVersions'.
Digging into the aws-sdk source I can see that config.d.ts does not include endpoint in the ConfigurationOptions class.
The endpoint property is defined on ServiceConfigurationOptions and can be passed to a client constructor. I believe the intention behind leaving it out of what can be set via AWS.config.update was that endpoint and params only ever apply to one service, whereas setting them globally would apply the same endpoint and bound parameters to all services.
@jeskew Thank you for your explanation for this, makes sense. For others that stumble upon this, here is how I resolved with @jeskew's help.
import AWS = require('aws-sdk');
import {ServiceConfigurationOptions} from 'aws-sdk/lib/service';
let serviceConfigOptions : ServiceConfigurationOptions = {
region: "us-west-2",
endpoint: "http://localhost:8000"
};
let dynamodb = new AWS.DynamoDB(serviceConfigOptions);
let docClient = new AWS.DynamoDB.DocumentClient( {
region: "us-west-2",
endpoint: "http://localhost:8000",
convertEmptyValues: true
});
@jstradli If you just intend to use the document client, you could simplify the code above to:
import AWS = require('aws-sdk');
let docClient = new AWS.DynamoDB.DocumentClient( {
region: "us-west-2",
endpoint: "http://localhost:8000",
convertEmptyValues: true
});
@jeskew yes good catch. I have some other code that I excluded which is calling dynamoDb.createTable(),
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Most helpful comment
@jeskew Thank you for your explanation for this, makes sense. For others that stumble upon this, here is how I resolved with @jeskew's help.