Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
| <a name="input_lambda_function_tags"></a> [lambda\_function\_tags](#input\_lambda\_function\_tags) | Additional tags for the Lambda function | `map(string)` | `{}` | no |
| <a name="input_lambda_function_vpc_security_group_ids"></a> [lambda\_function\_vpc\_security\_group\_ids](#input\_lambda\_function\_vpc\_security\_group\_ids) | List of security group ids when Lambda Function should run in the VPC. | `list(string)` | `null` | no |
| <a name="input_lambda_function_vpc_subnet_ids"></a> [lambda\_function\_vpc\_subnet\_ids](#input\_lambda\_function\_vpc\_subnet\_ids) | List of subnet ids when Lambda Function should run in the VPC. Usually private or intra subnets. | `list(string)` | `null` | no |
| <a name="input_lambda_layers"></a> [lambda\_layers](#input\_lambda\_layers) | (Optional) List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function | `list(string)` | <pre>[<br> "arn:aws:lambda:us-east-1:668099181075:layer:AWSLambda-Python-AWS-SDK:4"<br>]</pre> | no |
| <a name="input_lambda_layers"></a> [lambda\_layers](#input\_lambda\_layers) | (Optional) List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function | `list(string)` | `[]` | no |
| <a name="input_lambda_role"></a> [lambda\_role](#input\_lambda\_role) | IAM role attached to the Lambda Function. If this is set then a role will not be created for you. | `string` | `""` | no |
| <a name="input_messenger"></a> [messenger](#input\_messenger) | The name of the channel in Slack for notifications | `string` | n/a | yes |
| <a name="input_recreate_missing_package"></a> [recreate\_missing\_package](#input\_recreate\_missing\_package) | Whether to recreate missing Lambda package if it is missing locally or not | `bool` | `false` | no |
Expand All @@ -75,4 +75,4 @@
| <a name="output_lambda_iam_role_arn"></a> [lambda\_iam\_role\_arn](#output\_lambda\_iam\_role\_arn) | The ARN of the IAM role used by Lambda function |
| <a name="output_lambda_iam_role_name"></a> [lambda\_iam\_role\_name](#output\_lambda\_iam\_role\_name) | The name of the IAM role used by Lambda function |
| <a name="output_sns_topic_arn"></a> [sns\_topic\_arn](#output\_sns\_topic\_arn) | The ARN of the SNS topic from which messages will be sent to Slack |
<!-- END_TF_DOCS -->
<!-- END_TF_DOCS -->
15 changes: 9 additions & 6 deletions functions/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import json
import logging
#import requests
import urllib
from botocore.vendored import requests
import urllib.parse
import urllib.request

# ---------------------------------------------------------------------------------------------------------------------
# ENVIRONMENT VARIABLES
Expand Down Expand Up @@ -646,9 +645,13 @@ def ecs_events_parser_title(detail_type, detail):
def post(WEBHOOK_URL, message):
log.debug(f'Sending message: {json.dumps(message, indent=4)}')
headers = {'Content-type': 'application/json'}
response = requests.post(WEBHOOK_URL, json.dumps(message), headers=headers)
log.debug('Response: {}, message: {}'.format(response.status_code, response.text))
return response.status_code
payload = json.dumps(message).encode("utf-8")
request = urllib.request.Request(WEBHOOK_URL, data=payload, headers=headers, method="POST")
with urllib.request.urlopen(request) as response:
body = response.read().decode("utf-8")
status_code = response.getcode()
log.debug('Response: {}, message: {}'.format(status_code, body))
return status_code

# Lambda handler
def lambda_handler(event, context):
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variable "lambda_description" {
variable "lambda_layers" {
description = "(Optional) List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function"
type = list(string)
default = ["arn:aws:lambda:us-east-1:668099181075:layer:AWSLambda-Python-AWS-SDK:4"]
default = []
}

variable "sns_topic_name" {
Expand Down
Loading