Skip to content

Commit

Permalink
add condition if 202 and fix log access
Browse files Browse the repository at this point in the history
  • Loading branch information
Claude-GP committed Jan 31, 2024
1 parent f181a78 commit daf4849
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lambda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const handler: Handler = async (payload: Payload) => {
try {
if (!apiUrl)
{
throw error;
throw new error('API URL is missing');
}
// Make the HTTP request using Axios

const response = await axios.post(apiUrl, JSON.stringify(data), {
headers: headers,
});

if (response.status === 200) {
console.log('Alert sent to API successfully');
if (response.status === 200 || response.status === 202) {
console.log(`Alert sent to API successfully with status ${response.status}`);
} else {
console.error(`Failed to send alert to API. Status code: ${response.status}, Response: ${response.data}`);
}
Expand Down
9 changes: 9 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,12 @@ resource "aws_cloudwatch_log_group" "log_group" {
name = "/aws/lambda/${aws_lambda_function.lambda.function_name}"
retention_in_days = 14
}

data "aws_iam_policy" "write_logs_access" {
arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_iam_role_policy_attachment" "write_logs_access" {
role = aws_iam_role.lambda_execution_role.id
policy_arn = data.aws_iam_policy.write_logs_access.arn
}

0 comments on commit daf4849

Please sign in to comment.