Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get proper DBCluster port #8549

Closed
dekoza opened this issue Jun 15, 2020 · 2 comments
Closed

Can't get proper DBCluster port #8549

dekoza opened this issue Jun 15, 2020 · 2 comments
Assignees
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while.

Comments

@dekoza
Copy link

dekoza commented Jun 15, 2020

This look like regression - there was already similar bug: #2711

I try to configure RDS using CDK in Python and then pass port number to ECS.

This is how the DBCluster is created:

    cluster = rds.DatabaseCluster(
        stack,
        "MyDBCluster",
        #master_user=...
        default_database_name=DATABASE_NAME,
        engine=rds.DatabaseClusterEngine.AURORA_POSTGRESQL,
        engine_version="11.6",
        instances=1,
        parameter_group=rds.ClusterParameterGroup.from_parameter_group_name(
            stack, "MyParamGroup", "default.aurora-postgresql11"
        ),
        instance_props=rds.InstanceProps(
            instance_type=ec2.InstanceType.of(
                ec2.InstanceClass.BURSTABLE3, ec2.InstanceSize.MEDIUM,
            ),
            vpc=vpc,
        ),
        removal_policy=core.RemovalPolicy.RETAIN,
    )

and here is the ECS pattern:

ecs_patterns.ApplicationLoadBalancedFargateService(
        stack,
        "BackendService",
        # cluster= previously created ECS cluster...
        desired_count=1,
        task_image_options=ecs_patterns.ApplicationLoadBalancedTaskImageOptions(
            image=ecs.ContainerImage.from_ecr_repository(
                # repo and tag passed from previously created objects
            ),
            environment={
                "POSTGRES_DB": DATABASE_NAME,
                "POSTGRES_HOST": database.cluster_endpoint.hostname,
                "POSTGRES_PORT": str(database.cluster_endpoint.port),
                "POSTGRES_USER": DB_USER,
                "POSTGRES_PASSWORD": DB_PASS,
            },
        ),
)

After that POSTGRES_PORT has value "-1.8881545897087736e+289".

Expected result

POSTGRES_PORT should have value "3306".

Environment

  • CLI Version :aws-cli/2.0.16 Python/3.7.3 Linux/5.6.15-1-MANJARO botocore/2.0.0dev20
  • Framework Version: 1.45.0
  • Node.js Version: v14.3.0
  • OS : Manjaro Linux
  • Language (Version): Python 3.7/3.8

This is 🐛 Bug Report

@dekoza dekoza added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 15, 2020
@jogold
Copy link
Contributor

jogold commented Jun 15, 2020

You should be able to do something like this: core.Token.as_string(database.cluster_endpoint.port)

(database.cluster_endpoint.port is a deploy time value and it is encoded as a large negative number in the framework)

@SomayaB SomayaB added the @aws-cdk/aws-rds Related to Amazon Relational Database label Jun 17, 2020
@nija-at
Copy link
Contributor

nija-at commented Jun 22, 2020

@jogold is right. Because the value of the port is returned by CloudFormation after the resource is created (see Endpoint.Port here), the CDK does not know what this will be and hence holds a placeholder value.

If you need the string version of this number, you need to use the Token.asString() method mentioned above.

Let us know if that doesn't work.

@nija-at nija-at added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 22, 2020
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Jun 22, 2020
@github-actions github-actions bot added closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while.
Projects
None yet
Development

No branches or pull requests

4 participants