I am getting an error when I try to start aws query using python boto3
Error message:
There was an error in error_handler: An error occurred (AccessDeniedException) whencalling the StartQuery operation: User: arn:aws:sts::#########:assumed-role/cron-runner-production/ is not authorized to perform: logs:StartQuery on resource: arn:aws:logs:##-####-#:#########:log-group:/ecs/production:log-stream: because no identity-based policy allows the logs:StartQuery action
However, I added allowing policies:
statement {
effect = "Allow"
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:StartQuery",
"logs:GetQueryResults"
],
"Resource": "arn:aws:logs:##-####-#:#########:log-group:/aws/lambda/cron-runner-production:*"
]
}
Python code:
boto3_client = boto3.client('logs')
query_id = boto3_client.start_query(
logGroupName=log_group,
startTime=int((datetime.today() - timedelta(minutes=5)).timestamp()),
endTime=int(datetime.now().timestamp()),
queryString=query,
).get('queryId')
Also I getting warnings in AWS web console about "logs:StartQuery":
The actions in your policy do not support resource-level permissions and require you to choose All resources
Specify log-group resource ARN for the StartQuery and 1 more action