-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scheduler-targets-alpha):
SageMakerStartPipelineExecution
Targ…
…et (#28927) This PR adds SageMakerStartPipelineExecution Target for EventBridge Scheduler. Closes #27457 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
17 changed files
with
35,609 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/@aws-cdk/aws-scheduler-targets-alpha/lib/sage-maker-start-pipeline-execution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { ISchedule, IScheduleTarget, ScheduleTargetConfig } from '@aws-cdk/aws-scheduler-alpha'; | ||
import { Names } from 'aws-cdk-lib'; | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import { IPipeline } from 'aws-cdk-lib/aws-sagemaker'; | ||
import { ScheduleTargetBase, ScheduleTargetBaseProps } from './target'; | ||
import { sameEnvDimension } from './util'; | ||
|
||
/** | ||
* Properties for a pipeline parameter | ||
*/ | ||
export interface SageMakerPipelineParameter { | ||
/** | ||
* Name of parameter to start execution of a SageMaker Model Building Pipeline. | ||
*/ | ||
readonly name: string; | ||
|
||
/** | ||
* Value of parameter to start execution of a SageMaker Model Building Pipeline. | ||
*/ | ||
readonly value: string; | ||
} | ||
|
||
/** | ||
* Properties for a SageMaker Target | ||
*/ | ||
export interface SageMakerStartPipelineExecutionProps extends ScheduleTargetBaseProps { | ||
/** | ||
* List of parameter names and values to use when executing the SageMaker Model Building Pipeline. | ||
* | ||
* The length must be between 0 and 200. | ||
* | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-sagemakerpipelineparameters.html#cfn-scheduler-schedule-sagemakerpipelineparameters-pipelineparameterlist | ||
* | ||
* @default - no pipeline parameter list | ||
*/ | ||
readonly pipelineParameterList?: SageMakerPipelineParameter[]; | ||
} | ||
|
||
/** | ||
* Use a SageMaker pipeline as a target for AWS EventBridge Scheduler. | ||
*/ | ||
export class SageMakerStartPipelineExecution extends ScheduleTargetBase implements IScheduleTarget { | ||
constructor( | ||
private readonly pipeline: IPipeline, | ||
private readonly props: SageMakerStartPipelineExecutionProps = {}, | ||
) { | ||
super(props, pipeline.pipelineArn); | ||
|
||
if (props.pipelineParameterList !== undefined && props.pipelineParameterList.length > 200) { | ||
throw new Error(`pipelineParameterList length must be between 0 and 200, got ${props.pipelineParameterList.length}`); | ||
} | ||
} | ||
|
||
protected addTargetActionToRole(schedule: ISchedule, role: IRole): void { | ||
if (!sameEnvDimension(this.pipeline.stack.region, schedule.env.region)) { | ||
throw new Error(`Cannot assign pipeline in region ${this.pipeline.stack.region} to the schedule ${Names.nodeUniqueId(schedule.node)} in region ${schedule.env.region}. Both the schedule and the pipeline must be in the same region.`); | ||
} | ||
|
||
if (!sameEnvDimension(this.pipeline.stack.account, schedule.env.account)) { | ||
throw new Error(`Cannot assign pipeline in account ${this.pipeline.stack.account} to the schedule ${Names.nodeUniqueId(schedule.node)} in account ${schedule.env.region}. Both the schedule and the pipeline must be in the same account.`); | ||
} | ||
|
||
if (this.props.role && !sameEnvDimension(this.props.role.env.account, this.pipeline.stack.account)) { | ||
throw new Error(`Cannot grant permission to execution role in account ${this.props.role.env.account} to invoke target ${Names.nodeUniqueId(this.pipeline.node)} in account ${this.pipeline.stack.account}. Both the target and the execution role must be in the same account.`); | ||
} | ||
|
||
this.pipeline.grantStartPipelineExecution(role); | ||
} | ||
|
||
protected bindBaseTargetConfig(schedule: ISchedule): ScheduleTargetConfig { | ||
const sageMakerPipelineParameters = this.props.pipelineParameterList ? { | ||
pipelineParameterList: this.props.pipelineParameterList.map(param => { | ||
return { | ||
name: param.name, | ||
value: param.value, | ||
}; | ||
}), | ||
} : undefined; | ||
return { | ||
...super.bindBaseTargetConfig(schedule), | ||
sageMakerPipelineParameters, | ||
}; | ||
} | ||
} |
Oops, something went wrong.