import boto3 rds = boto3.client('rds') response = rds.describe_db_clusters(DBClusterIdentifier='your_cluster_identifier') cluster_arn = response['DBClusters'][0]['DBClusterArn']
import pymysql def lambda_handler(event, context): # 获取RDS集群arn rds = boto3.client('rds') response = rds.describe_db_clusters(DBClusterIdentifier='your_cluster_identifier') cluster_arn = response['DBClusters'][0]['DBClusterArn']
# 查询RDS
conn = pymysql.connect(host='your_rds_host', port=3306, user='your_username', password='your_password', db='your_db_name', ssl={'ca': '/etc/pki/rds-ca-cert.pem'}, cluster_arn=cluster_arn)
with conn.cursor() as cur:
cur.execute("SELECT * FROM your_table;")
result = cur.fetchall()
conn.commit()
conn.close()
return result
注意:以上示例使用pymysql库连接RDS。您还可以使用其他Python RDS客户端库,如psycopg2或sqlalchemy。