Skip to content

Commit daf4849

Browse files
committed
add condition if 202 and fix log access
1 parent f181a78 commit daf4849

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lambda/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ const handler: Handler = async (payload: Payload) => {
1111
try {
1212
if (!apiUrl)
1313
{
14-
throw error;
14+
throw new error('API URL is missing');
1515
}
16-
// Make the HTTP request using Axios
16+
1717
const response = await axios.post(apiUrl, JSON.stringify(data), {
1818
headers: headers,
1919
});
2020

21-
if (response.status === 200) {
22-
console.log('Alert sent to API successfully');
21+
if (response.status === 200 || response.status === 202) {
22+
console.log(`Alert sent to API successfully with status ${response.status}`);
2323
} else {
2424
console.error(`Failed to send alert to API. Status code: ${response.status}, Response: ${response.data}`);
2525
}

terraform/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,12 @@ resource "aws_cloudwatch_log_group" "log_group" {
101101
name = "/aws/lambda/${aws_lambda_function.lambda.function_name}"
102102
retention_in_days = 14
103103
}
104+
105+
data "aws_iam_policy" "write_logs_access" {
106+
arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
107+
}
108+
109+
resource "aws_iam_role_policy_attachment" "write_logs_access" {
110+
role = aws_iam_role.lambda_execution_role.id
111+
policy_arn = data.aws_iam_policy.write_logs_access.arn
112+
}

0 commit comments

Comments
 (0)