What is @aws-sdk/client-scheduler?
@aws-sdk/client-scheduler is an AWS SDK client that allows you to interact with the Amazon EventBridge Scheduler service. This service enables you to create, manage, and execute scheduled tasks and events in AWS. You can use it to automate tasks, trigger events at specific times, and manage schedules programmatically.
What are @aws-sdk/client-scheduler's main functionalities?
Create a Schedule
This code sample demonstrates how to create a new schedule using the @aws-sdk/client-scheduler package. The schedule triggers a Lambda function every 5 minutes.
const { SchedulerClient, CreateScheduleCommand } = require('@aws-sdk/client-scheduler');
const client = new SchedulerClient({ region: 'us-west-2' });
const params = {
Name: 'MySchedule',
ScheduleExpression: 'rate(5 minutes)',
Target: {
Arn: 'arn:aws:lambda:us-west-2:123456789012:function:MyFunction',
RoleArn: 'arn:aws:iam::123456789012:role/MyRole'
}
};
const command = new CreateScheduleCommand(params);
client.send(command).then(
(data) => console.log(data),
(error) => console.error(error)
);
List Schedules
This code sample demonstrates how to list all existing schedules using the @aws-sdk/client-scheduler package.
const { SchedulerClient, ListSchedulesCommand } = require('@aws-sdk/client-scheduler');
const client = new SchedulerClient({ region: 'us-west-2' });
const command = new ListSchedulesCommand({});
client.send(command).then(
(data) => console.log(data.Schedules),
(error) => console.error(error)
);
Delete a Schedule
This code sample demonstrates how to delete an existing schedule using the @aws-sdk/client-scheduler package.
const { SchedulerClient, DeleteScheduleCommand } = require('@aws-sdk/client-scheduler');
const client = new SchedulerClient({ region: 'us-west-2' });
const params = { Name: 'MySchedule' };
const command = new DeleteScheduleCommand(params);
client.send(command).then(
(data) => console.log(data),
(error) => console.error(error)
);
Other packages similar to @aws-sdk/client-scheduler
node-cron
node-cron is a lightweight npm package for scheduling tasks in Node.js using cron syntax. Unlike @aws-sdk/client-scheduler, which integrates with AWS services, node-cron is a standalone package that runs scheduled tasks locally within your Node.js application.
agenda
Agenda is a job scheduling package for Node.js that uses MongoDB for persistence. It provides more advanced scheduling features compared to @aws-sdk/client-scheduler, such as job prioritization and concurrency control. However, it does not integrate directly with AWS services.
bree
Bree is a job scheduler for Node.js that uses worker threads to run jobs. It supports cron syntax and provides features like graceful shutdown and job retries. Unlike @aws-sdk/client-scheduler, Bree is designed to run within your Node.js application and does not integrate with AWS services.