UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 10.3 kB
"use strict";var __esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0},__runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Schedule=exports.TimeWindow=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var scheduler_generated_1=()=>{var tmp=require("./scheduler.generated");return scheduler_generated_1=()=>tmp,tmp},cloudwatch=()=>{var tmp=require("../../aws-cloudwatch");return cloudwatch=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../../core/lib/metadata-resource");return metadata_resource_1=()=>tmp,tmp},prop_injectable_1=()=>{var tmp=require("../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp};class TimeWindow{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_scheduler.TimeWindow",version:"2.233.0"};static off(){return new TimeWindow("OFF")}static flexible(maxWindow){try{jsiiDeprecationWarnings().aws_cdk_lib_Duration(maxWindow)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.flexible),error}if(maxWindow.toMinutes()<1||maxWindow.toMinutes()>1440)throw new(core_1()).UnscopedValidationError(`The provided duration must be between 1 minute and 1440 minutes, got ${maxWindow.toMinutes()}`);return new TimeWindow("FLEXIBLE",maxWindow)}mode;maxWindow;constructor(mode,maxWindow){this.mode=mode,this.maxWindow=maxWindow}}exports.TimeWindow=TimeWindow;let Schedule=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=core_1().Resource;var Schedule2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),Schedule2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_scheduler.Schedule",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-scheduler.Schedule";static metricAll(metricName,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricAll),error}return new(cloudwatch()).Metric({namespace:"AWS/Scheduler",metricName,statistic:"sum",...props})}static metricAllThrottled(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricAllThrottled),error}return this.metricAll("InvocationThrottleCount",props)}static metricAllAttempts(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricAllAttempts),error}return this.metricAll("InvocationAttemptCount",props)}static metricAllErrors(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricAllErrors),error}return this.metricAll("TargetErrorCount",props)}static metricAllTargetThrottled(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricAllTargetThrottled),error}return this.metricAll("TargetErrorThrottledCount",props)}static metricAllDropped(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricAllDropped),error}return this.metricAll("InvocationDroppedCount",props)}static metricAllSentToDLQ(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricAllSentToDLQ),error}return this.metricAll("InvocationsSentToDeadLetterCount",props)}static metricAllFailedToBeSentToDLQ(errorCode,props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricAllFailedToBeSentToDLQ),error}return errorCode?this.metricAll(`InvocationsFailedToBeSentToDeadLetterCount_${errorCode}`,props):this.metricAll("InvocationsFailedToBeSentToDeadLetterCount",props)}static metricAllSentToDLQTruncated(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_cloudwatch_MetricOptions(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.metricAllSentToDLQTruncated),error}return this.metricAll("InvocationsSentToDeadLetterCount_Truncated_MessageSizeExceeded",props)}static fromScheduleArn(scope,id,scheduleArn){class Import extends core_1().Resource{scheduleArn=scheduleArn;scheduleName=core_1().Arn.split(scheduleArn,core_1().ArnFormat.SLASH_RESOURCE_NAME).resourceName.split("/")[1]}return new Import(scope,id)}scheduleGroup;scheduleArn;scheduleName;key;retryPolicy;constructor(scope,id,props){super(scope,id,{physicalName:props.scheduleName});try{jsiiDeprecationWarnings().aws_cdk_lib_aws_scheduler_ScheduleProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Schedule2),error}(0,metadata_resource_1().addConstructMetadata)(this,props),this.scheduleGroup=props.scheduleGroup;const targetConfig=props.target.bind(this);this.key=props.key,this.key&&this.key.grantDecrypt(targetConfig.role),this.retryPolicy=targetConfig.retryPolicy;const flexibleTimeWindow=props.timeWindow??TimeWindow.off();if(this.validateTimeFrame(props.start,props.end),props.scheduleName&&!core_1().Token.isUnresolved(props.scheduleName)&&props.scheduleName.length>64)throw new(core_1()).ValidationError(`scheduleName cannot be longer than 64 characters, got: ${props.scheduleName.length}`,this);const resource=new(scheduler_generated_1()).CfnSchedule(this,"Resource",{name:this.physicalName,flexibleTimeWindow:{mode:flexibleTimeWindow.mode,maximumWindowInMinutes:flexibleTimeWindow.maxWindow?.toMinutes()},scheduleExpression:props.schedule.expressionString,scheduleExpressionTimezone:props.schedule.timeZone?.timezoneName,groupName:this.scheduleGroup?.scheduleGroupName,state:props.enabled??!0?"ENABLED":"DISABLED",kmsKeyArn:this.key?.keyArn,target:{arn:targetConfig.arn,roleArn:targetConfig.role.roleArn,input:targetConfig.input?.bind(this),deadLetterConfig:targetConfig.deadLetterConfig,retryPolicy:this.renderRetryPolicy(),ecsParameters:targetConfig.ecsParameters,kinesisParameters:targetConfig.kinesisParameters,eventBridgeParameters:targetConfig.eventBridgeParameters,sageMakerPipelineParameters:targetConfig.sageMakerPipelineParameters,sqsParameters:targetConfig.sqsParameters},startDate:props.start?.toISOString(),endDate:props.end?.toISOString(),description:props.description});this.scheduleName=this.getResourceNameAttribute(resource.ref),this.scheduleArn=this.getResourceArnAttribute(resource.attrArn,{service:"scheduler",resource:"schedule",resourceName:`${this.scheduleGroup?.scheduleGroupName??"default"}/${this.physicalName}`})}renderRetryPolicy(){const policy={...this.retryPolicy};if(policy.maximumEventAgeInSeconds&&(policy.maximumEventAgeInSeconds<60||policy.maximumEventAgeInSeconds>86400))throw new(core_1()).ValidationError(`maximumEventAgeInSeconds must be between 60 and 86400, got ${policy.maximumEventAgeInSeconds}`,this);if(policy.maximumRetryAttempts&&(policy.maximumRetryAttempts<0||policy.maximumRetryAttempts>185))throw new(core_1()).ValidationError(`maximumRetryAttempts must be between 0 and 185, got ${policy.maximumRetryAttempts}`,this);return Object.values(policy).every(value=>value===void 0)?void 0:policy}validateTimeFrame(start,end){if(start&&end&&start>=end)throw new(core_1()).ValidationError(`start must precede end, got start: ${start.toISOString()}, end: ${end.toISOString()}`,this)}static{__runInitializers(_classThis,_classExtraInitializers)}};return Schedule2=_classThis})();exports.Schedule=Schedule;