@pulumi/aws-serverless
Version:
Pulumi Amazon Web Services (AWS) Serverless Components.
51 lines • 2.19 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");
/**
* Creates a new subscription to the given queue 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 + "-queue-subscription", handler, opts, {
policies: [aws.iam.AWSLambdaFullAccess, aws_1.iam.AmazonSQSFullAccess],
});
return new QueueEventSubscription(name, topic, func, args, opts);
}
exports.subscribe = subscribe;
class QueueEventSubscription extends subscription_1.EventSubscription {
constructor(name, queue, func, args, opts) {
super("aws-serverless:queue:QueueEventSubscription", name, func, { queue: queue }, opts);
args = args || {};
this.permission = new aws.lambda.Permission(name, {
action: "lambda:*",
function: func,
principal: "sqs.amazonaws.com",
sourceArn: queue.arn,
}, { parent: this });
this.eventSourceMapping = new aws_1.lambda.EventSourceMapping(name, {
batchSize: args.batchSize,
enabled: true,
eventSourceArn: queue.arn,
functionName: func.name,
}, { parent: this });
}
}
exports.QueueEventSubscription = QueueEventSubscription;
//# sourceMappingURL=queue.js.map