forked from aws/aws-cdk
/
integ.triggers.ts
43 lines (35 loc) · 1.37 KB
/
integ.triggers.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
39
40
41
42
43
import * as lambda from '@aws-cdk/aws-lambda';
import * as sns from '@aws-cdk/aws-sns';
import { App, Duration, Stack } from '@aws-cdk/core';
import * as triggers from '../lib';
import { InvocationType } from '../lib';
const app = new App();
const stack = new Stack(app, 'MyStack');
const topic1 = new sns.Topic(stack, 'Topic1');
const topic2 = new sns.Topic(stack, 'Topic2');
const triggerFunction = new triggers.TriggerFunction(stack, 'MyTriggerFunction', {
runtime: lambda.Runtime.NODEJS_16_X,
handler: 'index.handler',
code: lambda.Code.fromInline('exports.handler = function() { console.log("hi"); };'),
executeBefore: [topic1],
});
const func = new lambda.Function(stack, 'MyLambdaFunction', {
runtime: lambda.Runtime.NODEJS_16_X,
handler: 'index.handler',
timeout: Duration.minutes(15),
code: lambda.Code.fromInline('exports.handler = function() { await setTimeout(3*60*1000, "hi"); };'),
});
const trigger = new triggers.Trigger(stack, 'MyTrigger', {
handler: func,
invocationType: InvocationType.EVENT,
timeout: Duration.minutes(1),
executeAfter: [topic1],
});
triggerFunction.executeAfter(topic2);
trigger.executeAfter(topic2);
new triggers.TriggerFunction(stack, 'MySecondFunction', {
runtime: lambda.Runtime.NODEJS_16_X,
handler: 'index.handler',
code: lambda.Code.fromInline('exports.handler = function() { console.log("hello"); };'),
});
app.synth();