无法连接到本地DynamoDB(无服务器框架)

时间:2019-09-17 06:00:41

标签: amazon-dynamodb serverless amazon-dynamodb-local

我正在尝试建立本地DynamoDB,以在WSL中测试我的Lambda函数 serverless.yml 文件如下:

service: my-service

provider:
  name: aws
  runtime: nodejs10.x

  stage: dev
  region: eu-west-1

  environment:
    STAGE: ${opt:stage, self:provider.stage}
    DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}

functions:
  helloWorld:
    handler: ./api/handler.helloWorld
    events:
      - http:
          path: hello
          method: get
          cors: true

plugins:
  - serverless-dynamodb-local
  - serverless-offline

custom:
  dynamodb:
    start:
      port: 8000
      inMemory: false
      migrate: false
      dbPath: .
    stages:
      - dev

resources:
  Resources:
    ItemsDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:provider.environment.DYNAMODB_TABLE}

要启动本地服务器,请执行:

sls offline start

DynaboDB本地服务器已启动,正如我在控制台中看到的以下消息:

Dynamodb Local Started, Visit: http://localhost:8000/shell

我可以导航到Web浏览器外壳。问题是我不能在那里执行任何命令。例如,如果我执行:

dynamodb.createTable(params, function(err, data) {
    console.log("Response")
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

我没有任何回应。

如果我尝试使用 sls dynamodb migration 进行数据迁移,或者在 serverless.yml 文件中执行相同的操作,则会收到以下消息: >

  NetworkingError: socket hang up
    at connResetException (internal/errors.js:559:14)
    at Socket.socketOnEnd (_http_client.js:440:23)
    at Socket.emit (events.js:214:15)
    at Socket.EventEmitter.emit (domain.js:476:20)
    at endReadableNT (_stream_readable.js:1178:12)
    at processTicksAndRejections (internal/process/task_queues.js:77:11)

对问题的根源有任何想法吗?

提前谢谢

0 个答案:

没有答案