@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
62 lines • 2.64 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 });
exports.QueueEventSubscription = void 0;
const lambda = require("../lambda");
const queue = require("./queue");
const utils = require("../utils");
class QueueEventSubscription extends lambda.EventSubscription {
constructor(name, queue, handler, args = {}, opts = {}) {
// We previously did not parent the subscription to the queue. We now do. Provide an alias
// so this doesn't cause resources to be destroyed/recreated for existing stacks.
super("aws:sqs:QueueEventSubscription", name, {
parent: queue,
...utils.withAlias(opts, { parent: opts.parent }),
});
const parentOpts = { parent: this };
this.func = createFunctionFromEventHandler(name, handler, parentOpts);
this.permission = new lambda.Permission(name, {
action: "lambda:*",
function: this.func.name,
principal: "sqs.amazonaws.com",
sourceArn: queue.arn,
}, parentOpts);
this.eventSourceMapping = new lambda.EventSourceMapping(name, {
batchSize: args.batchSize,
maximumBatchingWindowInSeconds: args.maximumBatchingWindowInSeconds,
enabled: true,
eventSourceArn: queue.arn,
functionName: this.func.name,
}, parentOpts);
this.queue = queue;
this.registerOutputs();
}
}
exports.QueueEventSubscription = QueueEventSubscription;
function createFunctionFromEventHandler(name, handler, opts) {
if (handler instanceof Function) {
return new lambda.CallbackFunction(name, {
callback: handler,
// as we don't pass policies, we will pick up the default policies of the Callbackfunction
}, opts);
}
else {
return handler;
}
}
queue.Queue.prototype.onEvent = function (name, handler, args, opts) {
return new QueueEventSubscription(name, this, handler, args, opts);
};
//# sourceMappingURL=sqsMixins.js.map