#amazon-web-services #amazon-dynamodb #amazon-cloudformation #aws-sam #aws-sam-cli
Вопрос:
Просто добавил таблицу DynamoDB template.yaml
в свой стек для моего стека. Запуск aws deploy
зависает на некоторое время с сообщением Waiting for changeset to be created..
И через несколько минут завершается сбоем с
Файл «/usr/local/Cellar/aws-sam-cli/1.26.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py», строка 295, в наборе wait_for_changeset причина = соответственно[«По состоянию»] Ключевая ошибка: «по состоянию»
Я не уверен, чего мне не хватает, я полагаю, что IAM для этого пользователя также имеет все необходимые разрешения. Я очень новичок в AWS, поэтому буду признателен за любую помощь.
Мой шаблон.yaml-это
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
bibbl.io
Sample SAM Template for bibbl.io
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Environment:
Variables:
TABLE_NAME: my-table
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.8
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: get
MyTable:
Type: AWS::DynamoDB:Table
Properties:
TableName: my-table
AttributeDefinitions:
- AttributeName: note_id
AttributeType: S
- AttributeName: upload_uri
AttributeType: S
KeySchema:
- AttributeName: note_id
KeyType: HASH
GlobalSecondaryIndexes:
IndexName: "upload_uri"
KeySchema:
- AttributeName: "upload_uri"
KeyType: "HASH"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MyTable
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn
TableName:
Value: !Ref MyTable
Description: Table name of the newly created DynamoDB table
Ответ №1:
В вашем шаблоне.yml было несколько ошибок.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
bibbl.io
Sample SAM Template for bibbl.io
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Environment:
Variables:
TABLE_NAME: my-table
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.8
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: get
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MyTable
MyTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: my-table
AttributeDefinitions:
- AttributeName: note_id
AttributeType: S
- AttributeName: upload_uri
AttributeType: S
KeySchema:
- AttributeName: note_id
KeyType: HASH
GlobalSecondaryIndexes:
-
IndexName: "upload_uri"
KeySchema:
- AttributeName: "upload_uri"
KeyType: "HASH"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Fun ction ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn
TableName:
Value: !Ref MyTable
Description: Table name of the newly created DynamoDB table
- В типе вашей таблицы Динамо отсутствует вторая двоеточие после Динамо.
Policy
Атрибут должен быть на вашей Лямбде, а не на вашем столе. Вы хотите предоставить лямбда-функции доступ к вашей таблице, а не к вашей таблице самой по себе, что не имеет смысла.GlobalSecondaryIndexes
представляет собой список объектов. Вы пропустили тире, указывающее начало списка.