AWS CloudFormation:无法创建 Elasticache

AWS CloudFormation: unable to create ElasticCache

我正在使用 CloudFomration 创建 ElasticCache 内存缓存资源。但是当我部署模板时它失败了。

这是我的模板

  ElasticCacheSubnetGroup:
    Type: AWS::RDS::DBSubnetGroup
    Properties:
      DBSubnetGroupDescription: Subnet Group to specify the subnets for elastic cache
      SubnetIds:
        - !Ref DatabaseSubnet1
        - !Ref DatabaseSubnet2
  ElasticCacheSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: !Ref Vpc
      GroupDescription: Enable TCP connection on port 3306 for database connection
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '3306'
          ToPort: '3306'
          CidrIp: 0.0.0.0/0
  ElasticCacheCluster:
    Type: AWS::ElastiCache::CacheCluster
    Properties:
      AZMode: cross-az
      CacheNodeType: cache.t2.small
      Engine: memcached
      NumCacheNodes: '3'
      CacheSubnetGroupName: !Ref ElasticCacheSubnetGroup
      VpcSecurityGroupIds:
        - !Ref ElasticCacheSecurityGroup
      PreferredAvailabilityZones:
        - !Select
          - 0
          - Fn::GetAZs: !Ref AWS::Region
        - !Select
          - 1
          - Fn::GetAZs: !Ref AWS::Region

这是我在日志中得到的错误。

 {
            "StackId": "arn:aws:cloudformation:eu-west-1:733553390213:stack/threetierwebapp/c88ea6d0-d029-11ea-9279-02162fdbb6ee", 
            "EventId": "eed78640-d029-11ea-8cd8-02e056ab1688", 
            "ResourceStatus": "ROLLBACK_IN_PROGRESS", 
            "ResourceType": "AWS::CloudFormation::Stack", 
            "Timestamp": "2020-07-27T16:55:10.741Z", 
            "ResourceStatusReason": "The following resource(s) failed to create: [ElasticCacheCluster]. . Rollback requested by user.", 
            "StackName": "threetierwebapp", 
            "PhysicalResourceId": "arn:aws:cloudformation:eu-west-1:733553390213:stack/threetierwebapp/c88ea6d0-d029-11ea-9279-02162fdbb6ee", 
            "LogicalResourceId": "threetierwebapp"
        }, 
        {
            "StackId": "arn:aws:cloudformation:eu-west-1:733553390213:stack/threetierwebapp/c88ea6d0-d029-11ea-9279-02162fdbb6ee", 
            "EventId": "ElasticCacheCluster-CREATE_FAILED-2020-07-27T16:55:09.946Z", 
            "ResourceStatus": "CREATE_FAILED", 
            "ResourceType": "AWS::ElastiCache::CacheCluster", 
            "Timestamp": "2020-07-27T16:55:09.946Z", 
            "ResourceStatusReason": "Cache Subnet Group threetierwebapp-elasticcachesubnetgroup-1hxvajmdjip1i does not exist. (Service: AmazonElastiCache; Status Code: 400; Error Code: CacheSubnetGroupNotFoundFault; Request ID: 790019b8-2ed8-4748-9c38-7c1eec121251)", 
            "StackName": "threetierwebapp", 
            "ResourceProperties": "{\"CacheNodeType\":\"cache.t2.small\",\"CacheSubnetGroupName\":\"threetierwebapp-elasticcachesubnetgroup-1hxvajmdjip1i\",\"VpcSecurityGroupIds\":[\"sg-0603c1f4b76c8afde\"],\"PreferredAvailabilityZones\":[\"eu-west-1a\",\"eu-west-1b\",\"eu-west-1c\"],\"NumCacheNodes\":\"3\",\"Engine\":\"memcached\",\"AZMode\":\"cross-az\"}", 
            "PhysicalResourceId": "", 
            "LogicalResourceId": "ElasticCacheCluster"
        }, 

我的模板有什么问题,我该如何解决?

您已经为您的 ElasticCacheSubnetGroup 资源分配了一个 AWS::RDS::DBSubnetGroup

而是将其换成 AWS::ElastiCache::SubnetGroup 并从中删除 DBSubnetGroupDescription 属性。

这看起来像下面这样


  ElasticCacheSubnetGroup:
    Type: AWS::ElastiCache::SubnetGroup
    Properties:
      SubnetIds:
        - !Ref DatabaseSubnet1
        - !Ref DatabaseSubnet2
  ElasticCacheSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: !Ref Vpc
      GroupDescription: Enable TCP connection on port 3306 for database connection
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '3306'
          ToPort: '3306'
          CidrIp: 0.0.0.0/0
  ElasticCacheCluster:
    Type: AWS::ElastiCache::CacheCluster
    Properties:
      AZMode: cross-az
      CacheNodeType: cache.t2.small
      Engine: memcached
      NumCacheNodes: '3'
      CacheSubnetGroupName: !Ref ElasticCacheSubnetGroup
      VpcSecurityGroupIds:
        - !Ref ElasticCacheSecurityGroup
      PreferredAvailabilityZones:
        - !Select
          - 0
          - Fn::GetAZs: !Ref AWS::Region
        - !Select
          - 1
          - Fn::GetAZs: !Ref AWS::Region
        - !Select
          - 2
          - Fn::GetAZs: !Ref AWS::Region