Skip to content

Commit af4b9eb

Browse files
authored
fix: Ensure logger is initialized correctly and propagate log_level variable to LOG_LEVEL environment variable (#261)
fix: Resolve issue #253 - logger initialized, added log_level variable
1 parent b2489c3 commit af4b9eb

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Doing serverless with Terraform? Check out [serverless.tf framework](https://ser
88

99
## Supported Features
1010

11-
- AWS Lambda runtime Python 3.11
11+
- AWS Lambda runtime Python 3.13
1212
- Create new SNS topic or use existing one
1313
- Support plaintext and encrypted version of Slack webhook URL
1414
- Most of Slack message options are customizable
@@ -23,7 +23,7 @@ Doing serverless with Terraform? Check out [serverless.tf framework](https://ser
2323
```hcl
2424
module "notify_slack" {
2525
source = "terraform-aws-modules/notify-slack/aws"
26-
version = "~> 5.0"
26+
version = "~> 7.0"
2727
2828
sns_topic_name = "slack-topic"
2929
@@ -122,6 +122,7 @@ See the [functions](https://github.com/terraform-aws-modules/terraform-aws-notif
122122
| <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 |
123123
| <a name="input_lambda_source_path"></a> [lambda\_source\_path](#input\_lambda\_source\_path) | The source path of the custom Lambda function | `string` | `null` | no |
124124
| <a name="input_log_events"></a> [log\_events](#input\_log\_events) | Boolean flag to enabled/disable logging of incoming events | `bool` | `false` | no |
125+
| <a name="input_log_level"></a> [log\_level](#input\_log\_level) | Logging level for the Lambda function | `string` | `"INFO"` | no |
125126
| <a name="input_putin_khuylo"></a> [putin\_khuylo](#input\_putin\_khuylo) | Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! | `bool` | `true` | no |
126127
| <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` | `true` | no |
127128
| <a name="input_reserved_concurrent_executions"></a> [reserved\_concurrent\_executions](#input\_reserved\_concurrent\_executions) | The amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations | `number` | `-1` | no |

functions/notify_slack.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
# Set default region if not provided
2424
REGION = os.environ.get("AWS_REGION", "us-east-1")
2525

26+
# Initialize logging
27+
logger = logging.getLogger()
28+
logger.setLevel(os.environ.get("LOG_LEVEL", "INFO"))
29+
2630
# Create client so its cached/frozen between invocations
2731
KMS_CLIENT = boto3.client("kms", region_name=REGION)
2832

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ module "lambda" {
117117
SLACK_USERNAME = var.slack_username
118118
SLACK_EMOJI = var.slack_emoji
119119
LOG_EVENTS = var.log_events ? "True" : "False"
120+
LOG_LEVEL = var.log_level
120121
}
121122

122123
create_role = var.lambda_role == ""

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ variable "log_events" {
168168
default = false
169169
}
170170

171+
variable "log_level" {
172+
description = "Logging level for the Lambda function"
173+
type = string
174+
default = "INFO"
175+
}
176+
171177
variable "reserved_concurrent_executions" {
172178
description = "The amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations"
173179
type = number

0 commit comments

Comments
 (0)