Skip to content

Commit 7555189

Browse files
committed
remove aws_region env
1 parent b7476e3 commit 7555189

File tree

1 file changed

+61
-62
lines changed

1 file changed

+61
-62
lines changed

lib/thinq-notifier-stack.ts

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,61 @@
1-
import * as events from "@aws-cdk/aws-events";
2-
import * as targets from "@aws-cdk/aws-events-targets";
3-
import { Runtime } from "@aws-cdk/aws-lambda";
4-
import * as lambda from "@aws-cdk/aws-lambda-nodejs";
5-
import * as secretsmanager from "@aws-cdk/aws-secretsmanager";
6-
import * as sns from "@aws-cdk/aws-sns";
7-
import * as subscriptions from "@aws-cdk/aws-sns-subscriptions";
8-
import * as cdk from "@aws-cdk/core";
9-
import * as iam from "@aws-cdk/aws-iam";
10-
import * as path from "path";
11-
12-
export class ThinqNotifierStack extends cdk.Stack {
13-
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
14-
super(scope, id, props);
15-
16-
const topic = new sns.Topic(this, "ThinqNotificationTopic", {
17-
displayName: "ThinQ notification topic",
18-
});
19-
20-
const secretName = "live/thinq-notifier/lg";
21-
22-
const fn = new lambda.NodejsFunction(this, "LgNotifierLambda", {
23-
runtime: Runtime.NODEJS_14_X,
24-
entry: path.resolve(__dirname, "../lambda/index.ts"),
25-
timeout: cdk.Duration.seconds(10),
26-
bundling: {
27-
minify: true,
28-
sourceMap: true,
29-
sourceMapMode: lambda.SourceMapMode.INLINE,
30-
target: "es2018",
31-
externalModules: ["aws-sdk"],
32-
},
33-
environment: {
34-
AWS_REGION: process.env.AWS_REGION!,
35-
NOTIFICATION_FREQ_HRS: "3",
36-
NOTIFICATION_THRESHOLD_HRS: "3",
37-
TOPIC_ARN: topic.topicArn,
38-
SECRET_NAME: secretName,
39-
},
40-
});
41-
42-
const secret = secretsmanager.Secret.fromSecretNameV2(
43-
this,
44-
"MyQLogin",
45-
secretName
46-
);
47-
secret.grantRead(fn.role as iam.IGrantable);
48-
49-
const eventRule = new events.Rule(this, "LambdaScheduleRule", {
50-
ruleName: "thinq-check-hourly",
51-
schedule: events.Schedule.cron({ minute: "0" }),
52-
targets: [new targets.LambdaFunction(fn)],
53-
});
54-
55-
targets.addLambdaPermission(eventRule, fn);
56-
57-
topic.addSubscription(
58-
new subscriptions.EmailSubscription(process.env.SNS_EMAIL!)
59-
);
60-
topic.grantPublish(fn.role as iam.IGrantable);
61-
}
62-
}
1+
import * as events from "@aws-cdk/aws-events";
2+
import * as targets from "@aws-cdk/aws-events-targets";
3+
import { Runtime } from "@aws-cdk/aws-lambda";
4+
import * as lambda from "@aws-cdk/aws-lambda-nodejs";
5+
import * as secretsmanager from "@aws-cdk/aws-secretsmanager";
6+
import * as sns from "@aws-cdk/aws-sns";
7+
import * as subscriptions from "@aws-cdk/aws-sns-subscriptions";
8+
import * as cdk from "@aws-cdk/core";
9+
import * as iam from "@aws-cdk/aws-iam";
10+
import * as path from "path";
11+
12+
export class ThinqNotifierStack extends cdk.Stack {
13+
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
14+
super(scope, id, props);
15+
16+
const topic = new sns.Topic(this, "ThinqNotificationTopic", {
17+
displayName: "ThinQ notification topic",
18+
});
19+
20+
const secretName = "live/thinq-notifier/lg";
21+
22+
const fn = new lambda.NodejsFunction(this, "LgNotifierLambda", {
23+
runtime: Runtime.NODEJS_14_X,
24+
entry: path.resolve(__dirname, "../lambda/index.ts"),
25+
timeout: cdk.Duration.seconds(10),
26+
bundling: {
27+
minify: true,
28+
sourceMap: true,
29+
sourceMapMode: lambda.SourceMapMode.INLINE,
30+
target: "es2018",
31+
externalModules: ["aws-sdk"],
32+
},
33+
environment: {
34+
NOTIFICATION_FREQ_HRS: "3",
35+
NOTIFICATION_THRESHOLD_HRS: "3",
36+
TOPIC_ARN: topic.topicArn,
37+
SECRET_NAME: secretName,
38+
},
39+
});
40+
41+
const secret = secretsmanager.Secret.fromSecretNameV2(
42+
this,
43+
"MyQLogin",
44+
secretName
45+
);
46+
secret.grantRead(fn.role as iam.IGrantable);
47+
48+
const eventRule = new events.Rule(this, "LambdaScheduleRule", {
49+
ruleName: "thinq-check-hourly",
50+
schedule: events.Schedule.cron({ minute: "0" }),
51+
targets: [new targets.LambdaFunction(fn)],
52+
});
53+
54+
targets.addLambdaPermission(eventRule, fn);
55+
56+
topic.addSubscription(
57+
new subscriptions.EmailSubscription(process.env.SNS_EMAIL!)
58+
);
59+
topic.grantPublish(fn.role as iam.IGrantable);
60+
}
61+
}

0 commit comments

Comments
 (0)