使用 Aurora Serverless Data API 时是否传入 IAM 凭据?

Passing in IAM credentials when using the Aurora Serverless Data API?

我正在尝试弄清楚在使用 AWS 数据 API 与 Aurora Serverless 数据库交互时如何传递静态 IAM AWS 凭证。

我正在使用 AWS Python Boto 库,我像这样从 table 读取数据(默认情况下使用我的 ~/. aws/credentials 文件):

rds_client = boto3.client('rds-data')
rds_client.execute_statement(
        secretArn=self.db_credentials_secrets_store_arn,
        database=self.database_name,
        resourceArn=self.db_cluster_arn,
        sql='SELECT * FROM TestTable;',
        parameters=[])

这成功了。

但我希望能够将 AWS 访问密钥和密钥作为参数传递给 execute_statement 调用,例如:

rds_client.execute_statement(
        accessKey='XXX',
        secretKey='YYY',
        secretArn=self.db_credentials_secrets_store_arn,
        database=self.database_name,
        resourceArn=self.db_cluster_arn,
        sql='SELECT * FROM TestTable;',
        parameters=[])

但这不起作用。

关于如何实现这一点有什么想法吗?

谢谢!

为此,您需要创建一个新函数来获取访问密钥和秘密密钥,为该用户创建一个客户端,然后进行调用。

def execute_statement_with_iam_user(accessKey, secretKey):
    rds_client = boto3.client(
        'rds',
        aws_access_key_id=accessKey,
        aws_secret_access_key=secretKey
    )
    rds_client.execute_statement(
            secretArn=self.db_credentials_secrets_store_arn,
            database=self.database_name,
            resourceArn=self.db_cluster_arn,
            sql='SELECT * FROM TestTable;',
            parameters=[])

execute_statement_with_iam_user(accessKey, secretkey)

仅供参考,AWS does not recommend hard coding your credentials like this. What you should be doing is assuming a role with a temporary session. For this, you would need to look into the sts client and creating roles for assumption