Я работаю в проекте без сервера, и у меня возникают проблемы с локальным запуском моего приложения с помощью dynamicodb. Он не создает таблицу данных, поэтому не выполняет корректно начальное число. Что не так с моими конфигурациями?
команда запуска: $ sls offline start --stage dev
сообщение об ошибке:
Serverless: Bundling with Webpack...
Serverless: Watching for changes...
Dynamodb Local Started, Visit: http://localhost:8000/shell
Resource Not Found Exception ---------------------------
ResourceNotFoundException: Cannot do operations on a non-existent table
at Request.extractError (/home/mauricio/dev/project/covid-favor-api/node_modules/aws-sdk/lib/protocol/json.js:51:27)
at Request.callListeners (/home/mauricio/dev/project/covid-favor-api/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/home/mauricio/dev/project/covid-favor-api/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/home/mauricio/dev/project/covid-favor-api/node_modules/aws-sdk/lib/request.js:683:14)
at endReadableNT (_stream_readable.js:1183:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: linux
Node Version: 12.13.0
Framework Version: 1.64.0
Plugin Version: 3.4.0
SDK Version: 2.3.0
Components Core Version: 1.1.2
Components CLI Version: 1.4.0
Файл без сервера:
org: mauriciocoder
app: covid-favor
# We are using JEST for testing: https://jestjs.io/docs/en/getting-started.html - npm test
service: covid-favor-app-api
# Create an optimized package for our functions
package:
individually: true
# Create our resources with separate CloudFormation templates
resources:
# API Gateway Handler
- ${file(resources/api-gateway-handler.yml)}
# DynamoDb Handler
- ${file(resources/dynamodb-handler.yml)}
plugins:
- serverless-bundle # Package our functions with Webpack
- serverless-dynamodb-local
- serverless-offline
- serverless-dotenv-plugin # Load .env as environment variables
custom:
authorizer:
dev:
prod: aws_iam
dynamodb:
stages: dev
start:
port: 8000 # always se port 8000, otherwise serverless-dynamodb-client will not find
migrate: true # creates tables from serverless config
seed: true # determines which data to onload
seed:
domain:
sources:
- table: userAccount
sources: [./resources/migrations/v0.json]
provider:
name: aws
runtime: nodejs10.x
stage: ${opt:stage, 'dev'}
region: us-east-1
# These environment variables are made available to our functions
# under process.env.
environment:
helpTableName: help
userAccountTableName: userAccount
# 'iamRoleStatements' defines the permission policy for the Lambda function.
# In this case Lambda functions are granted with permissions to access DynamoDB.
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:us-east-1:*:*"
# These are the usage plan for throttling
usagePlan:
throttle:
burstLimit: 2
rateLimit: 1
functions: ...
Dynamodb файл обработчика:
userAccount:
Type: AWS::DynamoDB::Table
DeletionPolicy : Retain
Properties:
TableName: userAccount
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
начальный файл v0. json:
{
"Table": {
"TableName": "userAccount",
"KeySchema": [
{
"AttributeName": "userId",
"KeyType": "S"
}
],
"LocalSecondaryIndexes": [
{
"IndexName": "local_index_1",
"KeySchema": [
{
"AttributeName": "userId",
"KeyType": "HASH"
}
]
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
}
}
}
пакет. json
{
"name": "notes-app-api",
"version": "1.1.0",
"description": "A Node.js starter for the Serverless Framework with async/await and unit test support",
"main": "handler.js",
"scripts": {
"test": "serverless-bundle test"
},
"author": "",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/AnomalyInnovations/serverless-nodejs-starter.git"
},
"devDependencies": {
"aws-sdk": "^2.622.0",
"jest": "^25.1.0",
"serverless-bundle": "^1.2.5",
"serverless-dotenv-plugin": "^2.1.1",
"serverless-offline": "^5.3.3"
},
"dependencies": {
"serverless-dynamodb-client": "0.0.2",
"serverless-dynamodb-local": "^0.2.35",
"stripe": "^8.20.0",
"uuid": "^3.4.0"
}
}