AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
DeleteSchedule
搭配使用 AWS SDK
以下代码示例演示如何使用 DeleteSchedule
。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /// <summary> /// Deletes an existing schedule from Amazon EventBridge Scheduler. /// </summary> /// <param name="name">The name of the schedule to delete.</param> /// <param name="groupName">The group name of the schedule to delete.</param> /// <returns>True if the schedule was deleted successfully, false otherwise.</returns> public async Task<bool> DeleteScheduleAsync(string name, string groupName) { try { var request = new DeleteScheduleRequest { Name = name, GroupName = groupName }; await _amazonScheduler.DeleteScheduleAsync(request); Console.WriteLine($"Successfully deleted schedule with name '{name}'."); return true; } catch (ResourceNotFoundException ex) { _logger.LogError( $"Failed to delete schedule with ID '{name}' because the resource was not found: {ex.Message}"); return true; } catch (Exception ex) { _logger.LogError( $"An error occurred while deleting schedule with ID '{name}': {ex.Message}"); return false; } }
-
有关API详细信息,请参阅 “AWS SDK for .NET API参考 DeleteSchedule” 中的。
-
- Java
-
- SDK适用于 Java 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /** * Deletes a schedule with the specified name and group name. * * @param name the name of the schedule to be deleted * @param groupName the group name of the schedule to be deleted * @return a {@link CompletableFuture} that, when completed, indicates whether the schedule was successfully deleted * @throws CompletionException if an error occurs while deleting the schedule, except for the case where the schedule is not found */ public CompletableFuture<Boolean> deleteScheduleAsync(String name, String groupName) { DeleteScheduleRequest request = DeleteScheduleRequest.builder() .name(name) .groupName(groupName) .build(); CompletableFuture<DeleteScheduleResponse> response = getAsyncClient().deleteSchedule(request); return response.handle((result, ex) -> { if (ex != null) { if (ex instanceof ResourceNotFoundException) { throw new CompletionException("Resource not found while deleting schedule with ID: " + name, ex); } else { throw new CompletionException("Failed to delete schedule.", ex); } } logger.info("Successfully deleted schedule with name {}.", name); return true; }); }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 DeleteSchedule” 中的。
-
- 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 delete_schedule(self, name: str, schedule_group_name: str) -> None: """ Deletes the schedule with the specified name and schedule group. :param name: The name of the schedule. :param schedule_group_name: The name of the schedule group. """ try: self.scheduler_client.delete_schedule( Name=name, GroupName=schedule_group_name ) except ClientError as err: if err.response["Error"]["Code"] == "ResourceNotFoundException": logger.error( "Failed to delete schedule with ID '%s' because the resource was not found: %s", name, err.response["Error"]["Message"], ) else: logger.error( "Error deleting schedule: %s", err.response["Error"]["Message"] ) raise
-
有关API详细信息,请参阅DeleteSchedule中的 AWS SDKPython (Boto3) API 参考。
-
CreateScheduleGroup
DeleteScheduleGroup