aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 3.49 kB
JavaScript
"use strict";var _a;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};class SqsEventSource{constructor(queue,props={}){this.queue=queue,this.props=props,this._eventSourceMappingId=void 0,this._eventSourceMappingArn=void 0;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("Batching window is not supported for FIFO queues",queue);if(!this.props.maxBatchingWindow.isUnresolved()&&this.props.maxBatchingWindow.toSeconds()>300)throw new(core_1()).ValidationError(`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(`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(`Maximum batch size must be between 1 and 10 inclusive (given ${this.props.batchSize}) when batching window is not specified.`,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});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("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("SqsEventSource is not yet bound to an event source mapping",this.queue);return this._eventSourceMappingArn}}exports.SqsEventSource=SqsEventSource,_a=JSII_RTTI_SYMBOL_1,SqsEventSource[_a]={fqn:"aws-cdk-lib.aws_lambda_event_sources.SqsEventSource",version:"2.202.0"};