Lambda Python请求雅典娜错误OutputLocation [英] Lambda Python request athena error OutputLocation
问题描述
我正在使用AWS Lambda,我想在雅典娜中进行一个简单的查询并将我的数据存储在s3中。
I'm working with AWS Lambda and I would like to make a simple query in athena and store my data in an s3.
我的代码:
import boto3
def lambda_handler(event, context):
query_1 = "SELECT * FROM test_athena_laurent.stage limit 5;"
database = "test_athena_laurent"
s3_output = "s3://athena-laurent-result/lambda/"
client = boto3.client('athena')
response = client.start_query_execution(
QueryString=query_1,
ClientRequestToken='string',
QueryExecutionContext={
'Database': database
},
ResultConfiguration={
'OutputLocation': 's3://athena-laurent-result/lambda/'
}
)
return response
它在spyder 2.7上有效,但在AWS中却出现此错误:
It works on spyder 2.7 but in AWS I have this error :
Parameter validation failed:
Invalid length for parameter ClientRequestToken, value: 6, valid range: 32-inf: ParamValidationError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 18, in lambda_handler
'OutputLocation': 's3://athena-laurent-result/lambda/'
我认为它不理解我的道路, d我不知道为什么。
I think that It doesn't understand my path and I don't know why.
谢谢
推荐答案
每@Tomalak的指向 ClientRequestToken
是字符串。但是,根据我刚刚链接的文档,使用SDK时无论如何都不需要它。
Per @Tomalak's point ClientRequestToken
is a string. However, per the documentation I just linked, you don't need it anyway when using the SDK.
此令牌被列为不需要因为AWS开发工具包(例如适用于Java的AWS开发工具包)自动为用户生成令牌。如果您未使用AWS开发工具包或AWS CLI,则必须提供此令牌,否则操作将失败。
This token is listed as not required because AWS SDKs (for example the AWS SDK for Java) auto-generate the token for users. If you are not using the AWS SDK or the AWS CLI, you must provide this token or the action will fail.
所以,我可以这样重构:
So, I would refactor as such:
import boto3
def lambda_handler(event, context):
query_1 = "SELECT * FROM some_database.some_table limit 5;"
database = "some_database"
s3_output = "s3://some_bucket/some_tag/"
client = boto3.client('athena')
response = client.start_query_execution(QueryString = query_1,
QueryExecutionContext={
'Database': database
},
ResultConfiguration={
'OutputLocation': s3_output
}
)
return response
这篇关于Lambda Python请求雅典娜错误OutputLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!