amazon-dynamodb - DynamoDB 表未在 serverless.yml 文件中创建
问题描述
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
谁能帮忙指出这里有什么问题?我浏览了文档和在线提供的许多不同示例,但我所看到的与上面没有什么不同。
解决方案
serverless-dynamodb-local
文档说该块的custom
结构应该是这样的:
custom:
dynamodb:
start:
migrate: true
你有dynamoDb
而不是dynamodb
推荐阅读
- angular - 比较角度反应形式的密码
- cassandra - cassandra中删除的数据像幽灵一样回来了
- java - 无法解析 @androidx.annotation.NonNull ,无法解析方法匿名 android.hardware.camera2
- sql-server-2012 - 我无法使用 SQL Server 数据库图表功能
- c# - 我在 mvc 应用程序中使用地图时遇到问题,地图未显示在视图中,而工作代码中没有错误
- javascript - 从公共位置调用 Angular 组件的 ngAfterViewInit
- javascript - MUI-Datatable 可扩展行
- javascript - 如何合并具有相同键的对象数组
- emacs - 如何在dired-jump中打开由backup-each-save.el创建的备份文件?
- javascript - 如何使用 d3js 在条形图上居中对齐文本标签