UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 7.17 kB
"use strict";var _a,_b,_c;Object.defineProperty(exports,"__esModule",{value:!0}),exports.EcsRunEc2Task=exports.EcsRunFargateTask=exports.EcsRunTask=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var target_1=()=>{var tmp=require("./target");return target_1=()=>tmp,tmp},ec2=()=>{var tmp=require("../../aws-ec2");return ec2=()=>tmp,tmp},ecs=()=>{var tmp=require("../../aws-ecs");return ecs=()=>tmp,tmp},aws_iam_1=()=>{var tmp=require("../../aws-iam");return aws_iam_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp};class EcsRunTask extends target_1().ScheduleTargetBase{constructor(cluster,props){super(props,cluster.clusterArn),this.cluster=cluster,this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ecs_ICluster(cluster),jsiiDeprecationWarnings().aws_cdk_lib_aws_scheduler_targets_EcsRunTaskBaseProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,EcsRunTask),error}}addTargetActionToRole(role){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IRole(role)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.addTargetActionToRole),error}this.props.taskDefinition.grantRun(role),(this.props.propagateTags===!0||this.props.tags)&&role.addToPrincipalPolicy(new(aws_iam_1()).PolicyStatement({actions:["ecs:TagResource"],resources:[`arn:${this.cluster.stack.partition}:ecs:${this.cluster.env.region}:${this.props.taskDefinition.env.account}:task/${this.cluster.clusterName}/*`]}))}bindBaseTargetConfig(_schedule){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_scheduler_ISchedule(_schedule)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bindBaseTargetConfig),error}return{...super.bindBaseTargetConfig(_schedule),ecsParameters:{taskDefinitionArn:this.props.taskDefinition.taskDefinitionArn,capacityProviderStrategy:this.props.capacityProviderStrategies,taskCount:this.props.taskCount,tags:this.props.tags,propagateTags:this.props.propagateTags?ecs().PropagatedTagSource.TASK_DEFINITION:void 0,enableEcsManagedTags:this.props.enableEcsManagedTags,enableExecuteCommand:this.props.enableExecuteCommand,group:this.props.group,referenceId:this.props.referenceId}}}}exports.EcsRunTask=EcsRunTask,_a=JSII_RTTI_SYMBOL_1,EcsRunTask[_a]={fqn:"aws-cdk-lib.aws_scheduler_targets.EcsRunTask",version:"2.213.0"};class EcsRunFargateTask extends EcsRunTask{constructor(cluster,props){super(cluster,props);try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ecs_ICluster(cluster),jsiiDeprecationWarnings().aws_cdk_lib_aws_scheduler_targets_FargateTaskProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,EcsRunFargateTask),error}this.subnetSelection=props.vpcSubnets,this.assignPublicIp=props.assignPublicIp,this.platformVersion=props.platformVersion,this.capacityProviderStrategies=props.capacityProviderStrategies}bindBaseTargetConfig(_schedule){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_scheduler_ISchedule(_schedule)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bindBaseTargetConfig),error}if(!this.props.taskDefinition.isFargateCompatible)throw new(core_1()).ValidationError("TaskDefinition is not compatible with Fargate launch type.",_schedule);const subnetSelection=this.subnetSelection||{subnetType:ec2().SubnetType.PRIVATE_WITH_EGRESS};if(this.assignPublicIp&&subnetSelection.subnetType!==ec2().SubnetType.PUBLIC)throw new(core_1()).ValidationError("assignPublicIp should be set to true only for public subnets",_schedule);const assignPublicIp=this.assignPublicIp!==void 0?this.assignPublicIp?"ENABLED":"DISABLED":subnetSelection.subnetType===ec2().SubnetType.PUBLIC?"ENABLED":"DISABLED",launchType=this.capacityProviderStrategies?void 0:ecs().LaunchType.FARGATE,bindBaseTargetConfigParameters=super.bindBaseTargetConfig(_schedule).ecsParameters;return{...super.bindBaseTargetConfig(_schedule),ecsParameters:{...bindBaseTargetConfigParameters,launchType,platformVersion:this.platformVersion,networkConfiguration:{awsvpcConfiguration:{assignPublicIp,subnets:this.cluster.vpc.selectSubnets(subnetSelection).subnetIds,securityGroups:this.props.securityGroups&&this.props.securityGroups.length>0?this.props.securityGroups?.map(sg=>sg.securityGroupId):void 0}}}}}}exports.EcsRunFargateTask=EcsRunFargateTask,_b=JSII_RTTI_SYMBOL_1,EcsRunFargateTask[_b]={fqn:"aws-cdk-lib.aws_scheduler_targets.EcsRunFargateTask",version:"2.213.0"};class EcsRunEc2Task extends EcsRunTask{constructor(cluster,props){super(cluster,props);try{jsiiDeprecationWarnings().aws_cdk_lib_aws_ecs_ICluster(cluster),jsiiDeprecationWarnings().aws_cdk_lib_aws_scheduler_targets_Ec2TaskProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,EcsRunEc2Task),error}this.placementConstraints=props.placementConstraints,this.placementStrategies=props.placementStrategies,this.capacityProviderStrategies=props.capacityProviderStrategies}bindBaseTargetConfig(_schedule){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_scheduler_ISchedule(_schedule)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bindBaseTargetConfig),error}if(this.props.taskDefinition.compatibility===ecs().Compatibility.FARGATE)throw new(core_1()).ValidationError("TaskDefinition is not compatible with EC2 launch type",_schedule);const launchType=this.capacityProviderStrategies?void 0:ecs().LaunchType.EC2,taskDefinitionUsesAwsVpc=this.props.taskDefinition.networkMode===ecs().NetworkMode.AWS_VPC;if(!taskDefinitionUsesAwsVpc&&(this.props.securityGroups||this.props.vpcSubnets))throw new(core_1()).ValidationError("Security groups and subnets can only be used with awsvpc network mode",_schedule);const subnetSelection=taskDefinitionUsesAwsVpc?this.props.vpcSubnets||{subnetType:ec2().SubnetType.PRIVATE_WITH_EGRESS}:void 0,bindBaseTargetConfigParameters=super.bindBaseTargetConfig(_schedule).ecsParameters;return{...super.bindBaseTargetConfig(_schedule),ecsParameters:{...bindBaseTargetConfigParameters,launchType,placementConstraints:core_1().Lazy.any({produce:()=>this.placementConstraints?.length?this.placementConstraints?.map(constraint=>constraint.toJson()).flat():void 0}),placementStrategy:core_1().Lazy.any({produce:()=>this.placementStrategies?.length?this.placementStrategies?.map(strategy=>strategy.toJson()).flat():void 0},{omitEmptyArray:!0}),...taskDefinitionUsesAwsVpc&&{networkConfiguration:{awsvpcConfiguration:{subnets:this.cluster.vpc.selectSubnets(subnetSelection).subnetIds,securityGroups:this.props.securityGroups&&this.props.securityGroups.length>0?this.props.securityGroups.map(sg=>sg.securityGroupId):void 0}}}}}}}exports.EcsRunEc2Task=EcsRunEc2Task,_c=JSII_RTTI_SYMBOL_1,EcsRunEc2Task[_c]={fqn:"aws-cdk-lib.aws_scheduler_targets.EcsRunEc2Task",version:"2.213.0"};