Skip to content

Instantly share code, notes, and snippets.

@yossale
Last active June 21, 2020 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yossale/ac163048e31e0ad1533194e49c8987d8 to your computer and use it in GitHub Desktop.
Save yossale/ac163048e31e0ad1533194e49c8987d8 to your computer and use it in GitHub Desktop.
LogGroupRegistrationLambda
const util = require('util')
const AWS = require('aws-sdk')
const cloudWatchLogs = new AWS.CloudWatchLogs();
let DESTINATION_ARN = process.env.DESTINATION_ARN
async function registerLogGroupToLogz(logGroupName) {
let filterName = 'sample-filterName-1'
let filterPattern = '' //everything
const req = {
destinationArn: DESTINATION_ARN,
logGroupName: logGroupName,
filterName: filterName,
filterPattern: filterPattern
};
console.debug("adding subscription filter...", {
logGroupName,
arn: DESTINATION_ARN,
filterName,
filterPattern
});
await cloudWatchLogs
.putSubscriptionFilter(req)
.promise()
console.info(`subscribed log group to [${DESTINATION_ARN}]`, {
logGroupName,
arn: DESTINATION_ARN
});
}
exports.handler = async (event) => {
console.log(`New LogGroup identifies, registering: ${util.inspect(event, {depth: 20})}`)
await registerLogGroupToLogz(event.detail.requestParameters.logGroupName)
console.log(`${event.detail.requestParameters.logGroupName} registered`
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment