aws-cloudformation - 数组类型的 AWS Cloudformation 列表参数失败

标签 aws-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}]

最佳答案

查看 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"
                    }
                }
            }
        }
    }
}

关于aws-cloudformation - 数组类型的 AWS Cloudformation 列表参数失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53734770/

相关文章:

aws-cloudformation - AWS Python CDK 共享库

amazon-dynamodb - 使用 Cloudformation 创建具有复合主键的 DynamoDB

amazon-web-services - Cloudformation,无法创建类型为 `AWS::MSK::Configuration` 的资源

amazon-web-services - 使用 Qa、Dev 和 Prod 作为 Cloudformation 中的环境

amazon-elastic-beanstalk - 使用 CloudFormation 创建 BeanStalk 应用程序时如何修复 "Insufficient privileges for IAM PassRole Action"?

amazon-web-services - 无法使用 !Ref 在 Cloudformation 中创建 AWS Batch JobDefinition JobRoleArn

amazon-web-services - CDK 客户端 VPN 端点。想了解如何获取创建的 VpnEndpoint 的 DnsName

aws-cloudformation - YAML 错误 : could not determine a constructor for the tag

yaml - Fn::Foreach 具有内部函数参数 | Fn::GetAZ |找不到集合

amazon-web-services - 将 Redis 集群与一个堆栈分开