0

I've been playing with serverless offline and dynamodb local lately. When I've used websockets - things worked well. Then, I've decided to change protocol to http. Don't know how this can be related, but it's the only change I've did in the code.

Now, I receive error from dynamodb (including output of db command):

Serverless: [AWS dynamodb 400 0.034s 0 retries] query({
  TableName: 'DEVICE_TABLE_DEV',
  KeyConditionExpression: '#id = :id',
  ExpressionAttributeNames: { '#id': 'deviceId' },
  ExpressionAttributeValues: { ':id': { S: 'a1173b07-af44-450b-b709-902c0b011df2' } }
})
ResourceNotFoundException: Cannot do operations on a non-existent table

I've checked existing tables with command:

aws dynamodb list-tables --endpoint-url http://localhost:8042

And I see, that table exists:

{
    "TableNames": [
        "DEVICE_TABLE_DEV",
        "USER_TABLE_DEV"
    ]
}

Then I've printed dynamodb client, and I see, that options provided seems to be correct according to documentation:

DocumentClient {
  options: {
    region: 'localhost',
    endpoint: 'http://localhost:8042',
    attrValue: 'S6'
  },
  service: Service {
    config: Config {
      credentials: [SharedIniFileCredentials],
      credentialProvider: [CredentialProviderChain],
      region: 'localhost',
      logger: [CLI],
      apiVersions: {},
      apiVersion: null,
      endpoint: 'http://localhost:8042',
      httpOptions: [Object],
      maxRetries: undefined,
      maxRedirects: 10,
      paramValidation: true,
      sslEnabled: true,
      s3ForcePathStyle: false,
      s3BucketEndpoint: false,
      s3DisableBodySigning: true,
      s3UsEast1RegionalEndpoint: 'legacy',
      s3UseArnRegion: undefined,
      computeChecksums: true,
      convertResponseTypes: true,
      correctClockSkew: false,
      customUserAgent: null,
      dynamoDbCrc32: true,
      systemClockOffset: 0,
      signatureVersion: null,
      signatureCache: true,
      retryDelayOptions: {},
      useAccelerateEndpoint: false,
      clientSideMonitoring: false,
      endpointDiscoveryEnabled: undefined,
      endpointCacheSize: 1000,
      hostPrefixEnabled: true,
      stsRegionalEndpoints: 'legacy'
    },
    endpoint: Endpoint {
      protocol: 'http:',
      host: 'localhost:8042',
      port: 8042,
      hostname: 'localhost',
      pathname: '/',
      path: '/',
      href: 'http://localhost:8042/'
    },
    _events: { apiCallAttempt: [Array], apiCall: [Array] },
    MONITOR_EVENTS_BUBBLE: [Function: EVENTS_BUBBLE],
    CALL_EVENTS_BUBBLE: [Function: CALL_EVENTS_BUBBLE],
    _clientId: 1
  },
  attrValue: 'S6'
}

This is how I create a client:

const dynamo = new AWS.DynamoDB.DocumentClient({ region: 'localhost', endpoint: 'http://localhost:8042'});

UPDATE: adding my serverless.yml dynamodb section configuration:

dynamodb:
  # If you only want to use DynamoDB Local in some stages, declare them here
    stages:
      - local
    start:
      port: 8042
      inMemory: true
      heapInitial: 200m
      heapMax: 1g
      migrate: true
      seed: true
      convertEmptyValues: true
    # Uncomment only if you already have a DynamoDB running locally
      noStart: true

Would appreciate any advice in this direction.

6
  • List tables by dynamo instead of aws cli. Commented Feb 13, 2021 at 12:00
  • @hoangdv I've did, and I don't see tables. The question is why? What am I missing to target it properly to localhost? Commented Feb 13, 2021 at 12:52
  • region: 'localhost' looks odd to me. I still initialise with the real region even if I'm targeting a local DynamoDB, e.g. { region: 'eu-west-2', endpoint: 'http://localhost:8042'}. Also you have set noStart: true, just to confirm, are you starting your local DynamoDB separately? Did you define your DynamoDB tables in serverless.yml or elsewhere? Commented Feb 13, 2021 at 15:03
  • @yvesonline yes, dynamodb is started separately, initially region was non localhost as well. This is something I've found in official docs. Tables are also defined, but actually, in this case looks like it tries to read from elsewhere, not the defined ednpoint. Commented Feb 13, 2021 at 15:11
  • @yvesonline actually, just double checked without region property. And something changed. Feel free to post answer, at least the above mentioned issue is no longer topical. Commented Feb 13, 2021 at 15:13

1 Answer 1

1

You shouldn't init DynamoDB with region: 'localhost'.

Either leave it out or change it to a proper region, e.g.:

const dynamo = new AWS.DynamoDB.DocumentClient({ region: 'eu-west-2', endpoint: 'http://localhost:8042'});
Sign up to request clarification or add additional context in comments.

Comments

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.