UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

78 lines 3.49 kB
"use strict"; // 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.StreamEventSubscription = void 0; const iam = require("../iam"); const stream = require("./stream"); const lambda = require("../lambda"); const utils = require("../utils"); class StreamEventSubscription extends lambda.EventSubscription { constructor(name, stream, handler, args, opts = {}) { // We previously did not parent the subscription to the stream. We now do. Provide an alias // so this doesn't cause resources to be destroyed/recreated for existing stacks. super("aws:kinesis:StreamEventSubscription", name, { parent: stream, ...utils.withAlias(opts, { parent: opts.parent }), }); const parentOpts = { parent: this }; this.func = createFunctionFromEventHandler(name, handler, parentOpts); this.permission = new lambda.Permission(name, { function: this.func.name, action: "lambda:InvokeFunction", principal: "kinesis.amazonaws.com", sourceArn: stream.arn, }, parentOpts); const mappingArgs = { batchSize: args.batchSize, bisectBatchOnFunctionError: args.bisectBatchOnFunctionError, destinationConfig: args.destinationConfig, enabled: true, eventSourceArn: stream.arn, functionName: this.func.name, maximumBatchingWindowInSeconds: args.maximumBatchingWindowInSeconds, maximumRecordAgeInSeconds: args.maximumRecordAgeInSeconds, maximumRetryAttempts: args.maximumRetryAttempts, parallelizationFactor: args.parallelizationFactor, startingPosition: args.startingPosition, startingPositionTimestamp: args.startingPositionTimestamp, functionResponseTypes: args.functionResponseTypes, }; this.eventSourceMapping = new lambda.EventSourceMapping(name, mappingArgs, parentOpts); this.stream = stream; this.registerOutputs(); } } exports.StreamEventSubscription = StreamEventSubscription; function createFunctionFromEventHandler(name, handler, opts) { if (handler instanceof Function) { return new lambda.CallbackFunction(name, { callback: handler, policies: [ iam.ManagedPolicy.AWSLambdaKinesisExecutionRole, iam.ManagedPolicy.AmazonKinesisFullAccess, iam.ManagedPolicy.CloudWatchFullAccessV2, iam.ManagedPolicy.CloudWatchEventsFullAccess, iam.ManagedPolicy.LambdaFullAccess, ], }, opts); } else { return handler; } } stream.Stream.prototype.onEvent = function (name, handler, args, opts) { return new StreamEventSubscription(name, this, handler, args, opts); }; //# sourceMappingURL=kinesisMixins.js.map