aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 5.32 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SqsEventSource=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("../../core/lib/private/literal-string");return literal_string_1=()=>tmp,tmp};class SqsEventSource{queue;props;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_lambda_event_sources.SqsEventSource",version:"2.254.0"};_eventSourceMappingId=void 0;_eventSourceMappingArn=void 0;constructor(queue,props={}){this.queue=queue,this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_sqs_IQueue(queue),jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_event_sources_SqsEventSourceProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,SqsEventSource),error}if(this.props.maxBatchingWindow!==void 0){if(queue.fifo)throw new(core_1()).ValidationError((0,literal_string_1().lit)`BatchingWindowSupportedQueues`,"Batching window is not supported for FIFO queues",queue);if(!this.props.maxBatchingWindow.isUnresolved()&&this.props.maxBatchingWindow.toSeconds()>300)throw new(core_1()).ValidationError((0,literal_string_1().lit)`MaximumBatchingWindowSecondsLess`,`Maximum batching window must be 300 seconds or less (given ${this.props.maxBatchingWindow.toHumanString()})`,queue)}if(this.props.batchSize!==void 0&&!core_1().Token.isUnresolved(this.props.batchSize)){if(this.props.maxBatchingWindow!==void 0&&(this.props.batchSize<1||this.props.batchSize>1e4))throw new(core_1()).ValidationError((0,literal_string_1().lit)`MaximumBatchSizeInclusiveGiven`,`Maximum batch size must be between 1 and 10000 inclusive (given ${this.props.batchSize}) when batching window is specified.`,queue);if(this.props.maxBatchingWindow===void 0&&(this.props.batchSize<1||this.props.batchSize>10))throw new(core_1()).ValidationError((0,literal_string_1().lit)`MaximumBatchSizeInclusiveGiven`,`Maximum batch size must be between 1 and 10 inclusive (given ${this.props.batchSize}) when batching window is not specified.`,queue)}if(this.props.provisionedPollerConfig){if(this.props.maxConcurrency!==void 0)throw new(core_1()).ValidationError((0,literal_string_1().lit)`SqsProvisionedPollerConfigMaxConcurrencyMutuallyExclusive`,"provisionedPollerConfig and maxConcurrency are mutually exclusive \u2014 specify only one",queue);const{minimumPollers,maximumPollers}=this.props.provisionedPollerConfig,hasMin=minimumPollers!==void 0&&!core_1().Token.isUnresolved(minimumPollers),hasMax=maximumPollers!==void 0&&!core_1().Token.isUnresolved(maximumPollers);if(hasMin&&(minimumPollers<2||minimumPollers>200))throw new(core_1()).ValidationError((0,literal_string_1().lit)`SqsMinimumProvisionedPollersInclusive`,`Minimum provisioned pollers for SQS must be between 2 and 200 inclusive, got: ${minimumPollers}`,queue);if(hasMax&&(maximumPollers<2||maximumPollers>2e3))throw new(core_1()).ValidationError((0,literal_string_1().lit)`SqsMaximumProvisionedPollersInclusive`,`Maximum provisioned pollers for SQS must be between 2 and 2000 inclusive, got: ${maximumPollers}`,queue);if(hasMin&&hasMax&&minimumPollers>maximumPollers)throw new(core_1()).ValidationError((0,literal_string_1().lit)`SqsMinimumProvisionedPollersLessEqual`,`Minimum provisioned pollers must be less than or equal to maximum provisioned pollers, got: min=${minimumPollers}, max=${maximumPollers}`,queue)}}bind(target){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_IFunction(target)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}const eventSourceMapping=target.addEventSourceMapping(`SqsEventSource:${core_1().Names.nodeUniqueId(this.queue.node)}`,{batchSize:this.props.batchSize,maxBatchingWindow:this.props.maxBatchingWindow,maxConcurrency:this.props.maxConcurrency,reportBatchItemFailures:this.props.reportBatchItemFailures,enabled:this.props.enabled,eventSourceArn:this.queue.queueArn,filters:this.props.filters,filterEncryption:this.props.filterEncryption,metricsConfig:this.props.metricsConfig,provisionedPollerConfig:this.props.provisionedPollerConfig});this._eventSourceMappingId=eventSourceMapping.eventSourceMappingId,this._eventSourceMappingArn=eventSourceMapping.eventSourceMappingArn,target.role?this.queue.grantConsumeMessages(target):core_1().Annotations.of(target).addWarningV2("@aws-cdk/aws-lambda-event-sources:sqsFunctionImportWithoutRole",`Function '${target.node.path}' was imported without an IAM role so it was not granted access to consume messages from '${this.queue.node.path}'`)}get eventSourceMappingId(){if(!this._eventSourceMappingId)throw new(core_1()).ValidationError((0,literal_string_1().lit)`SqsEventSourceYetBound`,"SqsEventSource is not yet bound to an event source mapping",this.queue);return this._eventSourceMappingId}get eventSourceMappingArn(){if(!this._eventSourceMappingArn)throw new(core_1()).ValidationError((0,literal_string_1().lit)`SqsEventSourceYetBound`,"SqsEventSource is not yet bound to an event source mapping",this.queue);return this._eventSourceMappingArn}}exports.SqsEventSource=SqsEventSource;