-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (42 loc) · 1020 Bytes
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
module.exports = function (arc, cloudformation, stage) {
if (process.env.SLACK_WEBHOOK) {
arc.slack = [[stage, process.env.SLACK_WEBHOOK]];
}
if (!arc.slack) {
throw new Error('Missing slack webhook');
}
const envs = {};
arc.slack.forEach(item => {
envs[item[0]] = item[1];
});
if (!envs[stage]) {
throw new Error(`Missing slack webhook for stage: ${stage}`);
}
const url = envs[stage];
cloudformation.Resources.LambdaSlackHandler = {
Type: 'AWS::Serverless::Function',
Properties: {
Handler: 'index.handler',
CodeUri: 's3://lambda-slack-handler/1.3.2.zip',
Runtime: 'nodejs14.x',
MemorySize: 128,
Timeout: 5,
Environment: {
Variables: {
SLACK_HOOK: url
}
},
Role: {
'Fn::Sub': [
'arn:aws:iam::${AWS::AccountId}:role/${roleName}',
{
roleName: {
Ref: 'Role'
}
}
]
}
}
};
return cloudformation;
};