Use workgroups to separate users, teams, applications, or workloads, to set limits on amount of data each query or the entire workgroup can process, and to track costs. Because workgroups act as resources, you can use resource-level identity-based policies to control access to a specific workgroup
Click on workgroupA and click on View details
We will now set the maximum data scanned by any query in this workgroup to be 100 MB. Click on Data usage controls and enter 100 MB for Data limits and click Update.
Open Cloudformation and open the stack named Athena-Workshop and click on Outputs.
Click on the ConsoleLogin link. Enter the following values:
IAM user name: userA
Once logged in open Athena console, enter a default location for query result location and then click on Workgroup : primary. Click on workgroupA and click Switch workgroup.
Try running the following query which should succeed and you would see it scanned around 57 MB of data.
/* Let's try to find the products by number of reviews and avg star rating in Mobile_Apps category */
SELECT product_id, product_title, count(*) as num_reviews, avg(star_rating) as avg_stars
FROM amazon_reviews_parquet where product_category='Mobile_Apps'
GROUP BY 1, 2
ORDER BY 3 DESC
Try running this query which will try to scan more data than 100 MB and see if the query succeeds or fails.
/* Let's try to find the products and their corresponding category by number of reviews and avg star rating on parquet table */
SELECT product_id, product_category, product_title, count(*) as num_reviews, avg(star_rating) as avg_stars
GROUP BY 1, 2, 3
ORDER BY 4 DESC
Next lets try to switch the workgroup and see if the userA is able to run the same queries in workgroup B. You should see an error that the userA is not authorized to run queries in workgroupB as he doesn’t have necessary permissions.
Switch back the workgroup to workgroupA and click on view details → Metrics. This is where the cloud watch metrics would get published for the workgroup.
Above steps shows control limits on per-query execution within a workgroup. You can also define workgroup-wide data usage control limit and also check metrics for various queries in each workgroup.