aws / aws/aws-cdk

aws-lambda: introduce `Function.addSchedule()` integration with EventBridge Scheduler

Open
#32,266 3 comments 3 reactions 0 assignees View on GitHub
@aws-cdk/aws-lambda effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

Currently, you need to write the following code to invoke a function on a schedule:

```ts
import { join } from "path";
import {
Schedule,
ScheduleExpression,
} from "@aws-cdk/aws-scheduler-alpha";
import { LambdaInvoke } from "@aws-cdk/aws-scheduler-targets-alpha";
import { Duration, Stack, StackProps } from "aws-cdk-lib";
import { Architecture, LoggingFormat, Runtime } from "aws-cdk-lib/aws-lambda";
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
import { Construct } from "constructs";

export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);

const cronFunction = new NodejsFunction(this, `CronFunction`, {
functionName: `cron-function`,
entry: join(__dirname, "..", "functions", "cron", "index.ts"),
runtime: Runtime.NODEJS_22_X,
architecture: Architecture.ARM_64,
memorySize: 1024,
timeout: Duration.minutes(1),
loggingFormat: LoggingFormat.JSON,
});

new Schedule(this, "RateBasedSchedule", {
scheduleName: "rate-based-schedule",
schedule: ScheduleExpression.rate(Duration.minutes(1)),
target: new LambdaInvoke(cronFunction),
});
}
}
```

### Use Case

The code could be optimized by introducing a native integration between AWS Lambda and EventBridge Scheduler.

### Proposed Solution

```ts
import { join } from "path";
import { ScheduleExpression } from "@aws-cdk/aws-scheduler-alpha";
import { Duration, Stack, StackProps } from "aws-cdk-lib";
import { Architecture, LoggingFormat, Runtime } from "aws-cdk-lib/aws-lambda";
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
import { Construct } from "constructs";

export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);

const cronFunction = new NodejsFunction(this, `CronFunction`, {
functionName: `cron-function`,
entry: join(__dirname, "..", "functions", "cron", "index.ts"),
runtime: Runtime.NODEJS_22_X,
architecture: Architecture.ARM_64,
memorySize: 1024,
timeout: Duration.minutes(1),
loggingFormat: LoggingFormat.JSON,
});

cronFunction.addSchedule({
schedule: ScheduleExpression.rate(Duration.minutes(1)),
});
}
}
```

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.170.0

### Environment details (OS name and version, etc.)

Ubuntu 24.04 LTS

Contributor guide

Open the contributing guide

Research direction

Begin at the proposed cronFunction.addSchedule entry point and compare the current Schedule/LambdaInvoke usage shown in the issue. Confirm that the native integration supports the stated rate expression and equivalent scheduled Lambda invocation behavior; done means the proposed API works for this use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.