-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscheduled-lambda.ts
38 lines (32 loc) · 1.22 KB
/
scheduled-lambda.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Rule, RuleTargetInput, Schedule } from '@aws-cdk/aws-events';
import { LambdaFunction } from '@aws-cdk/aws-events-targets';
import { Function, FunctionProps } from '@aws-cdk/aws-lambda';
import { Construct } from '@aws-cdk/core';
export interface ScheduledLambdaProps extends FunctionProps {
/**
* The schedule or rate (frequency) that determines when CloudWatch Events
* triggers the Lambda function. For more information, see Schedule Expression Syntax for
* Rules in the Amazon CloudWatch User Guide.
*
* @see http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
*/
readonly schedule : Schedule;
/**
* The input to send to the lambda
*
* @default - use the CloudWatch Event
*/
readonly input? : RuleTargetInput;
}
export class ScheduledLambda extends Function {
constructor(scope : Construct, id : string, props : ScheduledLambdaProps) {
super(scope, id, props);
new Rule(this, 'Rule', {
description: 'Rule to trigger scheduled lambda function',
schedule: props.schedule,
targets: [
new LambdaFunction(this, {event: props.input}),
],
});
}
}