原因:无效模板 属性 或属性 [Api]

Reason: Invalid template property or properties [Api]

在 deploy_image 到 docker 之后,我发现:

Waiting for changeset to be created..

Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED.

我的模板有什么问题:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: 'testimg

  Sample SAM Template for testimg

  '
Globals:
  Function:
    Timeout: 60
Api:
  BinaryMediaTypes:
  - image/png
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: 
      Handler: app.lambda_handler
      Runtime: python3.6
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: post

Outputs:
  HelloWorldApi:
    Description: API Gateway endpoint URL for Prod stage for Hello World function
    Value:
      Fn::Sub: https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/
  HelloWorldFunction:
    Description: Hello World Lambda Function ARN
    Value:
      Fn::GetAtt:
      - HelloWorldFunction
      - Arn
  HelloWorldFunctionIamRole:
    Description: Implicit IAM Role created for Hello World function
    Value:
      Fn::GetAtt:
      - HelloWorldFunctionRole
      - Arn

我预计它会在 cloudformation 中创建一个堆栈。

你的模板有两个问题:

  1. 您模板的顶层有一个键 Api SAM/CloudFormation 无法识别。请参阅文档 here。看起来你的缩进错了,而你的全局部分应该是:
Globals:
  Function:
    Timeout: 60
  Api:
    BinaryMediaTypes:
    - image/png
  1. 您的 CodeUri 字段为空。那应该是 Python 代码的本地路径,例如 CodeUri: hello_world/.

如果您解决了这些问题,它应该会部署。