aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

[Python] aws_redshift.CfnCluster association with subnetworks failed

Open dgreenshtein opened this issue 6 years ago • 5 comments

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

  1. Create VPC with 2 public and 2 private subnets
  2. Create CfnClusterSubnetGroup
  3. 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

dgreenshtein avatar May 27 '20 08:05 dgreenshtein

Hey @dgreenshtein ,

thanks for opening the issue. Couple of follow-up questions, which are not shown in your code above:

  1. Can you show the code that creates the Vpc?
  2. Where does subnet_ids come from in your code?

Thanks, Adam

skinny85 avatar May 27 '20 16:05 skinny85

Hi @skinny85, VPC section was missing, I added it to the code sample above, thanks.

dgreenshtein avatar May 27 '20 21:05 dgreenshtein

@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 avatar May 28 '20 22:05 skinny85

@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.

dgreenshtein avatar May 29 '20 09:05 dgreenshtein

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

skinny85 avatar May 29 '20 16:05 skinny85