Home > Back-end >  How to know mock postgres host name?
How to know mock postgres host name?

Time:01-30

I´m trying to create some unit tests on a python aws lambda proyect using moto. I´ve created an rds postgres instance using:

@pytest.fixture(scope='function')
def rds(aws_credentials):
    with mock_rds():
        yield boto3.client("rds", region_name="us-west-2").create_db_instance(
            DBInstanceIdentifier="db-master-1",
            AllocatedStorage=10,
            Engine="postgres",
            DBName="fox-postgres",
            DBInstanceClass="db.m1.small",
            LicenseModel="license-included",
            MasterUsername="postgres",
            MasterUserPassword="postgres",
            Port=5432,
            DBSecurityGroups=["my_sg"],
            VpcSecurityGroupIds=["sg-123456"],
            EnableCloudwatchLogsExports=["audit", "error"],
        )

How do I know (or set) the host name in order to run queries? Is that even possible? I don´t know if this is a real (or almost) database instance.

Thanks in advance.

CodePudding user response:

It is not possible to run actual queries against Moto - RDS responses are completely mocked.

Moto's describe_db_instances-method does return an endpoint in the Endpoint.Address-attribute, but this is hardcoded - see https://github.com/getmoto/moto/blob/339309c9af4188006d9592469d52193f57249b1e/moto/rds/models.py#L674

  • Related