Skip to content

Commit

Permalink
#15 converted to variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kunduso committed Jun 12, 2024
1 parent 5d83bcd commit d678181
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ resource "aws_lambda_function" "lambda_run" {
log_group = aws_cloudwatch_log_group.lambda_log.name
system_log_level = "INFO"
}
environment {
variables = {
parameter_name = aws_ssm_parameter.parameter.name
log_group_name = aws_cloudwatch_log_group.lambda_log.name
log_stream_name = aws_cloudwatch_log_stream.log_stream.name
}
}
}

resource "aws_cloudwatch_event_rule" "lambda_trigger" {
Expand Down
8 changes: 4 additions & 4 deletions lambda_function/handler.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import boto3
import logging
import time
import os

def lambda_handler(event, context):
# Initialize the Boto3 clients for SSM and CloudWatch Logs
ssm_client = boto3.client('ssm')
logs_client = boto3.client('logs')
parameter_name = '/app-7'
log_group_name = 'app-7'
log_stream_name = 'app-7-lambda-log-stream'
parameter_name = os.environ['parameter_name']
log_group_name = os.environ['log_group_name']
log_stream_name = os.environ['log_stream_name']
try:
# Read the parameter from SSM Parameter Store
response = ssm_client.get_parameter(Name=parameter_name, WithDecryption=True)
parameter_value = response['Parameter']['Value']

# Write the parameter value to CloudWatch Logs
logs_client.create_log_stream(logGroupName=log_group_name, logStreamName=log_stream_name)
logs_client.put_log_events(
logGroupName=log_group_name,
logStreamName=log_stream_name,
Expand Down

0 comments on commit d678181

Please sign in to comment.