A construct that creates a scheduler to invoke a Lambda function at sub-minute intervals.

This construct leverages AWS Step Functions and EventBridge to invoke a Lambda function multiple times per minute based on the specified interval. It is designed for use cases where a Lambda function needs to be triggered more frequently than once per minute.

The construct defines a Step Functions state machine that invokes the Lambda function and waits for the next iteration based on the provided interval. An EventBridge rule is used to trigger the state machine every minute.

import { Stack } from 'aws-cdk-lib';
import { lambda } from '@reuters-graphics/structs';

export class MyLambdaStack extends Stack {
constructor(scope: Construct, id: string, props: LambdaStackProps) {
super(scope, id, props);

const myLambda = new lambda.NodeJSLambda(this, 'my-lambda', {
entry: './src/index.ts',
handler: 'handle',
});

const schedule = new lambda.schedulers.SubMinuteLambdaScheduler(
this,
'my-lambda-schedule',
{
interval: 15,
lambdaFunction: myLambda.lambda,
enabled: true,
}
);

schedule.eventsRule; // EventBridge rule
schedule.stepFunction; // Step Functions state machine
}
};

Hierarchy

  • Construct
    • SubMinuteLambdaScheduler

Constructors

  • Constructs a new instance of the SubMinuteLambdaScheduler.

    Parameters

    • scope: Construct

      The scope in which this construct is defined.

    • id: string

      The scoped construct ID.

    • props: SubMinuteLambdaSchedulerOptions

      The properties to configure the scheduler.

    Returns SubMinuteLambdaScheduler

    Will throw an error if the interval does not evenly divide 60 seconds.

Properties

stepFunction: StateMachine

The AWS Step Functions state machine that controls the invocation schedule.

eventsRule: Rule

The EventBridge rule that triggers the Step Functions state machine every minute.

node: Node

The tree node.

Methods

  • Checks if x is a construct.

    Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

    Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

    Parameters

    • x: any

      Any object

    Returns x is Construct

    true if x is an object created from a class which extends Construct.

  • Returns a string representation of this construct.

    Returns string