Use CreateScheduleGroup with an AWS SDK - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use CreateScheduleGroup with an AWS SDK

The following code examples show how to use CreateScheduleGroup.

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:

.NET
AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Creates a new schedule group in Amazon EventBridge Scheduler. /// </summary> /// <param name="name">The name of the schedule group.</param> /// <returns>True if the schedule group was created successfully, false otherwise.</returns> public async Task<bool> CreateScheduleGroupAsync(string name) { try { var request = new CreateScheduleGroupRequest { Name = name }; var response = await _amazonScheduler.CreateScheduleGroupAsync(request); Console.WriteLine($"Successfully created schedule group '{name}': {response.ScheduleGroupArn}."); return true; } catch (ConflictException ex) { // If the name is not unique, a ConflictException will be thrown. _logger.LogError($"Failed to create schedule group '{name}' due to a conflict. {ex.Message}"); return false; } catch (Exception ex) { _logger.LogError( $"An error occurred while creating schedule group '{name}': {ex.Message}"); return false; } }
Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/** * Creates a new schedule group. * * @param name the name of the schedule group to be created * @return a {@link CompletableFuture} representing the asynchronous operation of creating the schedule group */ public CompletableFuture<CreateScheduleGroupResponse> createScheduleGroup(String name) { CreateScheduleGroupRequest request = CreateScheduleGroupRequest.builder() .name(name) .build(); logger.info("Initiating createScheduleGroup call for group: {}", name); CompletableFuture<CreateScheduleGroupResponse> futureResponse = getAsyncClient().createScheduleGroup(request); futureResponse.whenComplete((response, ex) -> { if (ex != null) { if (ex instanceof CompletionException && ex.getCause() instanceof ConflictException) { // Rethrow the ConflictException throw (ConflictException) ex.getCause(); } else { throw new CompletionException("Failed to create schedule group: " + name, ex); } } else if (response == null) { throw new RuntimeException("Failed to create schedule group: response was null"); } else { logger.info("Successfully created schedule group '{}': {}", name, response.scheduleGroupArn()); } }); return futureResponse; }
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.

class SchedulerWrapper: def __init__(self, eventbridge_scheduler_client: client): self.scheduler_client = eventbridge_scheduler_client @classmethod def from_client(cls) -> "SchedulerWrapper": """ Creates a SchedulerWrapper instance with a default EventBridge Scheduler client. :return: An instance of SchedulerWrapper initialized with the default EventBridge Scheduler client. """ eventbridge_scheduler_client = boto3.client("scheduler") return cls(eventbridge_scheduler_client) def create_schedule_group(self, name: str) -> str: """ Creates a new schedule group with the specified name and description. :param name: The name of the schedule group. :param description: The description of the schedule group. :return: The ARN of the created schedule group. """ try: response = self.scheduler_client.create_schedule_group(Name=name) return response["ScheduleGroupArn"] except ClientError as err: if err.response["Error"]["Code"] == "ConflictException": logger.error( "Failed to create schedule group '%s' due to a conflict. %s", name, err.response["Error"]["Message"], ) else: logger.error( "Error creating schedule group: %s", err.response["Error"]["Message"], ) raise