阵列类型的AWS Cloudformation列表参数失败

时间:2018-12-12 01:22:46

标签: amazon-cloudformation

我正在使用cloudformation创建一个Cloudfront发行版,并尝试使用参数填充别名。

如果我使用单个字符串,它将失败,因为它需要一个列表。而且,如果我使用列表,它会失败,因为它需要一个数组。

例如,这有效(无参数):

<!-- language: json -->

{
    "Resources": {
        "FrontEndBucket": {
            "Type": "AWS::S3::Bucket",
            "Properties": {
                "BucketName":"test.tester.huh"
            }
        },
        "CloudFrontDistro": {
            "Type": "AWS::CloudFront::Distribution",
            "Properties": {
                "DistributionConfig": {
                    "Aliases": ["testalias.tester.huh"],
                    "Enabled":true,
                    "Origins": [
                        {
                            "DomainName": "test.tester.huh.s3.amazonaws.com",
                            "Id":"OriginId",
                            "S3OriginConfig": { }
                        }
                    ],
                    "DefaultCacheBehavior": {
                        "TargetOriginId": "OriginId",
                        "ViewerProtocolPolicy": "allow-all",
                        "ForwardedValues": {
                            "QueryString": true
                        }
                    }
                }
            }
        }
    }
}

但是当我运行它时:

{
    "Parameters" : {
        "DomainAliases" : {
            "Type" : "CommaDelimitedList"
        }
    },
    "Resources": {
        "CloudFrontDistro": {
            "Type": "AWS::CloudFront::Distribution",
            "Properties": {
                "DistributionConfig": {
                    "Aliases": {"ref":"DomainAliases"},
                    "Enabled":true,
                    "Origins": [
                        {
                            "DomainName": "test.tester.huh.s3.amazonaws.com",
                            "Id":"OriginId",
                            "S3OriginConfig": { }
                        }
                    ],
                    "DefaultCacheBehavior": {
                        "TargetOriginId": "OriginId",
                        "ViewerProtocolPolicy": "allow-all",
                        "ForwardedValues": {
                            "QueryString": true
                        }
                    }
                }
            }
        }
    }
}

此操作失败: (*注:它确实通过了初始验证)

Property validation failure: [Value of property {/DistributionConfig/Aliases} does not match type {Array}]

2 个答案:

答案 0 :(得分:1)

看看AWS :: CloudFront :: Distribution的最低要求以及其页面中的示例,以下模板对我来说非常合适:

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {
        "DomainAliases": {
            "Type": "CommaDelimitedList"
        }
    },
    "Resources": {
        "myDistribution": {
            "Type": "AWS::CloudFront::Distribution",
            "Properties": {
                "DistributionConfig": {
                    "Aliases": {
                        "ref": "DomainAliases"
                    },
                    "Origins": [{
                        "DomainName": "mybucket.s3.amazonaws.com",
                        "Id": "myS3Origin",
                        "S3OriginConfig": {
                            "OriginAccessIdentity": "origin-access-identity/cloudfront/E127EXAMPLE51Z"
                        }
                    }],
                    "Enabled": "true",
                    "DefaultCacheBehavior": {
                        "AllowedMethods": ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"],
                        "TargetOriginId": "myS3Origin",
                        "ForwardedValues": {
                            "QueryString": "false",
                            "Cookies": {
                                "Forward": "none"
                            }
                        },
                        "TrustedSigners": ["1234567890EX", "1234567891EX"],
                        "ViewerProtocolPolicy": "allow-all"
                    }
                }
            }
        }
    }
}

答案 1 :(得分:0)

我自己遇到了这个问题。它希望别名以数组而不是字符串的形式出现。添加了一些方括号并将其修复:

"Properties": {
                 "DistributionConfig": 
                       {
                              "Aliases": 
                                 [
                                    {
                                       "ref":"DomainAliases"
                                    }
                                 ],
                       }
                 }