Skip to content

Commit 06187a0

Browse files
authored
Merge pull request #9 from allcloud-jonathan/master
Username Prefix && housekeeping
2 parents 21638fa + c71f4cf commit 06187a0

File tree

7 files changed

+58
-34
lines changed

7 files changed

+58
-34
lines changed

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,29 @@ resource "aws_sns_topic_subscription" "lambda_sns_to_slack" {
5252
}
5353
```
5454

55-
### Configurable variables
56-
57-
| **Variable** | **Description** | **Required** | **Default** |
58-
|:--------------------------:|:-----------------------------------------------------------------:|--------------|--------------------------------|
59-
| **slack_webhook_url** | Slack incoming webhook URL without protocol name. | yes | |
60-
| **slack_channel_map** | Topic-to-channel mapping. | yes | |
61-
| **lambda_function_name** | AWS Lambda function name for the Slack notifier | no | `"sns-to-slack"` |
62-
| **default_username** | Default username for notifications used if no matching one found. | no | `"AWS Lambda"` |
63-
| **default_channel** | Default channel used if no matching channel found. | no | `"#webhook-tests"` |
64-
| **default_emoji** | Default emoji used if no matching emoji found. | no | `":information_source:"` |
65-
| **lambda_iam_role_name** | IAM role name for lambda functions. | no | `"lambda-sns-to-slack"` |
66-
| **lambda_iam_policy_name** | IAM policy name for lambda functions. | no | `"lambda-sns-to-slack-policy"` |
67-
68-
### Output variables
69-
70-
| **Variable** | **Description** |
71-
|-------------------------|-----------------------------------|
72-
| **lambda_function_arn** | AWS Lambda notifier function ARN. |
55+
## Configurable variables
56+
57+
### Inputs
58+
59+
| Name | Description | Type | Default | Required |
60+
|------|-------------|:----:|:-----:|:-----:|
61+
| default\_channel | Default channel used if no matching channel found | string | `#webhook-tests` | no |
62+
| default\_emoji | Default emoji used if no matching emoji found | string | `:information_source:` | no |
63+
| default\_username | Default username for notifications used if no matching one found | string | `AWS Lambda` | no |
64+
| lambda\_function\_name | AWS Lambda function name for the Slack notifier | string | `sns-to-slack` | no |
65+
| lambda\_iam\_policy\_name | IAM policy name for lambda functions | string | `lambda-sns-to-slack-policy` | no |
66+
| lambda\_iam\_role\_name | IAM role name for lambda functions | string | `lambda-sns-to-slack` | no |
67+
| slack\_channel\_map | Topic-to-channel mapping | map | - | yes |
68+
| slack\_webhook\_url | Slack incoming webhook URL without protocol name | string | - | yes |
69+
| username\_prefix | if sepecified the usernames that are looked up will be prefixed by this. Useful in situations where multiple accounts report to a single slack channel. | string | `` | no |
70+
71+
### Outputs
72+
73+
| Name | Description |
74+
|------|-------------|
75+
| lambda\_function\_arn | AWS Lambda notifier function ARN |
76+
77+
7378

7479
## Examples
7580

build-function.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pipenv run pip install -r <(pipenv lock -r) --target _build/
1616
cp lambda_function.py _build/
1717

1818
pushd _build
19+
find . -name '*.pyc' -delete
20+
rm -f ${zipname}
1921
zip -r ${zipname} *
2022
cp ${zipname} ${outdir}
2123
popd

module/lambda.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ resource "aws_lambda_function" "sns_to_slack" {
1717
DEFAULT_USERNAME = "${var.default_username}"
1818
DEFAULT_CHANNEL = "${var.default_channel}"
1919
DEFAULT_EMOJI = "${var.default_emoji}"
20+
USERNAME_PREFIX = "${var.username_prefix}"
2021
}
2122
}
2223
}

module/lambda/sns-to-slack.zip

-481 KB
Binary file not shown.

module/outputs.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
output "lambda_function_arn" {
2-
value = "${aws_lambda_function.sns_to_slack.arn}"
2+
value = "${aws_lambda_function.sns_to_slack.arn}"
3+
description = "AWS Lambda notifier function ARN"
34
}

module/variables.tf

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
variable "slack_webhook_url" {
2-
type = "string"
2+
type = "string"
3+
description = "Slack incoming webhook URL without protocol name"
34
}
45

56
variable "slack_channel_map" {
6-
type = "map"
7+
type = "map"
8+
description = "Topic-to-channel mapping"
79
}
810

911
variable "lambda_function_name" {
10-
type = "string"
11-
default = "sns-to-slack"
12+
type = "string"
13+
default = "sns-to-slack"
14+
description = "AWS Lambda function name for the Slack notifier"
1215
}
1316

1417
variable "default_username" {
15-
type = "string"
16-
default = "AWS Lambda"
18+
type = "string"
19+
default = "AWS Lambda"
20+
description = "Default username for notifications used if no matching one found"
21+
}
22+
23+
variable "username_prefix" {
24+
type = "string"
25+
default = ""
26+
description = "if sepecified the usernames that are looked up will be prefixed by this. Useful in situations where multiple accounts report to a single slack channel."
1727
}
1828

1929
variable "default_channel" {
20-
type = "string"
21-
default = "#webhook-tests"
30+
type = "string"
31+
default = "#webhook-tests"
32+
description = "Default channel used if no matching channel found"
2233
}
2334

2435
variable "default_emoji" {
25-
type = "string"
26-
default = ":information_source:"
36+
type = "string"
37+
default = ":information_source:"
38+
description = "Default emoji used if no matching emoji found"
2739
}
2840

2941
variable "lambda_iam_role_name" {
30-
type = "string"
31-
default = "lambda-sns-to-slack"
42+
type = "string"
43+
default = "lambda-sns-to-slack"
44+
description = "IAM role name for lambda functions"
3245
}
3346

3447
variable "lambda_iam_policy_name" {
35-
type = "string"
36-
default = "lambda-sns-to-slack-policy"
48+
type = "string"
49+
default = "lambda-sns-to-slack-policy"
50+
description = "IAM policy name for lambda functions"
3751
}

sns-to-slack/lambda_function.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
DEFAULT_USERNAME = os.environ.get('DEFAULT_USERNAME', 'AWS Lambda')
4747
DEFAULT_CHANNEL = os.environ.get('DEFAULT_CHANNEL', '#webhook-tests')
4848
DEFAULT_EMOJI = os.environ.get('DEFAULT_EMOJI', ':information_source:')
49+
USERNAME_PREFIX = os.environ.get('USERNAME_PREFIX', '')
4950

5051

5152
def get_slack_emoji(event_src, topic_name, event_cond='default'):
@@ -92,7 +93,7 @@ def get_slack_username(event_src):
9293
'rds': 'AWS RDS'}
9394

9495
try:
95-
return username_map[event_src]
96+
return "{0}{1}".format(USERNAME_PREFIX, username_map[event_src])
9697
except KeyError:
9798
return DEFAULT_USERNAME
9899

0 commit comments

Comments
 (0)