Skip to content

hexlabsio/eventbridge-schedule-expressions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eventbridge Schedule Expressions

Typescript Build NPM Version

A small Typescript package that checks AWS EventBridge Scheduler scheduled expressions are valid at compile time. Cron expressions are incredibly powerful but mistakes can be easily made.

Typescripts type system can be used to give better validation that plain strings enforcing rules such as cron minute values are being between 0-59 while hours between 0-23

Cron Expressions

Cron expression

Rate Expressions

Rate expression

Formats

Expression formats are takes from the AWS Schedule Expressions syntax. Feel free to create an issue if you find anything that breaks these formats.

Installation

npm install --save-dev @hexlabs/eventbridge-schedule-expressions

Usage

import {scheduleExpression} from '@hexlabs/eventbridge-schedule-expressions';

aws.schedulerSchedule({
    groupName: schedulerGroup.name,
    name: 'sheduler',
    scheduleExpression: scheduleExpression('cron(0 * * * ? *)'),
    target: {arn: lambda.attributes.Arn, roleArn: schedulerRole.attributes.Arn},
    flexibleTimeWindow: {mode: 'OFF'},
  },
);

CDK

import {scheduleExpression} from '@hexlabs/eventbridge-schedule-expressions';

new CfnSchedule(this, 'my-schedule', {
  groupName: schedulerGroup.name,
  scheduleExpression:  scheduleExpression('cron(5,35 * * * ? *)'),
  target: {
    arn: lambdaFunction.functionArn,
    roleArn: schedulerRole.roleArn,
  },
  flexibleTimeWindow: {
    mode: 'OFF',
  },
});

AWS SDK

  import {scheduleExpression} from '@hexlabs/eventbridge-schedule-expressions';

  await eventBridge.putRule({
    Name: 'Rule-Name',
    ScheduleExpression: scheduleExpression('cron(5,35 * * * ? *)')
  }).promise();

About

Typesafe cron and rate expressions for AWS EventBridge Scheduler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published