【问题标题】:AWS Cloudformation [/Resources/PrivateGateway/Properties] 'null' values are not allowed in templatesAWS Cloudformation [/Resources/PrivateGateway/Properties] 模板中不允许使用“null”值
【发布时间】:2019-09-04 22:31:18
【问题描述】:

我正在尝试运行 Cloudformation 模板来创建私有 API 网关,我收到空值错误,无法弄清楚原因,
以下是我正在尝试使用的模板-

AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: Api Template Stack

Parameters:
    VpcId:
        Type: String
        Default: "vpc-xxxxxx"

Resources:
    PrivateGateway:
        Type: 'AWS::ApiGateway::RestApi'
        Properties:
        Name: 'private-gw'
        EndpointConfiguration:
            Types:
            - PRIVATE
        Policy: !Sub |
          {
            "Version": "2012-10-17",
            "Statement": [
                {
                "Effect": "Deny",
                "Principal": "*",
                "Action": "execute-api:Invoke",
                "Resource": "arn:aws:execute-api:us-east-1:${AWS::AccountId}:*/*/*/*",
                "Condition": {
                    "StringNotEquals": {
                    "aws:sourceVpc": !Ref VpcId
                    }
                }
                },
                {
                "Effect": "Allow",
                "Principal": "*",
                "Action": "execute-api:Invoke",
                "Resource": "arn:aws:execute-api:us-east-1:${AWS::AccountId}:*/*/*/*"
                }
            ]
          }

错误 -

[/Resources/PrivateGateway/Properties] 'null' values are not allowed in templates

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    据我所知,这似乎是 yaml 解析错误,而不是 CloudFormation 错误。

    因为这是一个yaml模板,所以以yaml specification为准。

    每个节点必须比其父节点缩进更多。所有兄弟节点必须使用完全相同的缩进级别。但是每个兄弟节点的内容可以进一步独立缩进。

    在您的示例中,Properties 下的节点没有进一步缩进,因此它们不被视为该节点的子节点,而是兄弟节点。这很可能是您收到“空”值消息的原因,因为 Properties 节点被视为“空”或“空”。

    尝试在“属性:”行下的每一行的开头添加两个空格。这将使NameEndpointConfigurationPolicy等节点成为Properties节点的子节点。

    【讨论】:

    • 感谢指出,缩进确实是模板中的问题之一
    【解决方案2】:

    能够使用花括号替换策略中的 VpcId 来解决它 -

    AWSTemplateFormatVersion: 2010-09-09
    Transform: 'AWS::Serverless-2016-10-31'
    Description: Api Template Stack
    
    Parameters:
        VpcId:
            Type: String
            Default: "vpc-xxxxxx"
    
    Resources:
        PrivateGateway:
            Type: 'AWS::ApiGateway::RestApi'
            Properties:
                Name: 'private-gw'
                EndpointConfiguration:
                    Types:
                    - PRIVATE
                Policy: !Sub |
                {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Effect": "Deny",
                            "Principal": "*",
                            "Action": "execute-api:Invoke",
                            "Resource": "arn:aws:execute-api:us-east-1:${AWS::AccountId}:*/*/*/*",
                            "Condition": {
                                "StringNotEquals": {
                                    "aws:sourceVpc": "${VpcId}"
                                }
                            }
                        },
                        {
                            "Effect": "Allow",
                            "Principal": "*",
                            "Action": "execute-api:Invoke",
                            "Resource": "arn:aws:execute-api:us-east-1:${AWS::AccountId}:*/*/*/*"
                        }
                    ]
                }
    

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 2023-01-10
      • 2018-08-24
      • 2021-04-27
      • 2020-10-23
      • 1970-01-01
      • 2022-08-18
      • 2012-08-09
      • 2021-07-20
      相关资源
      最近更新 更多