【问题标题】:Review needed to correct this ElastiCache CloudFormation Template更正此 ElastiCache CloudFormation 模板所需的审核
【发布时间】:2021-09-02 03:26:24
【问题描述】:

此模板用于创建 ElastiCache-Redis 集群。 它向我显示错误,例如 - 检测到 1 个验证错误:'typeNameList' 处的值 '[AWS::ElastiCache::CacheCluster, AWS::EC2::SecurityGroup::Id]' 未能满足约束:成员必须满足约束:[成员长度必须小于或等于 204,成员必须长度大于或等于 10,成员必须满足正则表达式模式:[A-Za-z0-9]{2,64}::[A-Za-z0 -9]{2,64}::[A-Za-z0-9]{2,64}(::MODULE){0,1}]。 想知道参数声明是否正确。

AWSTemplateFormatVersion: 2010-09-09

Description: Create ElastiCache and related resources

Parameters:
  VPC:
    Description: VPC 
    Type: AWS::EC2::VPC::Id
  Subnet:
    Description: Subnet
    Type: AWS::EC2::Subnet::Id
  ClusterName:
    Description: Custom name of the cluster. Auto generated if you 
    don't supply your own.
    Type: String
  CacheNodeType:
    Description: Cache node instance class, e.g. cache.t2.micro. 
    Type: String
    Default: cache.t2.micro
    ConstraintDescription: Node instance class not supported
    AllowedValues:
      - cache.t2.micro
      - cache.t2.small
      - cache.t2.medium
      - cache.m4.large
      - cache.m4.xlarge
      - cache.m4.2xlarge
      - cache.m4.4xlarge
      - cache.m4.10xlarge
      - cache.r4.large
      - cache.r4.xlarge
      - cache.r4.2xlarge
      - cache.r4.4xlarge
      - cache.r4.8xlarge
      - cache.r4.16xlarge
  CacheEngine:
    Description: The underlying cache engine, either Redis or 
    Memcached
    Type: String
    Default: redis
    ConstraintDescription: Node instance class not supported
    AllowedValues:
      - redis
      - memcached
  CacheNodeCount:
    Description: Number of nodes in the cluster. Only used with 
    memcached engine, for redis this value will be set to 1.
    Type: Number
    MinValue: 1
    MaxValue: 15
    ConstraintDescription: Node count must be between 1 and 15
    Default: 1
  AutoMinorVersionUpgrade:
    Description: Whether or not minor version upgrades to the cache 
    engine should be applied automatically during the maintenance 
    window.
    Type: String
    Default: true
    AllowedValues:
      - true
      - false

Resources:
  SecurityGroup:
    Type: AWS::EC2::SecurityGroup::Id
    Properties:
      GroupDescription: ElastiCache Security Group
      VpcId: !Ref VPC
      SecurityGroupIngress:
          - IpProtocol: tcp
            FromPort: 6379
            ToPort: 6379
          - IpProtocol: tcp
            FromPort: 11211
            ToPort: 11211
      Tags:
        -
          Key: Name
          Value: "App-SG"
  ElastiCacheCluster:
    Type: AWS::ElastiCache::CacheCluster
    Properties:
      AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade
      Engine: !Ref CacheEngine
      CacheNodeType: !Ref CacheNodeType
      ClusterName : !Ref ClusterName
      NumCacheNodes: !Ref CacheNodeCount
      CacheSubnetGroupName: !Ref Subnet 
      VpcSecurityGroupIds: !Ref SecurityGroup
      Tags:
        - Key: Name
          Value: ElastiCache-Redis

此外,查看整个模板以避免更多错误也会有所帮助。主要问题似乎来自资源部分。

【问题讨论】:

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


    【解决方案1】:

    这个问题很老,我确信 OP 找到了解决方案,但对于可能遇到这个问题的任何其他人 - 我相信问题是 ElastiCacheCluster.VpcSecurityGroupIds 必须是一个列表,而 !Ref SecurityGroup 将简单地返回 ID安全组的字符串。

    另外,由于这两个资源是由同一个模板创建的,所以我们要确保安全组会先被创建,否则在创建Elasticache集群时引用它会导致错误。

    这是 ElastiCache::CacheCluster 资源,其中包含一个列表作为 VpcSecurityGroupIds 的值以及对安全组的依赖。

    ElastiCacheCluster:
     Type: AWS::ElastiCache::CacheCluster
     Properties:
      AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade
      Engine: !Ref CacheEngine
      CacheNodeType: !Ref CacheNodeType
      ClusterName : !Ref ClusterName
      NumCacheNodes: !Ref CacheNodeCount
      CacheSubnetGroupName: !Ref Subnet 
      VpcSecurityGroupIds: 
       - !Ref SecurityGroup
      Tags:
       - Key: Name
         Value: ElastiCache-Redis
     DependsOn: SecurityGroup
    

    【讨论】:

      猜你喜欢
      • 2022-01-26
      • 2015-12-08
      • 1970-01-01
      • 2020-10-23
      • 2016-08-04
      • 2017-03-10
      • 1970-01-01
      • 2019-12-14
      • 1970-01-01
      相关资源
      最近更新 更多