我在AWS Athena上创建了一张表格,可以运行任何查询而不会出错:
然而,我遇到了以下错误:
select * from mytestdb.test
表格有三列,分别是customer_Id, product_Id, price 。 |
我尝试使用boto3创建一个lambda函数来运行相同的查询:
import time
import boto3
DATABASE = 'mytestdb'
TABLE = 'test'
output='s3://mybucketons3/'
COLUMN = 'Customer_Id'
def lambda_handler(event, context):
keyword = 'xyz12345'
query = "SELECT * FROM %s.%s where %s = '%s';" % (DATABASE, TABLE, COLUMN, keyword)
client = boto3.client('athena')
# Execution
response = client.start_query_execution(
QueryString=query,
QueryExecutionContext={
'Database': DATABASE
},
ResultConfiguration={
'OutputLocation': output,
}
)
return
然而,我遇到了以下错误:
Response:
{
"errorMessage": "An error occurred (AccessDeniedException) when calling the StartQueryExecution operation: User: arn:aws:sts::076088932150:assumed-role/Test/QueryTest is not authorized to perform: athena:StartQueryExecution on resource: arn:aws:athena:us-west-2:076088932150:workgroup/primary",
"errorType": "ClientError",
看起来是访问问题,但我不确定原因,因为我使用的是相同账户下的Lambda和Athena数据库。