如何解决AWS sam 部署失败:服务员 ChangeSetCreateComplete 失败:超过最大尝试次数
刚刚为我的堆栈添加了一个 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中 原因 = 响应 ["StatusReason"] KeyError: 'StatusReason'
我不确定我缺少什么,我相信此用户的 IAM 也具有所有必需的权限。我对 AWS 非常陌生,因此我们将不胜感激。
我的 template.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
解决方法
您的 template.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
-
Dynamo Table 的类型在 Dynamo 之后缺少第二个冒号。
-
Policy
属性需要在您的 Lambda 上,而不是在您的表上。您想让 Lambda 函数访问您的表,而不是您的表本身,这是没有意义的。 -
GlobalSecondaryIndexes
是一个对象列表。您缺少指示列表开头的破折号。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。