Cannot create DocumentDB instance in a Cluster because of InvalidSubnet Error

0

I have a cluster running and I want to scale out the cluster by adding a new read node.

Unfortunately I experience following error when I try to scale out the cluster programmatically. I am using AWS Lambda function with boto3 Python code using client.create_db_instance

[ERROR] InvalidSubnet: An error occurred (InvalidSubnet) when calling the CreateDBInstance operation: No default subnet detected in VPC. Please contact AWS Support to recreate default Subnets.

Any suggestions? Thanks

Eralper
asked 2 months ago227 views
2 Answers
1
Accepted Answer

Hello.

Can you share the code you are using?
Could you also share the settings of the subnet group etc. associated with the database cluster?

If you follow the error message, I think you need to create a default VPC using the steps in the document below.
https://repost.aws/knowledge-center/recreate-default-vpc

profile picture
EXPERT
answered 2 months ago
  • Thank you for sharing the code. When I looked at the code, it seemed like there was no problem. If you are successful with AWS CLI, I think there is no problem with the API itself. One possibility is that it may be an issue with the boto3 version. So, try creating and configuring a Lambda layer for the latest version of boto3 using the command below.

    LIB_DIR=boto3-mylayer/python
    mkdir -p $LIB_DIR
    pip3 install boto3 -t $LIB_DIR
    cd boto3-mylayer
    zip -r /tmp/boto3-mylayer.zip .
    aws lambda publish-layer-version --layer-name boto3-mylayer --zip-file fileb:///tmp/boto3-mylayer.zip --compatible-runtimes python3.11
    aws lambda update-function-configuration --function-name <Lambda Function Name> --layers arn:aws:lambda:ap-northeast-1:<your AWS Account ID>:layer:boto3-mylayer:1
    

    By the way, will the same error occur even if I delete the AZ specification? Will it work properly if I delete all the parameters other than the required parameters listed in the document below? https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/docdb/client/create_db_instance.html

  •     response = client.create_db_instance(
            DBInstanceIdentifier=newDBInstanceIdentifier,
            DBInstanceClass=pTargetDBInstanceClass,
            Engine=Engine,
            DBClusterIdentifier=DBClusterIdentifier
        )
    
  • Hi Riku, I really appretiate your help, it worked like a charm :) I did not realize that it might be just because of the boto3 version I was working with latest Python version Python 3.12 so I now understand that 3.11 works fine.

0

Hi Riku,

I see that I have to launch my cluster within Default VPC or create a new default VPC in my AWS account. And generally this is not the case we prefer to use default VPCs in any account under our organization.

My code is as simple as calling the boto3 create_db_instance method of docdb client object I tried to pass AZ as parameter but did not help either.

I really expected while creation of a new node, the cluster will launch it in one of the subnets associated in its subnet group definition considering a balance between AZs

    response = client.create_db_instance(
        DBInstanceIdentifier=newDBInstanceIdentifier,
        DBInstanceClass=pTargetDBInstanceClass,
        Engine=Engine,
        AvailabilityZone='eu-central-1b', # TO-DO
        DBClusterIdentifier=DBClusterIdentifier,
        CopyTagsToSnapshot=True,
        PromotionTier=pPromotionTier,
        EnablePerformanceInsights=True,
        PerformanceInsightsKMSKeyId=KmsKeyId
    )

Furthermore, I just realized that using below CLI command I can successfully launch a new read replica node The default VPC related error did not come up this time

create-db-instance --db-instance-identifier sandbox-03 --db-instance-class db.t3.medium --engine docdb --db-cluster-identifier docdb-sandbox
Eralper
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions