@pulumi/aws-serverless
Version:
Pulumi Amazon Web Services (AWS) Serverless Components.
51 lines • 2.22 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.
Object.defineProperty(exports, "__esModule", { value: true });
const aws = require("@pulumi/aws");
const aws_1 = require("@pulumi/aws");
const function_1 = require("./function");
const subscription_1 = require("./subscription");
function onEvent(name, scheduleOrRule, handler, args, opts) {
args = args || {};
const func = function_1.createLambdaFunction(name + "-cloudwatch-subscription", handler, opts);
return new CloudwatchEventSubscription(name, scheduleOrRule, func, args, opts);
}
exports.onEvent = onEvent;
class CloudwatchEventSubscription extends subscription_1.EventSubscription {
constructor(name, scheduleOrRule, func, args, opts) {
super("aws-serverless:cloudwatch:CloudwatchEventSubscription", name, func, {}, opts);
if (typeof scheduleOrRule === "string") {
this.eventRule = new aws_1.cloudwatch.EventRule(name, {
scheduleExpression: scheduleOrRule,
}, { parent: this });
}
else {
this.eventRule = scheduleOrRule;
}
this.target = new aws.cloudwatch.EventTarget(name, {
rule: this.eventRule.name,
arn: this.func.arn,
targetId: name,
}, { parent: this });
this.permission = new aws.lambda.Permission(name, {
action: "lambda:invokeFunction",
function: this.func,
principal: "events.amazonaws.com",
sourceArn: this.eventRule.arn,
}, { parent: this });
}
}
exports.CloudwatchEventSubscription = CloudwatchEventSubscription;
//# sourceMappingURL=cloudwatch.js.map