@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
83 lines • 4.2 kB
JavaScript
;
// 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.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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, Object.assign({ 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, (event, context, callback) => __awaiter(this, void 0, void 0, function* () {
const decoded = yield decodeLogGroupEvent(event);
yield handler(decoded, context, callback);
}), args, opts);
};
function decodeLogGroupEvent(event) {
return __awaiter(this, void 0, void 0, function* () {
const zlib = yield 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