There are more AWS SDK examples available in the AWS Doc SDK Examples
Use CreateWorkGroup with an AWS SDK or CLI
The following code examples show how to use CreateWorkGroup.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- CLI
-
- AWS CLI
-
To create a workgroup
The following
create-work-groupexample creates a workgroup calledData_Analyst_Groupthat has the query results output locations3://amzn-s3-demo-bucket. The command creates a workgroup that overrides client configuration settings, which includes the query results output location. The command also enables CloudWatch metrics and adds three key-value tag pairs to the workgroup to distinguish it from other workgroups. Note that the--configurationargument has no spaces before the commas that separate its options.aws athena create-work-group \ --nameData_Analyst_Group\ --configuration ResultConfiguration={OutputLocation="s3://amzn-s3-demo-bucket"},EnforceWorkGroupConfiguration="true",PublishCloudWatchMetricsEnabled="true" \ --description"Workgroup for data analysts"\ --tagsKey=Division,Value=WestKey=Location,Value=SeattleKey=Team,Value="Big Data"This command produces no output. To see the results, use
aws athena get-work-group --work-group Data_Analyst_Group.For more information, see Managing Workgroups in the Amazon Athena User Guide.
-
For API details, see CreateWorkGroup
in AWS CLI Command Reference.
-
- Python
-
- SDK for Python (Boto3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. def create_work_group( self, name: str, output_location: str, description: str = "Created by Athena basics scenario", ) -> None: """ Creates an Athena workgroup with the specified name and configuration. :param name: The name for the new workgroup. :param output_location: The S3 location for query results (e.g., s3://bucket/prefix/). :param description: A description for the workgroup. :raises ClientError: If the workgroup could not be created. """ try: self.athena_client.create_work_group( Name=name, Configuration={ "ResultConfiguration": { "OutputLocation": output_location, }, "EnforceWorkGroupConfiguration": True, "PublishCloudWatchMetricsEnabled": True, }, Description=description, ) logger.info("Created workgroup '%s'.", name) except ClientError as err: if err.response["Error"]["Code"] == "InvalidRequestException": logger.error( "Invalid request creating workgroup '%s'. The name may already " "exist or the configuration is invalid. %s: %s", name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise-
For API details, see CreateWorkGroup in AWS SDK for Python (Boto3) API Reference.
-