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
Logging AWS Communication
make_client accepts an optional [SharedInterceptor]. By passing an interceptor that
implements aws_sdk_scheduler::config::Intercept, you can run custom logic — such as
logging — every time the client communicates with AWS.
The interceptor below logs each request, response, and operation result. It uses the
tracing crate, which is also what the AWS SDK uses
internally.
use make_client;
use ;
type BoxError = ;
;
# async
tracing does not emit anything until a subscriber is initialized. Set one up once in your
application (for example with tracing-subscriber) and control verbosity with RUST_LOG:
// Add `tracing-subscriber` to your dependencies.
fmt
.with_env_filter
.init;
Example output (RUST_LOG=info):
INFO SchedulerLoggingInterceptor: Scheduler -> AWS request method=POST uri=https://scheduler.ap-northeast-1.amazonaws.com/
INFO SchedulerLoggingInterceptor: AWS -> Scheduler response status=200
INFO SchedulerLoggingInterceptor: Scheduler operation succeeded
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
- 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.
- The client uses the AWS SDK's default credential chain, supporting IAM roles, environment variables, and other standard authentication methods.
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.