[Python] aws_redshift.CfnCluster association with subnetworks failed
I am creating Redshift cluster and trying to associate it with previously created (in a separate stack) private subnetworks. When I run cdk synth there is no any error. When I run cdk deploy "*" there is an error (see bellow)
Reproduction Steps
- Create VPC with 2 public and 2 private subnets
- Create CfnClusterSubnetGroup
- Create CfnCluster
self.vpc = ec2.Vpc(self, "VPC",
max_azs=2,
cidr="10.0.0.0/16",
subnet_configuration=[ec2.SubnetConfiguration(
subnet_type=ec2.SubnetType.PUBLIC,
name="Public",
cidr_mask=24
), ec2.SubnetConfiguration(
subnet_type=ec2.SubnetType.PRIVATE,
name="Private",
cidr_mask=24
)
]
)
self.selection = self.vpc.select_subnets(
subnet_type=ec2.SubnetType.PRIVATE
)
self.subnet_group = redshift.CfnClusterSubnetGroup(self, id="RedshiftSubnetGroup", subnet_ids=self.selection.subnet_ids, description="redshift_subnets")
redshift.CfnCluster(self, id="test-cluster",
cluster_type="multi-node",
db_name="cdk_redshift_cluster",
master_username="dwh_user",
master_user_password=self.password_string,
node_type=self.instance_parameter.value_as_string,
cluster_subnet_group_name="RedshiftSubnetGroup",
number_of_nodes=self.nodes_number.value_as_number)
Error Log
1/4 | 9:38:21 AM | CREATE_FAILED | AWS::Redshift::Cluster | test-cluster (testcluster) Vpc associated with db subnet group RedshiftSubnetGroup does not exist. (Service: AmazonRedshift; Status Code: 400; Error Code: InvalidClusterSubnetGroupStateFault; Request ID: xxxxxx)
Environment
- CLI Version: 1.16.240
- Framework Version: 1.41.0
- OS: MacOS
- Language: Python
Other
I have to say maybe there is not a bug and I am missing some parts but unfortunately there is no any example I can find creating Redshift cluster with subnets, IAM roles and security groups using Python, it would be great to have it in this repo.
This is :bug: Bug Report
Hey @dgreenshtein ,
thanks for opening the issue. Couple of follow-up questions, which are not shown in your code above:
- Can you show the code that creates the
Vpc? - Where does
subnet_idscome from in your code?
Thanks, Adam
Hi @skinny85, VPC section was missing, I added it to the code sample above, thanks.
@dgreenshtein I think I know what the issue is. In CfnCluster, in the cluster_subnet_group_name, you have "RedshiftSubnetGroup"; but in fact, it should be self. subnet_group.ref.
Can you try that, and let me know if that works?
Thanks, Adam
@skinny85 thanks a lot, it is working now. Probably .ref usage came from CFN templates and not very obvious for a classical programming language perspective where object reference is usually used.
I agree, but remember the Cfn* classes are meant to be 1-to-1 with their CloudFormation counterparts, so some knowledge of CloudFormation is assumed when using them.
Note that we just merged an L2 (so a higher-level) construct for Redshift in #5730 , so in the next version, 1.43.0, you should be able to use it, and not worry about these low-level details!
I'm resolving this one, please let us know if we can do anything else for you for this issue.
Thanks, Adam