I need to get host for RDS instance. I tried to do it like this:
import boto3
region = 'eu-west-1'
db_instance = 'db-instance-identifier'
def lambda_handler(event, context):
source = boto3.client('rds', region_name=region)
try:
instances = source.describe_db_instances(DBInstanceIdentifier=db_instance)
rds_host = instances[0].endpoint.address
except Exception as e:
raise e
Perhaps you can suggest what might be the problem. Thank you in advance!
Based on the boto3 docs for describe_db_instances
, the response is a dictionary. To access your particular DB instance, access it as follows:
instances = source.describe_db_instances(DBInstanceIdentifier=db_instance)
rds_host = instances.get('DBInstances')[0].get('Endpoint').get('Address')
# or
# rds_host = instances.get('DBInstances')[0]['Endpoint']['Address']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With