I am following https://davidpallmann.hashnode.dev/hello-athena to connect to Athena from VS 2022 C# using AWSSDK.Athena.
In C# code var result = await _client.StartQueryExecutionAsync(queryRequest)
, I am getting the below error.
"You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again."
When I query on AWS Athena, I need to switch the Role to say "myRole", and also need to switch the Workgroup from primary to another Workgroup, say "mycompany-workgroup", then I can run the query successfully.
If I don’t switch the workgroup to "mycompany-workgroup", I am getting a similar error
"You are not authorized to perform: athena:GetWorkGroup on the resource. After your AWS administrator or you have updated your permissions, please try again."
How in my C# code can I switch Role to "myRole" ?
_client = new AmazonAthenaClient(Amazon.RegionEndpoint.USEast1);
var queryRequest = new StartQueryExecutionRequest
{
QueryString = "SELECT * from myDB.myTable",
QueryExecutionContext = new QueryExecutionContext()
{
Database = "myDB"
},
WorkGroup = "myWorkgroup"
};
Thank you
2
Answers
In
StartQueryExecutionRequest
class, there isWorkGroup
property. You can use that property to specify the name of the workgroup in which you want to run the query.Reference – StartQueryExecutionRequest : AmazonAthenaRequest
I got an Athena query working with .NET Service Client (V3). See the output here:
Here is the .NET code that works. Make sure you specify you bucket name, etc to get this program to work successfully. Notice you can specify the working group on the StartQueryExecutionRequest object. For more information, see How workgroups work.