aws_utils_scheduler
A Rust wrapper for AWS EventBridge Scheduler with type-safe builders for schedule expressions.
Overview
aws_utils_scheduler provides a convenient and type-safe interface for working with AWS EventBridge Scheduler. It includes:
- Simple client creation with optional endpoint configuration
- Type-safe builders for schedule expressions (at, rate, cron)
- Stream-based pagination for listing schedules
- Comprehensive error handling
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Creating a Client
use aws_utils_scheduler;
use Duration;
async
Creating Schedules
One-time Schedule (At Expression)
use ;
use ;
use ;
let future_time = now + hours;
let at_expression = new.build?;
let target = builder
.arn
.role_arn
.build
.unwrap;
let flexible_window = builder
.mode
.build
.unwrap;
create_schedule.await?;
Recurring Schedule (Rate Expression)
use ;
use ;
let rate_expression = new.build?;
let target = builder
.arn
.role_arn
.build
.unwrap;
let flexible_window = builder
.mode
.build
.unwrap;
create_schedule.await?;
Cron Schedule
use CronExpressionBuilder;
use ;
let cron_expression = new
.minutes
.hours
.days_of_month
.months
.days_of_week
.build?;
let target = builder
.arn
.role_arn
.build
.unwrap;
let flexible_window = builder
.mode
.build
.unwrap;
create_schedule.await?;
Listing Schedules
Stream-based Listing
use TryStreamExt;
let stream = list_schedules_stream;
pin_mut!;
while let Some = stream.try_next.await?
Batch Listing
let schedules = list_schedules_all.await?;
for schedule in schedules
Other Operations
use ;
// Get schedule details
let schedule = get_scheduler.await?;
// Update a schedule
let target = builder
.arn
.role_arn
.build
.unwrap;
let flexible_window = builder
.mode
.build
.unwrap;
update_schedule.await?;
// Delete a schedule
delete_schedule.await?;
Schedule Expression Builders
AtExpressionBuilder
Creates one-time schedules that run at a specific date and time.
use Utc;
let at_expr = new.build?;
// Returns: "at(2024-01-02T15:30:00)"
RateExpressionBuilder
Creates recurring schedules that run at regular intervals.
let rate_expr = new.build?;
// Returns: "rate(30 minutes)"
CronExpressionBuilder
Creates schedules using cron expressions for complex timing requirements.
let cron_expr = new
.minutes
.hours
.days_of_month
.months
.days_of_week
.build?;
// Returns: "cron(0 9 * * MON-FRI)"
Error Handling
The crate provides comprehensive error handling through the SchedulerError enum:
use SchedulerError;
match create_schedule.await
Important Notes
- All client creation functions (
make_client,make_client_with_timeout,make_client_with_timeout_default) set dummy AWS credentials if they're not already present in the environment. This is useful for local development with tools like LocalStack. - The
make_client_with_timeout_defaultfunction provides reasonable default timeout values (connect: 3100s, operation: 60s, operation attempt: 55s, read: 50s) suitable for most use cases. - All schedule names must be unique within a schedule group.
- The IAM role must have the necessary permissions to invoke the target.
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.