-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added support for custom lambda function (#172)
- Loading branch information
Showing
6 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
locals { | ||
custom = { | ||
name = "ex-${replace(basename(path.cwd), "_", "-")}-custom" | ||
tags = merge({ "Type" = "custom" }, local.tags) | ||
} | ||
} | ||
|
||
################################################################################ | ||
# Supporting Resources | ||
################################################################################ | ||
|
||
resource "aws_sns_topic" "custom_lambda" { | ||
name = local.custom.name | ||
tags = local.custom.tags | ||
} | ||
|
||
################################################################################ | ||
# Slack Notify Module | ||
################################################################################ | ||
|
||
module "custom_lambda" { | ||
source = "../../" | ||
|
||
lambda_function_name = "custom_lambda" | ||
lambda_source_path = "../../functions/mylambda.py" | ||
|
||
iam_role_name_prefix = "custom" | ||
|
||
sns_topic_name = aws_sns_topic.custom_lambda.name | ||
|
||
slack_webhook_url = "https://hooks.slack.com/services/AAA/BBB/CCC" | ||
slack_channel = "aws-notification" | ||
slack_username = "reporter" | ||
|
||
tags = local.custom.tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/python3.6 | ||
# CUSTOM LAMBDA FUNCTION | ||
|
||
import urllib3 | ||
import json | ||
import os | ||
http = urllib3.PoolManager() | ||
|
||
|
||
def lambda_handler(event, context): | ||
url = os.environ["SLACK_WEBHOOK_URL"] | ||
msg = { | ||
"channel": "#channel-name", | ||
"username": "Prometheus", | ||
"text": event['Records'][0]['Sns']['Message'], | ||
"icon_emoji": "" | ||
} | ||
|
||
encoded_msg = json.dumps(msg).encode('utf-8') | ||
resp = http.request('POST', url, body=encoded_msg) | ||
print({ | ||
"message": event['Records'][0]['Sns']['Message'], | ||
"status_code": resp.status, | ||
"response": resp.data | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters