-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(scheduler-targets-alpha): SageMakerStartPipelineExecution
Target
#28927
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c4f2ae3
feat(scheduler-targets-alpha): Target
go-to-k 64275fd
new line
go-to-k 21513e3
integ test and snapshot
go-to-k 5a30af5
add unit test
go-to-k 5529915
Merge branch 'main' into scheduler-targets-sagemaker
go-to-k e41f5f5
import order in integs
go-to-k e2e3a37
fix rosetta
go-to-k 249220a
fix to SageMaker with capital M
go-to-k 05b0668
Merge branch 'scheduler-targets-sagemaker' of https://github.com/go-t…
go-to-k bb687e6
revert IPipeline
go-to-k 7671cca
add IPipeline
go-to-k 91d0a2f
Merge branch 'main' into scheduler-targets-sagemaker
go-to-k 55fbb20
change eslint settings and an integ test
go-to-k 0f0e67e
Update integ.sage-maker-start-pipeline-execution.ts
go-to-k 1fc2be5
Merge branch 'main' into scheduler-targets-sagemaker
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
96 changes: 96 additions & 0 deletions
96
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,96 @@ | ||
import { ISchedule, IScheduleTarget, ScheduleTargetConfig } from '@aws-cdk/aws-scheduler-alpha'; | ||
import { ArnFormat, Names, Stack } from 'aws-cdk-lib'; | ||
import { IRole, PolicyStatement } from 'aws-cdk-lib/aws-iam'; | ||
import { CfnPipeline } 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 { | ||
private readonly pipelineArn: string; | ||
|
||
constructor( | ||
private readonly pipeline: CfnPipeline, | ||
private readonly props: SageMakerStartPipelineExecutionProps = {}, | ||
) { | ||
const targetArn = Stack.of(pipeline).formatArn({ | ||
service: 'sagemaker', | ||
resource: 'pipeline', | ||
resourceName: pipeline.pipelineName, | ||
arnFormat: ArnFormat.SLASH_RESOURCE_NAME, | ||
}); | ||
super(props, targetArn); | ||
this.pipelineArn = targetArn; | ||
|
||
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.`); | ||
} | ||
|
||
role.addToPrincipalPolicy(new PolicyStatement({ | ||
actions: ['sagemaker:StartPipelineExecution'], | ||
resources: [this.pipelineArn], | ||
})); | ||
} | ||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is fine except for this... it should be an
IPipeline
but that doesn't exist yet. The problem is that this locks in people to the L1 pipeline, and ideally we'd want this to be interoperable with a community L2 if that existed.So how about adding a very barebones
IPipeline
construct toaws-sagemaker
. Nothing controversial, just kind of a placeholder. In the future, if we develop a Pipeline L2, it can build off of theIPipeline
as can any community L2. As long as we don't make any crazy decisions, this can be stable from day 1. We did something similar inIEndpoint
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
The
IEndpoint
is also creating an interface in theaws-sagemaker-alpha
module, but that is to ensure that the existing implementation is not affected, so is it correct to create it only in theaws-sagemaker
module for this PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed.