AWS sam 部署失败:Waiter ChangeSetCreateComplete 失败:超出最大尝试次数

AWS sam deploy failed : Waiter ChangeSetCreateComplete failed: Max attempts exceeded

刚刚为我的堆栈添加了一个 DynamoDB table 到我的 template.yaml。 运行 aws deploy 与消息一起冻结了一段时间 Waiting for changeset to be created.. 几分钟后失败

File "/usr/local/Cellar/aws-sam-cli/1.26.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py", line 295, in wait_for_changeset reason = resp["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
  1. Dynamo Table 的类型在 Dynamo 之后缺少第二个冒号。

  2. Policy 属性需要在您的 Lambda 上,而不是在您的 table 上。您想让 Lambda 函数访问您 table 而不是您的 table 本身,这没有意义。

  3. GlobalSecondaryIndexes 是一个对象列表。您缺少指示列表开头的破折号。