AWS不能使用SecretManager在查询编辑器中连接数据
创始人
2024-09-24 00:30:30
0
  1. 确认Secret Manager中的凭证是否已正确配置,其中包含了正确的数据库连接信息和凭证。

  2. 在查询编辑器中使用以下代码,确保环境变量已正确设置,并使用正确的凭证访问Secrets Manager获取数据库凭证信息,以便连接数据库:

import boto3 import os

def get_secret(): secret_name = "my/db/credentials" region_name = "us-west-2"

session = boto3.session.Session() 
client = session.client( 
    service_name='secretsmanager', 
    region_name=region_name) 

get_secret_value_response = client.get_secret_value( 
    SecretId=secret_name) 

if 'SecretString' in get_secret_value_response: 
    secret = get_secret_value_response['SecretString'] 
else: 
    secret = base64.b64decode(get_secret_value_response['SecretBinary']) 

return secret 

db_credentials = json.loads(get_secret())

Retrieve database access credentials from Secrets Manager

database = db_credentials["database"] username = db_credentials["username"] password = db_credentials["password"] host = db_credentials["host"] port = str(db_credentials["port"])

Use credentials to connect to database

conn = psycopg2.connect( database=database, user=username, password=password, host=host, port=port)

  1. 如果仍然遇到问题,则通过查看 CloudWatch 日志,查找问题并进行排除。

注意:以上代码仅适用于PostgreSQL数据库。如果使用其他数据库,请更改适当的连接语法。

相关内容

热门资讯

今日科普!微信卡五星辅助器,微... 今日科普!微信卡五星辅助器,微乐自建房脚本免费入口(开挂自建房)攻略;1.微信卡五星辅助器 选牌创建...
重大通报!微乐自建房辅助工具挂... 重大通报!微乐自建房辅助工具挂,微乐小程序免费黑科技(开挂自建房)app1、打开软件启动之后找到中间...
让我来分享经验!微乐自建房辅助... 让我来分享经验!微乐自建房辅助工具免费app,微乐自建房脚本免费入口(开挂自建房)脚本1、微乐自建房...
记者揭秘!微乐小程序自建房辅助... 记者揭秘!微乐小程序自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)软件微乐小程序自建房辅助...
必看攻略!微乐自建房辅助工具免... 必看攻略!微乐自建房辅助工具免费app,微乐家乡麻将自建房辅助app(开挂自建房)攻略1、每一步都需...
必备攻略!微乐家乡麻将自建房辅... 必备攻略!微乐家乡麻将自建房辅助app,微乐家乡麻将自建房辅助app(开挂自建房)技巧1、必备攻略!...
查到实测辅助!微信卡五星辅助器... 查到实测辅助!微信卡五星辅助器,微乐家乡麻将自建房辅助app(开挂自建房)教程1、超多福利:超高返利...
传递经验!微乐自建房辅助工具挂... 传递经验!微乐自建房辅助工具挂,微乐小程序免费黑科技(开挂自建房)技巧1、操作简单,无需微乐自建房辅...
一分钟教你!微信卡五星辅助器,... 一分钟教你!微信卡五星辅助器,微乐家乡麻将自建房辅助app(开挂自建房)插件1、这是跨平台的微乐家乡...
传递经验!微乐小程序自建房辅助... 传递经验!微乐小程序自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)脚本传递经验!微乐小程序...