在运行cannot do operation on a non-existent table
并尝试访问用户端点之后得到错误sls offline start
。 serverless.yml文件如下:
service:
name: digital-secret
plugins:
- serverless-dynamodb-local
- serverless-offline # must be last in the list
custom:
userTableName: 'users-table-${self:provider.stage}'
dynamoDb:
start:
migrate: true
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-east-2
iamRoleStatements:
- Effect: Allow
Action:
- 'dynamodb:Query'
- 'dynamodb:Scan'
- 'dynamodb:GetItem'
- 'dynamodb:PutItem'
- 'dynamodb:UpdateItem'
- 'dynamodb:DeleteItem'
Resource:
- { "Fn::GetAtt": ["usersTable", "Arn"] }
environment:
USERS_TABLE: ${self:custom.userTableName}
functions:
app:
handler: index.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'
user:
handler: index.handler
events:
- http: 'GET /users/{proxy+}'
- http: 'POST /users'
resources:
Resources:
usersTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${self:custom.userTableName}
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
谁能帮忙指出这里出了什么问题?我浏览了文档,并在网上找到了许多不同的示例,但我看不出与上面的有所不同。
答案 0 :(得分:1)
serverless-dynamodb-local
文档说custom
块的结构应如下:
custom:
dynamodb:
start:
migrate: true
您有dynamoDb
而不是dynamodb
答案 1 :(得分:1)
如果其他人对此有疑问,我花了数小时试图找出问题所在,这是因为我无意中在serverless.yml中的[r] esources部分遇到了错误的情况
Resources: <-- Needs to be lower case 'r'
Resources:
usersTable:
Type: 'AWS::DynamoDB::Table'
Properties:
...