【问题标题】:Reason: Invalid template property or properties [Api]原因:无效的模板属性或属性 [Api]
【发布时间】:2019-09-24 18:51:17
【问题描述】:

通过docker deploy_image后发现:

等待创建变更集..

创建变更集失败:Waiter ChangeSetCreateComplete 失败:Waiter 遇到终端故障状态状态: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 中创建一个堆栈。

【问题讨论】:

    标签: aws-sam


    【解决方案1】:

    你的模板有两个问题:

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

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

    【讨论】:

    • 嗨,alex,如果我没记错的话,Api 将是 `Globals: Function: Timeout: 60 Api: BinaryMediaTypes: - image~1png ` 我已经有了代码 uri ...但仍然是同样的问题
    • @ToufiqurRahman,有一个例子here。正如我所说,您的缩进是错误的,这就是您收到错误的原因。
    • 是的,我已经改变了,但又遇到了同样的问题。
    • @ToufiqurRahman, here 是一个要点,展示了我如何重现您的错误,然后我修复了缩进问题,然后它显示它已部署。
    • @ToufiqurRahman,不客气。您愿意通过选择绿色勾号来接受答案吗?
    猜你喜欢
    • 1970-01-01
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    相关资源
    最近更新 更多