gpt4 book ai didi

python - 如何使用 boto3 获取 RDS 实例的主机

转载 作者:行者123 更新时间:2023-12-02 02:18:58 26 4
gpt4 key购买 nike

我需要获取 RDS 实例的主机。我尝试这样做:

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

也许您可以提出可能存在问题的建议。预先感谢您!

最佳答案

基于the boto3 docs for describe_db_instances ,响应是一本字典。要访问您的特定数据库实例,请按如下方式访问:

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']

关于python - 如何使用 boto3 获取 RDS 实例的主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45814199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com