UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

75 lines 3.39 kB
"use strict"; // Copyright 2016-2018, Pulumi Corporation. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. Object.defineProperty(exports, "__esModule", { value: true }); exports.LogGroupEventSubscription = void 0; const pulumi = require("@pulumi/pulumi"); const config = require("../config"); const lambda = require("../lambda"); const logGroup = require("./logGroup"); const logSubscriptionFilter = require("./logSubscriptionFilter"); const utils = require("../utils"); class LogGroupEventSubscription extends lambda.EventSubscription { constructor(name, logGroup, handler, args = {}, opts = {}) { // We previously did not parent the subscription to the logGroup. We now do. Provide an alias // so this doesn't cause resources to be destroyed/recreated for existing stacks. super("aws:cloudwatch:LogGroupEventSubscription", name, { parent: logGroup, ...utils.withAlias(opts, { parent: opts.parent }), }); const parentOpts = { parent: this }; this.func = lambda.createFunctionFromEventHandler(name, handler, parentOpts); const provider = this.getProvider("aws::"); let region = provider ? provider.region : undefined; region = region || config.region; this.permission = new lambda.Permission(name, { action: "lambda:invokeFunction", function: this.func.name, principal: pulumi.interpolate `logs.${region}.amazonaws.com`, sourceArn: pulumi.interpolate `${logGroup.arn}:*`, }, parentOpts); this.logSubscriptionFilter = new logSubscriptionFilter.LogSubscriptionFilter(name, { destinationArn: this.func.arn, filterPattern: args.filterPattern || "", logGroup: logGroup.name, }, parentOpts); this.logGroup = logGroup; this.registerOutputs(); } } exports.LogGroupEventSubscription = LogGroupEventSubscription; logGroup.LogGroup.prototype.onEvent = function (name, handler, args, opts) { return new LogGroupEventSubscription(name, this, handler, args, opts); }; logGroup.LogGroup.prototype.onDecodedEvent = function (name, handler, args, opts) { return this.onEvent(name, async (event, context, callback) => { const decoded = await decodeLogGroupEvent(event); await handler(decoded, context, callback); }, args, opts); }; async function decodeLogGroupEvent(event) { const zlib = await Promise.resolve().then(() => require("zlib")); const payload = Buffer.from(event.awslogs.data, "base64"); return new Promise((resolve, reject) => { zlib.gunzip(payload, function (err, result) { if (err) { reject(err); } else { resolve(JSON.parse(result.toString("ascii"))); } }); }); } //# sourceMappingURL=logGroupMixins.js.map