@pulumi/aws-serverless
Version:
Pulumi Amazon Web Services (AWS) Serverless Components.
46 lines • 1.99 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 function_1 = require("./function");
const subscription_1 = require("./subscription");
/**
* Creates a new subscription to the given topic using the lambda provided, along with optional
* options to control the behavior of the subscription.
*/
function subscribe(name, topic, handler, args, opts) {
args = args || {};
const func = function_1.createLambdaFunction(name + "-topic-subscription", handler, opts);
return new TopicEventSubscription(name, topic, func, args, opts);
}
exports.subscribe = subscribe;
class TopicEventSubscription extends subscription_1.EventSubscription {
constructor(name, topic, func, args, opts) {
super("aws-serverless:topic:TopicEventSubscription", name, func, { topic: topic }, opts);
this.permission = new aws.lambda.Permission(name, {
action: "lambda:invokeFunction",
function: func,
principal: "sns.amazonaws.com",
sourceArn: topic.id,
}, { parent: this });
this.subscription = new aws.sns.TopicSubscription(name, {
topic: topic,
protocol: "lambda",
endpoint: func.arn,
}, { parent: this });
}
}
exports.TopicEventSubscription = TopicEventSubscription;
//# sourceMappingURL=topic.js.map