UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 7.93 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ERROR_OUTPUT_TYPE=exports.PARTITION_KEY_LAMBDA=exports.PARTITION_KEY_QUERY=void 0,exports.createLoggingOptions=createLoggingOptions,exports.createBufferingHints=createBufferingHints,exports.createEncryptionConfig=createEncryptionConfig,exports.createProcessingConfig=createProcessingConfig,exports.createBackupConfig=createBackupConfig,exports.createDynamicPartitioningConfiguration=createDynamicPartitioningConfiguration;var constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},logs=()=>{var tmp=require("../../../aws-logs");return logs=()=>tmp,tmp},s3=()=>{var tmp=require("../../../aws-s3");return s3=()=>tmp,tmp},cdk=()=>{var tmp=require("../../../core");return cdk=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("../../../core/lib/private/literal-string");return literal_string_1=()=>tmp,tmp},util_1=()=>{var tmp=require("../../../core/lib/util");return util_1=()=>tmp,tmp};exports.PARTITION_KEY_QUERY="partitionKeyFromQuery",exports.PARTITION_KEY_LAMBDA="partitionKeyFromLambda",exports.ERROR_OUTPUT_TYPE="!{firehose:error-output-type}";function createLoggingOptions(scope,props){if(props.loggingConfig?.logging!==!1||props.loggingConfig?.logGroup){const logGroup=props.loggingConfig?.logGroup??constructs_1().Node.of(scope).tryFindChild("LogGroup")??new(logs()).LogGroup(scope,"LogGroup"),logGroupGrant=logGroup.grantWrite(props.role);return{loggingOptions:{enabled:!0,logGroupName:logGroup.logGroupName,logStreamName:logGroup.addStream(props.streamId).logStreamName},dependables:[logGroupGrant]}}}function createBufferingHints(scope,interval,size,dataFormatConversionEnabled,dynamicPartitioningEnabled){if(!interval&&!size&&!dataFormatConversionEnabled&&!dynamicPartitioningEnabled)return;const intervalInSeconds=interval?.toSeconds()??300;if(!cdk().Token.isUnresolved(intervalInSeconds)){if(intervalInSeconds>900)throw new(cdk()).ValidationError((0,literal_string_1().lit)`BufferingIntervalTooLarge`,`Buffering interval must be less than 900 seconds, got ${intervalInSeconds} seconds.`,scope);if(dynamicPartitioningEnabled&&intervalInSeconds<60)throw new(cdk()).ValidationError((0,literal_string_1().lit)`DynamicPartitioningBufferingIntervalTooSmall`,`When dynamic partitioning is enabled, buffering interval must be at least 60 seconds, got ${intervalInSeconds} seconds.`,scope)}const defaultSizeInMBs=dataFormatConversionEnabled||dynamicPartitioningEnabled?128:5,sizeInMBs=size?.toMebibytes()??defaultSizeInMBs;if(!cdk().Token.isUnresolved(sizeInMBs)){if(sizeInMBs>128)throw new(cdk()).ValidationError((0,literal_string_1().lit)`BufferingSizeTooLarge`,`Buffering size must be at most 128 MiBs, got ${sizeInMBs} MiBs.`,scope);if((dataFormatConversionEnabled||dynamicPartitioningEnabled)&&sizeInMBs<64)throw new(cdk()).ValidationError((0,literal_string_1().lit)`DataFormatConversionBufferingSizeTooSmall`,`When data format conversion or dynamic partitioning is enabled, buffering size must be at least 64 MiBs, got ${sizeInMBs} MiBs.`,scope);if(sizeInMBs<1)throw new(cdk()).ValidationError((0,literal_string_1().lit)`BufferingSizeTooSmall`,`Buffering size must be at least 1 MiB, got ${sizeInMBs} MiBs.`,scope)}return{intervalInSeconds,sizeInMBs}}function createEncryptionConfig(role,encryptionKey){return encryptionKey?.grantEncryptDecrypt(role),encryptionKey?{kmsEncryptionConfig:{awskmsKeyArn:encryptionKey.keyArn}}:void 0}function createProcessingConfig(scope,props,options){if(props.processor&&props.processors)throw new(cdk()).ValidationError((0,literal_string_1().lit)`ProcessorAndProcessorsConflict`,"You can specify either 'processors' or 'processor', not both.",scope);const processors=((props.processor?[props.processor]:props.processors)??[]).map(dp=>renderDataProcessor(dp,scope,options)),processorTypes=new Set(processors.map(p=>p.type));if(processorTypes.has("CloudWatchLogProcessing")&&!processorTypes.has("Decompression"))throw new(cdk()).ValidationError((0,literal_string_1().lit)`CloudWatchLogProcessorRequiresDecompression`,"CloudWatchLogProcessor can only be enabled with DecompressionProcessor",scope);if(options.dynamicPartitioningEnabled){const withLambda=processorTypes.has("Lambda"),withInline=processorTypes.has("MetadataExtraction");if(!options.prefix)throw new(cdk()).ValidationError((0,literal_string_1().lit)`DynamicPartitioningRequiresDataOutputPrefix`,"When dynamic partitioning is enabled, you must specify dataOutputPrefix.",scope);if(!withLambda&&!withInline)throw new(cdk()).ValidationError((0,literal_string_1().lit)`DynamicPartitioningRequiresProcessors`,"When dynamic partitioning is enabled, you must specify ether LambdaFunctionProcessor or MetadataExtractionProcessor, or both.",scope);if(withLambda&&!withInline&&!options.prefix.includes(`!{${exports.PARTITION_KEY_LAMBDA}:`))throw new(cdk()).ValidationError((0,literal_string_1().lit)`DynamicPartitioningLambdaRequiresPartitionKey`,`When dynamic partitioning is enabled and the only LambdaFunctionProcessor is specified, you must specify at least one instance of !{${exports.PARTITION_KEY_LAMBDA}:keyID}.`,scope);if(!withLambda&&options.prefix.includes(`!{${exports.PARTITION_KEY_LAMBDA}:`))throw new(cdk()).ValidationError((0,literal_string_1().lit)`LambdaPartitionKeyRequiresProcessor`,`The dataOutputPrefix cannot contain !{${exports.PARTITION_KEY_LAMBDA}:keyID} when LambdaFunctionProcessor is not specified.`,scope);if(!withInline&&options.prefix.includes(`!{${exports.PARTITION_KEY_QUERY}:`))throw new(cdk()).ValidationError((0,literal_string_1().lit)`QueryPartitionKeyRequiresProcessor`,`The dataOutputPrefix cannot contain !{${exports.PARTITION_KEY_QUERY}:keyID} when MetadataExtractionProcessor is not specified.`,scope)}if(processors.length!==0)return{enabled:!0,processors}}function renderDataProcessor(processor,scope,options){const processorConfig=processor.bind(scope,options);if(processorConfig.parameters)return{type:processorConfig.processorType,parameters:processorConfig.parameters};const parameters=[{parameterName:"RoleArn",parameterValue:options.role.roleArn}];return parameters.push(processorConfig.processorIdentifier),processor.props.bufferInterval&&parameters.push({parameterName:"BufferIntervalInSeconds",parameterValue:processor.props.bufferInterval.toSeconds().toString()}),processor.props.bufferSize&&parameters.push({parameterName:"BufferSizeInMBs",parameterValue:processor.props.bufferSize.toMebibytes().toString()}),processor.props.retries&&parameters.push({parameterName:"NumberOfRetries",parameterValue:processor.props.retries.toString()}),{type:processorConfig.processorType,parameters}}function createBackupConfig(scope,role,props){if(!props||props.mode===void 0&&!props.bucket)return;const bucket=props.bucket??new(s3()).Bucket(scope,"BackupBucket"),bucketGrant=bucket.grantReadWrite(role),{loggingOptions,dependables:loggingDependables}=createLoggingOptions(scope,{loggingConfig:props.loggingConfig,role,streamId:"S3Backup"})??{};return{backupConfig:{bucketArn:bucket.bucketArn,roleArn:role.roleArn,prefix:props.dataOutputPrefix,errorOutputPrefix:props.errorOutputPrefix,bufferingHints:createBufferingHints(scope,props.bufferingInterval,props.bufferingSize),compressionFormat:props.compression?.value,encryptionConfiguration:createEncryptionConfig(role,props.encryptionKey),cloudWatchLoggingOptions:loggingOptions},dependables:[bucketGrant,...loggingDependables??[]]}}function createDynamicPartitioningConfiguration(scope,props){if(!props)return;const durationInSeconds=props.retryDuration?.toSeconds();if(durationInSeconds!=null&&!cdk().Token.isUnresolved(durationInSeconds)&&durationInSeconds>7200)throw new(cdk()).ValidationError((0,literal_string_1().lit)`RetryDurationTooLarge`,`Retry duration must be less than 7200 seconds, got ${durationInSeconds} seconds.`,scope);return{enabled:props.enabled,retryOptions:(0,util_1().undefinedIfAllValuesAreEmpty)({durationInSeconds})}}