0

I have a weird issue with CloudFormation that seems either to be a bug, or more likely - i've missed something pretty basic.

I have the following template (a snippet) defining two subnets and a subnet group as follow:

...

"redissubnet1": {
  "Type": "AWS::EC2::Subnet",
  "Properties": {
    "CidrBlock": "10.0.8.0/24",
    "AvailabilityZone": "us-east-1c",
    "VpcId": {
      "Ref": "myVPC"
    },
    "Tags": [
      {
        "Key": "Name",
        "Value": "redissubnet1"
      }
    ]
  }
},
"redissubnet2": {
  "Type": "AWS::EC2::Subnet",
  "Properties": {
    "CidrBlock": "10.0.9.0/24",
    "AvailabilityZone": "us-east-1c",
    "VpcId": {
      "Ref": "myVPC"
    },
    "Tags": [
      {
        "Key": "Name",
        "Value": "redissubnet2"
      }
    ]
  }
},
"SubnetGroupName": {
  "Type": "AWS::ElastiCache::SubnetGroup",
  "Properties": {
    "Description": "Subnet group for main application redis elastic cache",
    "SubnetIds": [
      {
        "Ref": "redissubnet1"
      },
      {
        "Ref": "redissubnet2"
      }
    ]
  }
}

...

All resources are created, yet the SubnetGroup name - "SubnetGroupName" - is not honoured. AWS auto-assigns a name in the format [a-z]-[a-z]-[a-z0-9]

Has anyone encountered this?

What I'm actually trying to do is reference this subnet group by name in the creation of an ElastiCache::Cluster - however because the resource name is not honoured I can't do so.

Anyone have any ideas? All help gratefully received :)

Guillaume Roderick
  • 1,139
  • 11
  • 12

1 Answers1

0

Answer was to reference the subnet group name in the elastic cache resource, as follows:

{
"subnet1": {
    "Type": "AWS::EC2::Subnet",
    "Properties": {
        "CidrBlock": "10.0.8.0/24",
        "AvailabilityZone": "us-east-1c",
        "VpcId": {
            "Ref": "myVPC"
        },
        "Tags": [{
            "Key": "Name",
            "Value": "subnet1"
        }]
    }
},
"subnet2": {
    "Type": "AWS::EC2::Subnet",
    "Properties": {
        "CidrBlock": "10.0.9.0/24",
        "AvailabilityZone": "us-east-1c",
        "VpcId": {
            "Ref": "myVPC"
        },
        "Tags": [{
            "Key": "Name",
            "Value": "subnet2"
        }]
    }
},
"redis1": {
    "Type": "AWS::ElastiCache::SubnetGroup",
    "Properties": {
        "Description": "Subnet group for main application redis elastic cache",
        "SubnetIds": [{
            "Ref": "subnet1"
        }, {
            "Ref": "subnet2"
        }]
    }
},
"mainredis": {
    "Type": "AWS::ElastiCache::CacheCluster",
    "Properties": {
        "AutoMinorVersionUpgrade": "true",
        "CacheNodeType": "cache.t2.small",
        "CacheSubnetGroupName": {
            "Ref": "redis1"
        },
        "ClusterName": "mainredis",
        "Engine": "redis",
        "NumCacheNodes": "1",
        "Port": "6379",
        "Tags": [{
            "Key": "Name",
            "Value": "mainredis"
        }, {
            "Key": "Function",
            "Value": "Main redis store"
        }],
        "VpcSecurityGroupIds": [
            "redissecuritygroup"
        ]
    }
  }
}
MuntingInsekto
  • 1,543
  • 4
  • 19
  • 36
Guillaume Roderick
  • 1,139
  • 11
  • 12