0

运行 CLI 命令 aws cloudformation deploy 后出现以下错误(在 sam 包之后)

“创建变更集失败:Waiter ChangeSetCreateComplete 失败:Waiter 遇到终端故障状态状态:FAILED。原因:无效的模板属性或属性 [MyApi]”

这是模板。我无法获得有关哪个是无效属性的信息。这可能吗?否则这个模板有什么问题?

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31

Resources:
  HelloFunction:
    Type: AWS::Serverless::Function
    Properties:`enter code here`
      Handler: main
      Runtime: go1.x
      Events:
        GetEvent:
          Type: Api
          Properties:
            Path: /
            Method: post
            #RestApiId: !Ref ApiGateway1

  LambdaInvokePermission:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !GetAtt
        - HelloFunction
        - Arn
      Action: 'lambda:InvokeFunction'
      Principal: apigateway.amazonaws.com
      SourceAccount: !Ref 'AWS::AccountId'

MyApi:
  Type: AWS::Serverless::Api
  Properties:
    StageName: default
    EndpointConfiguration: REGIONAL
    DefinitionBody:
      swagger: "2.0"
      info:
        title: "TestAPI"
      paths:
        /:
          get:
#            parameters:
#              - name: "id"
#                in: "query"
#                required: true
#                type: "string"
#            x-amazon-apigateway-request-validator: "Validate query string parameters and\
#                \ headers"
            x-amazon-apigateway-integration:
              uri:
                Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloFunction.Arn}/invocations
              responses: {}
              httpMethod: "POST"
              type: "aws_proxy"



Outputs:
  FunctioArn:
    Value: !GetAtt  HelloFunction.Arn
    Export:
      Name: HelloFunctionArn
4

1 回答 1

2

MyApi 出现缩进错误。使用以下内容:

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31

Resources:
  HelloFunction:
    Type: AWS::Serverless::Function
    Properties:`enter code here`
      Handler: main
      Runtime: go1.x
      Events:
        GetEvent:
          Type: Api
          Properties:
            Path: /
            Method: post
            #RestApiId: !Ref ApiGateway1

  LambdaInvokePermission:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !GetAtt
        - HelloFunction
        - Arn
      Action: 'lambda:InvokeFunction'
      Principal: apigateway.amazonaws.com
      SourceAccount: !Ref 'AWS::AccountId'

  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: default
      EndpointConfiguration: REGIONAL
      DefinitionBody:
        swagger: "2.0"
        info:
          title: "TestAPI"
        paths:
          /:
            get:
  #            parameters:
  #              - name: "id"
  #                in: "query"
  #                required: true
  #                type: "string"
  #            x-amazon-apigateway-request-validator: "Validate query string parameters and\
  #                \ headers"
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloFunction.Arn}/invocations
                responses: {}
                httpMethod: "POST"
                type: "aws_proxy"



Outputs:
  FunctioArn:
    Value: !GetAtt  HelloFunction.Arn
    Export:
      Name: HelloFunctionArn
于 2019-03-07T10:46:49.117 回答