Reputation: 450
Getting the error cannot do operation on a non-existent table
after running sls offline start
and attempting to access the users endpoint. serverless.yml file is as follows:
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
Can anyone help point out what is wrong here? I've looked through the docs and at many different examples available online, but nothing I can see is different than the above.
Upvotes: 2
Views: 2728
Reputation: 517
If anyone else is having issues with this, I spent hours trying to track down this issue and it was because I inadvertently had the wrong case for the [r]esources section in serverless.yml
Resources: <-- Needs to be lower case 'r'
Resources:
usersTable:
Type: 'AWS::DynamoDB::Table'
Properties:
...
Upvotes: 3
Reputation: 1348
The serverless-dynamodb-local
docs say that the custom
block should be structured like this:
custom:
dynamodb:
start:
migrate: true
You have dynamoDb
instead of dynamodb
Upvotes: 3