UNPKG

@pulumi/aws

Version:

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

67 lines 3.2 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.TableEventSubscription = void 0; const pulumi = require("@pulumi/pulumi"); const table = require("./table"); const lambda = require("../lambda"); const utils = require("../utils"); class TableEventSubscription extends lambda.EventSubscription { constructor(name, table, handler, args, opts = {}) { // We previously did not parent the subscription to the table. We now do. Provide an alias // so this doesn't cause resources to be destroyed/recreated for existing stacks. super("aws:dynamodb:TableEventSubscription", name, { parent: table, ...utils.withAlias(opts, { parent: opts.parent }), }); const streamArn = pulumi.all([table.streamEnabled, table.streamArn]) .apply(([streamEnabled, streamArn]) => { if (!streamEnabled) { throw new pulumi.ResourceError("Table must be created with `streamEnabled: true` to support listening for events.", this); } return streamArn; }); const parentOpts = { parent: this }; this.func = lambda.createFunctionFromEventHandler(name, handler, parentOpts); this.permission = new lambda.Permission(name, { function: this.func.name, action: "lambda:InvokeFunction", principal: "dynamodb.amazonaws.com", sourceArn: streamArn, }, parentOpts); this.eventSourceMapping = new lambda.EventSourceMapping(name, { batchSize: args.batchSize, bisectBatchOnFunctionError: args.bisectBatchOnFunctionError, destinationConfig: args.destinationConfig, enabled: true, eventSourceArn: streamArn, functionName: this.func.name, maximumBatchingWindowInSeconds: args.maximumBatchingWindowInSeconds, maximumRecordAgeInSeconds: args.maximumRecordAgeInSeconds, maximumRetryAttempts: args.maximumRetryAttempts, parallelizationFactor: args.parallelizationFactor, startingPosition: args.startingPosition, functionResponseTypes: args.functionResponseTypes, filterCriteria: args.filterCriteria, }, parentOpts); this.table = table; this.registerOutputs(); } } exports.TableEventSubscription = TableEventSubscription; table.Table.prototype.onEvent = function (name, handler, args, opts) { return new TableEventSubscription(name, this, handler, args, opts); }; //# sourceMappingURL=dynamodbMixins.js.map