我正在尝试在 WSL中设置一个本地 DynamoDB,以测试我的 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 migrate 迁移数据,或者在 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)
对问题的根源有任何想法吗?
先感谢您