AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
CreateScheduleGroup
搭配使用 AWS SDK
以下代码示例演示如何使用 CreateScheduleGroup
。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /// <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; } }
-
有关API详细信息,请参阅 “AWS SDK for .NET API参考 CreateScheduleGroup” 中的。
-
- Java
-
- SDK适用于 Java 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /** * 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; }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 CreateScheduleGroup” 中的。
-
- Python
-
- SDK适用于 Python (Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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
-
有关API详细信息,请参阅CreateScheduleGroup中的 AWS SDKPython (Boto3) API 参考。
-
CreateSchedule
DeleteSchedule