使用boto运行cloudformation模板yaml会产生验证错误

时间:2018-05-04 07:14:31

标签: amazon-web-services amazon-cloudformation boto3

我创建了一个yaml模板文件。我想根据文档https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html

中给出的条件标记lambda函数

以下是我的yaml -

AWSTemplateFormatVersion: '2012-10-10'  
Description: "Cloud formation template"

Parameters:  
      tagName:  
        Type: String  
        Description: "tag name for the resource"  
        Default: test  

Conditions:  
      isConditionalTag:  
        - Fn::Equals:  
            - Ref: tagName  
            - "test"  
Resources:  
       TestambdaFunction:  
       Properties:  
            Code:  
                 S3Bucket: "abc-test"  
                 S3Key: xyz-RELEASE.jar  
            Description: Test Lambda function  
            Environment:  
              Variables:  
                DATA_TYPE: "test-data"  
            FunctionName: TestFunction  
            Handler: com.test.testLambda::handleRequest  
            MemorySize: 200  
            Role: "arn:aws:iam::user:role/general"  
            Runtime: java8  
            Timeout: 300  
            Tags:  
            -    Key: "component"  
                 Value:  
                    Fn::If:  
                        - isConditionalTag  
                        - Ref: tagName  
                        - "newValue"  
       Type: AWS::Lambda::Function 

使用boto运行模板时没有格式错误,验证错误为

boto.exception.BotoServerError:BotoServerError:400 Bad Request {“Error”:{“Code”:“ValidationError”,“Message”:“模板格式错误:条件只能是对参数和其他条件的布尔运算”,“类型”:“发件人”},“RequestId”:“ 30250a23-4a66-11e8-a3bd-a14cac12563" }

1 个答案:

答案 0 :(得分:0)

您无需使用Condition即可完成此操作。

条件用于定义是否在Cloudformation中创建资源。

基于documentation

  

可选条件部分包含定义何时a的语句   创建资源或定义属性时。例如,你   可以比较一个值是否等于另一个值。基于   该条件的结果,您可以有条件地创建资源

你应该能够解决这个问题(未经测试):

Parameters:  
  tagName:  
    Type: String  
    Description: "tag name for the resource"  
    Default: test  
Resources:  
  TestambdaFunction:  
    Properties:  
      Code:  
        S3Bucket: "abc-test"  
        S3Key: xyz-RELEASE.jar  
      Description: Test Lambda function  
      Environment:  
        Variables:  
          DATA_TYPE: "test-data"  
      FunctionName: TestFunction  
      Handler: com.test.testLambda::handleRequest  
      MemorySize: 256  
      Role: "arn:aws:iam::user:role/general"  
      Runtime: java8  
      Timeout: 300
      Tags:  
        - Key: "component"  
          Value: !Ref tagName
    Type: AWS::Lambda::Function

请注意,Lambda函数需要以64MB

为增量的内存