Я создал проект SAM «Быстрый старт: веб-сервер» AWS, который включает таблицу DynamoDB с использованием sam init sam-app
.
Следуя инструкциям в файле readme, когда я пытаюсь создать и вызвать лямбда-функция, которая ссылается на таблицу Dynamo:
sam build
sam local invoke getAllItemsFunction --event events/event-get-all-items.json
Я получаю Requested resource not found
ошибку:
Invoking src/handlers/get-all-items.getAllItemsHandler (nodejs12.x)
Fetching lambci/lambda:nodejs12.x Docker container image......
Mounting /Users/dev/lab/sam-app/.aws-sam/build/getAllItemsFunction as /var/task:ro,delegated inside runtime container
START RequestId: bd1dd37e-d464-13c1-45da-a4d427db1e84 Version: $LATEST
2020-07-12T23:33:50.674Z bd1dd37e-d464-13c1-45da-a4d427db1e84 INFO received: { httpMethod: 'GET' }
2020-07-12T23:33:50.812Z bd1dd37e-d464-13c1-45da-a4d427db1e84 ERROR Invoke Error {"errorType":"ResourceNotFoundException","errorMessage":"Requested resource not found","code":"ResourceNotFoundException","message":"Requested resource not found","time":"2020-07-12T23:33:50.809Z","requestId":"E711QAGJJAH7FDFSIU8PR88053VV4KQNSO5AEMVJF66Q9ASUAAJG","statusCode":400,"retryable":false,"retryDelay":26.07018253857256,"stack":["ResourceNotFoundException: Requested resource not found"," at Request.extractError (/var/task/node_modules/aws-sdk/lib/protocol/json.js:51:27)"," at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)"," at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)"," at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:688:14)"," at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)"," at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)"," at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10"," at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:38:9)"," at Request.<anonymous> (/var/task/node_modules/aws-sdk/lib/request.js:690:12)"," at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:116:18)"]}
Пример проекта содержит 3 лямбда-функции, которые вызывают серверную часть DynamoDb (обрезано для ясности ):
AWSTemplateFormatVersion: 2010-09-09
Description: >-
sam-ap
Transform:
- AWS::Serverless-2016-10-31
Resources:
getAllItemsFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/get-all-items.getAllItemsHandler
Runtime: nodejs12.x
MemorySize: 128
Timeout: 100
Description: A simple example includes a HTTP get method to get all items from a DynamoDB table.
Policies:
# Give Create/Read/Update/Delete Permissions to the SampleTable
- DynamoDBCrudPolicy:
TableName: !Ref SampleTable
Environment:
Variables:
# Make table name accessible as environment variable from function code during execution
SAMPLE_TABLE: !Ref SampleTable
Events:
Api:
Type: Api
Properties:
Path: /
Method: GET
SampleTable:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: id
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
Outputs:
WebEndpoint:
Description: "API Gateway endpoint URL for Prod stage"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
Я предполагаю, что таблица DynamoDB не создается локально внутри контейнера AWS test docker. Есть ли еще один этап сборки или другой файл определения, который мне не хватает для локального тестирования DynamoDB?