Skip to content
Open
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
12 changes: 7 additions & 5 deletions alerter/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const https = require('https');
const Promise = require('bluebird');
const zlib = Promise.promisifyAll(require('zlib'));
import https from 'https';
import zlib from 'zlib';
import { promisify } from 'util';
const gunzipAsync = promisify(zlib.gunzip);

/**
*
* Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
Expand All @@ -13,9 +15,9 @@ const zlib = Promise.promisifyAll(require('zlib'));
* @returns {Object} object - API Gateway Lambda Proxy Output Format
*
*/
exports.lambdaHandler = async (event, context) => {
export const lambdaHandler = async (event, context) => {
const payload = Buffer.from(event.awslogs.data, 'base64');
const gunzipped = (await zlib.gunzipAsync(payload)).toString('utf8');
const gunzipped = (await gunzipAsync(payload)).toString('utf8');
const eventDetails = JSON.parse(gunzipped);
let messageArray = eventDetails.logEvents[0].message.split('\t');
let errorJSON, errorType, errorMessage;
Expand Down
13 changes: 0 additions & 13 deletions alerter/package-lock.json

This file was deleted.

4 changes: 1 addition & 3 deletions alerter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
},
"author": "",
"license": "ISC",
"dependencies": {
"bluebird": "^3.7.2"
}
"type": "module"
}
13 changes: 6 additions & 7 deletions subscriber/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Load the SDK for JavaScript
var AWS = require('aws-sdk');

const cloudwatchlogs = new AWS.CloudWatchLogs();
import { CloudWatchLogsClient, DescribeSubscriptionFiltersCommand, DeleteSubscriptionFilterCommand, PutSubscriptionFilterCommand } from '@aws-sdk/client-cloudwatch-logs';
const cloudWatchLogsClient = new CloudWatchLogsClient({});
/**
*
* Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
Expand All @@ -14,7 +13,7 @@ const cloudwatchlogs = new AWS.CloudWatchLogs();
* @returns {Object} object - API Gateway Lambda Proxy Output Format
*
*/
exports.lambdaHandler = async (event, context) => {
export const lambdaHandler = async (event, context) => {
console.log(JSON.stringify(event));
const detail = event.detail;
const resourceSplit = event.resources[0].split(':');
Expand All @@ -38,7 +37,7 @@ exports.lambdaHandler = async (event, context) => {
};
let describeSubscriptionFiltersResult;
try {
describeSubscriptionFiltersResult = await cloudwatchlogs.describeSubscriptionFilters(params).promise();
describeSubscriptionFiltersResult = await cloudWatchLogsClient.send(new DescribeSubscriptionFiltersCommand(params));
} catch (err) {
console.log('Unable to describe subscription filters');
//dont throw so we can try removing the log subscription just in case it is there
Expand All @@ -57,7 +56,7 @@ exports.lambdaHandler = async (event, context) => {
});
if (removeParams) {
try{
await cloudwatchlogs.deleteSubscriptionFilter(removeParams).promise();
await cloudWatchLogsClient.send(new DeleteSubscriptionFilterCommand(removeParams));
}catch(err){
console.log(err);
throw err;
Expand All @@ -80,7 +79,7 @@ exports.lambdaHandler = async (event, context) => {
distribution: 'ByLogStream'
};
try {
await cloudwatchlogs.putSubscriptionFilter(params).promise();
await cloudWatchLogsClient.send(new PutSubscriptionFilterCommand(params));
} catch (err) {
console.log(err);
throw err;
Expand Down
3 changes: 2 additions & 1 deletion subscriber/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
"license": "ISC",
"type": "module"
}
6 changes: 3 additions & 3 deletions template.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
lambda-errors-to-slack
lambda-errors-to-slack-sdk-v3

Subscribes to tagged Lambdas in your account and forwards their errors to a specified Slack channel

Expand All @@ -18,7 +18,7 @@ Resources:
Properties:
CodeUri: alerter/
Handler: index.lambdaHandler
Runtime: nodejs12.x
Runtime: nodejs18.x
Environment:
Variables:
SLACK_WEBHOOK_URL: !Ref SlackWebhookURL
Expand All @@ -27,7 +27,7 @@ Resources:
Properties:
CodeUri: subscriber/
Handler: index.lambdaHandler
Runtime: nodejs12.x
Runtime: nodejs18.x
Policies:
- Version: '2012-10-17' # Policy Document
Statement:
Expand Down