Trying to run the docs from (https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_rds/ClusterInstance.html), it says ClusterInstance
is a part of aws_rds
. When cdk synth
gets to that line, it says it can't find that module though. The confusing part is other parts of aws_rds
get imported just fine. Also dir(aws_rds)
shows most of the modules, just not this one.
I'm trying to run:
from aws_cdk import (
Stack,
aws_rds as rds,
aws_ec2 as ec2,
)
from constructs import Construct
from cdk_utils.get_param import get_param
class AuroraDbStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
vpc = ec2.Vpc(
self,
"Aurora TEMP VPC",
max_azs=2,
subnet_configuration=[
ec2.SubnetConfiguration(
subnet_type=ec2.SubnetType.PRIVATE_ISOLATED,
name="Aurora TEMP Private Subnet",
),
],
)
cluster = rds.DatabaseCluster(self, "Database",
engine=rds.DatabaseClusterEngine.aurora_mysql(
version=rds.AuroraMysqlEngineVersion.VER_3_01_0
),
## HERE: When trying to access `rds.ClusterInstance`
writer=rds.ClusterInstance.provisioned("writer",
publicly_accessible=False
),
readers=[
rds.ClusterInstance.serverless_v2("reader2")
],
vpc_subnets=ec2.SubnetSelection(
subnet_type=ec2.SubnetType.PRIVATE_ISOLATED
),
vpc=vpc
)
Exact traceback:
Synthesizing test-aurora-db
Traceback (most recent call last):
File "/cdk/AuroraDB/app.py", line 23, in <module>
AuroraDbStack(
File "/usr/local/lib/python3.9/site-packages/jsii/_runtime.py", line 118, in __call__
inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
File "/cdk/AuroraDB/aurora_db/aurora_db_stack.py", line 34, in __init__
writer=rds.ClusterInstance.provisioned("writer",
AttributeError: module 'aws_cdk.aws_rds' has no attribute 'ClusterInstance'
Versions:
cdk --version
: 2.106.0 (build 0d1a333) (Was 2.105.0 yesterday, which is where the docs are at).
python3 --version
: Python 3.9.16
npm --version
: 10.1.0
node --version
: v20.7.0
I expected ClusterInstance to be a module of aws_rds. Maybe it got renamed, and the docs need updating? The confusing part is so many other modules are working fine, so I don't think it's python path related...
I think I found the answer finally, the python package aws-cdk-lib
was out of date. Bumping it 2.81.0
-> 2.99.1
allows me to use rds.ClusterInstance.