-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless_http_checker-stack.js
36 lines (28 loc) · 1.24 KB
/
serverless_http_checker-stack.js
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
const sns = require('@aws-cdk/aws-sns');
const subs = require('@aws-cdk/aws-sns-subscriptions');
const events = require('@aws-cdk/aws-events');
const targets = require('@aws-cdk/aws-events-targets');
const lambda = require('@aws-cdk/aws-lambda');
const cdk = require('@aws-cdk/core');
const fs = require('fs');
class ServerlessHttpCheckerStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const email = new cdk.CfnParameter(this, "email", {
type: "String",
description: "The email address to receive notification when the program finds something interesting"});
const topic = new sns.Topic(this,'Sns');
topic.addSubscription(new subs.EmailSubscription(email.valueAsString));
const lambdaFn = new lambda.Function(this,'Lambda',{
code: new lambda.InlineCode(fs.readFileSync('lambda/index.js',{encoding:'utf-8'})),
handler:'index.handler',
runtime:lambda.Runtime.NODEJS_12_X,
environment:{'SNS_ARN':topic.topicArn}
});
const rule = new events.Rule(this,'Rule',{
schedule: events.Schedule.rate(cdk.Duration.minutes(5))
});
rule.addTarget(new targets.LambdaFunction(lambdaFn));
}
}
module.exports = { ServerlessHttpCheckerStack }