如何使用boto3在lambda调用具有动态参数的redshift存储过程?

0

【以下的问题经过翻译处理】 我有一个lambda函数需要调用redshift中的存储过程,其中一个参数的值在运行时未知。我在调用中缩小了代码范围:

response = rs_client.execute_statement(
            ClusterIdentifier='my_cluster_name',
            Database='my_db_name',
            DbUser='my_user'',
            Sql='call my_schema.this_is_my_proc()',
            Parameters=[{'name': 'in_param', 'value': 'this is the parameter'}],
            StatementName='Test of SP call'
        )

上述代码可以在凭据正常的情况下(我已将其匿名化),也可以在没有参数和在Sql参数中硬编码参数的情况下运行,即Sql=call my_schema.this_is_my_proc('this is hardcoded'),因此问题不在此处。我还尝试了将参数传递为格式化字符串的方式:

param = 'this is the parameter'
stmnt = f'call my_schema.this_is_my_proc({param})',


我从lambda函数测试执行中得到的异常是: An error occurred (ValidationException) when calling the ExecuteStatement operation: Parameters list contains unused parameters. Unused parameters: [in_param]

是否可以从lambda函数调用具有参数的Redshift存储过程?

TIA

profile picture
专家
已提问 5 个月前14 查看次数
1 回答
0

【以下的回答经过翻译处理】 你好, 如文档中所述(https://docs.aws.amazon.com/redshift/latest/mgmt/data-api.html),参数应该以:parameter的格式在sql语句中进行输入。

根据文档,你的代码应该长这样:


response = rs_client.execute_statement(
            ClusterIdentifier='my_cluster_name',
            Database='my_db_name',
            DbUser='my_user'',
            Sql='call my_schema.this_is_my_proc(:in_param)',
            Parameters=[{'name': 'in_param', 'value': '此为参数'}],
            StatementName='测试存储过程调用'
        )


希望这可以帮到你

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则