Redis cluster reports SubnetGroup does not exist, if building SubnetGroup part of the same stack
See original GitHub issueI am building a VPC, with private, public and protected subnets. Part of the same stack, I need to create a Redis cluster (and some other things later, but those don’t matter for now). It requires a SubnetGroup. While building the stack, including the SubnetGroup, all is well and it builds.
When moving to the Redis cluster, it reports the SubnetGroup does not exist (technically, it doesn’t exist yet, but that’s what the stack is doing).
A work around is to run the stack in stages, go as far as subnet group, then uncomment the rest and build redis cluster and so on. Not a workable solution in reality. It’s a bug as far as I can tell, but I would be happy to know if I’m doing the below wrong.
Reproduction Steps
Simply build the stack
from aws_cdk import (
aws_ec2 as ec2,
aws_elasticache as elasticache,
aws_ecs as ecs,
core
)
class IntegrationsVPC(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
# Create new VPC
vpc = ec2.Vpc(
self, "Default",
max_azs=3,
nat_gateways=1,
cidr=ec2.Vpc.DEFAULT_CIDR_RANGE,
subnet_configuration=[
ec2.SubnetConfiguration(
name="Private-Subnet",
subnet_type=ec2.SubnetType.PRIVATE,
cidr_mask=19,
reserved=None
),
ec2.SubnetConfiguration(
name="Public-Subnet",
subnet_type=ec2.SubnetType.PUBLIC,
cidr_mask=22,
reserved=None
),
ec2.SubnetConfiguration(
name="Isolated-Subnet",
subnet_type=ec2.SubnetType.ISOLATED,
cidr_mask=28,
reserved=None
)
]
)
# Try subnet group
subnet_group = elasticache.CfnSubnetGroup(
scope=self,
id="Testing-Subnet-Group",
description="Group private subnets for redis access.",
subnet_ids=[subnet.subnet_id for subnet in vpc.private_subnets],
cache_subnet_group_name="test-int-private-subnets"
)
redis_security_group = ec2.SecurityGroup(
scope=self,
id="TEMP-redis-SG",
vpc=vpc,
allow_all_outbound=False
)
redis_cluster = elasticache.CfnCacheCluster(
scope=self,
cache_node_type="cache.t2.micro",
id="testmy-redis",
engine="redis",
num_cache_nodes=1,
vpc_security_group_ids=[redis_security_group.security_group_id],
cache_subnet_group_name=subnet_group.cache_subnet_group_name,
cluster_name="testmy-redis"
)
app = core.App()
IntegrationsVPC(app, "Integrations-VPC-TEMP", env={
'account': 'XXXXXXXXXX',
'region': 'eu-west-2' # or what ever you want
})
app.synth()
Error Log
15/43 | 1:09:41 PM | CREATE_FAILED | AWS::ElastiCache::CacheCluster | integrations-redis (integrationsredis) Cache Subnet Group test-int-private-subnets does not exist. (Service: AmazonElastiCache; Status Code: 400; Error Code: CacheSubnetGroupNotFoundFault; Request ID: 475a20d2-fc40-4d94-809c-******)
Environment
- CLI Version : 1.12.0 (build 923055e)
- **Framework Version: 1.12.0 **
- **OS : Ubuntu 18 **
- **Language : Python **
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
AWS CDK: Error when deploying Redis ElastiCache: Subnet ...
I do not understand why Cloud Formation is doing that, as both the security group and the cache subnet group are linked to...
Read more >awslabs/aws-cdk - Gitter
Hi. I've created a Aurora Mysql Cluster with the CDK, and a Lambda that should connect to it. They are both in the...
Read more >Subnets and subnet groups - Amazon ElastiCache for Redis
A subnet group is a collection of subnets (typically private) that you can designate for your clusters running in an Amazon Virtual Private...
Read more >terraform-aws-modules/rds/aws
AWS RDS Terraform module. Terraform module which creates RDS resources on AWS. SWUbanner. Root module calls these modules which can also be used...
Read more >aws elasticache - Fig.io
Solution: Create an Amazon S3 bucket in the same region as your snapshot. ... If you are creating a cluster inside of a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Me too 😄
@cristianrat thanks for opening the issue. I believe what you want is to add a dependency between
subnet_group
andredis_cluster
, so that CFN knows to deploy the former before the latter:Or you can do this:
which I believe is equivalent to what you had originally, and adds the dependency automatically.
Let me know if this helps!
Thanks, Adam