-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(sagemaker-alpha): add Pipeline import methods for existing SageMaker Pipelines #35230
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
Open
pahud
wants to merge
6
commits into
aws:main
Choose a base branch
from
pahud:fix-35220
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8851e8a
feat(aws-sagemaker-alpha): add Pipeline import methods for existing S…
pahud 3bcb381
update snapshots
pahud 3c785b2
Merge branch 'main' into fix-35220
pahud 0fd16c2
update test
pahud 5be9bae
fix rosetta error
pahud c46d5a7
import IPipeline from aws-sagemaker
pahud 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 hidden or 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 hidden or 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 hidden or 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,189 @@ | ||
| import { Construct } from 'constructs'; | ||
| import { Grant, IGrantable } from 'aws-cdk-lib/aws-iam'; | ||
| import { IPipeline } from 'aws-cdk-lib/aws-sagemaker'; | ||
| import { Arn, Resource, Stack, Token } from 'aws-cdk-lib'; | ||
| import { ValidationError } from 'aws-cdk-lib/core/lib/errors'; | ||
|
|
||
| /** | ||
| * Validates a SageMaker Pipeline name according to AWS requirements | ||
| * @param pipelineName The pipeline name to validate | ||
| * @param scope The construct scope for error reporting | ||
| * @throws ValidationError if the pipeline name is invalid | ||
| */ | ||
| function validatePipelineName(pipelineName: string, scope: Construct): void { | ||
| // Skip validation for CDK tokens | ||
| if (Token.isUnresolved(pipelineName)) { | ||
| return; | ||
| } | ||
|
|
||
| // Check length constraints (1-256 characters) | ||
| if (!pipelineName || pipelineName.length === 0 || pipelineName.length > 256) { | ||
| throw new ValidationError(`Invalid pipeline name format: ${pipelineName}. Pipeline name must be between 1-256 characters.`, scope); | ||
| } | ||
|
|
||
| // Check character pattern: must start and end with alphanumeric, can contain hyphens | ||
| if (!/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$/.test(pipelineName)) { | ||
| throw new ValidationError(`Invalid pipeline name format: ${pipelineName}. Must start and end with alphanumeric characters, can contain hyphens but not consecutive hyphens, underscores, dots, or spaces.`, scope); | ||
| } | ||
|
|
||
| // Check for consecutive hyphens (not allowed) | ||
| if (pipelineName.includes('--')) { | ||
| throw new ValidationError(`Invalid pipeline name format: ${pipelineName}. Cannot contain consecutive hyphens.`, scope); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Attributes for importing a SageMaker Pipeline | ||
| */ | ||
| export interface PipelineAttributes { | ||
| /** | ||
| * The ARN of the pipeline | ||
| * @default - Either this or pipelineName must be provided | ||
| */ | ||
| readonly pipelineArn?: string; | ||
|
|
||
| /** | ||
| * The name of the pipeline | ||
| * @default - Either this or pipelineArn must be provided | ||
| */ | ||
| readonly pipelineName?: string; | ||
|
|
||
| /** | ||
| * The account the pipeline is in | ||
| * @default - same account as the stack | ||
| */ | ||
| readonly account?: string; | ||
|
|
||
| /** | ||
| * The region the pipeline is in | ||
| * @default - same region as the stack | ||
| */ | ||
| readonly region?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Properties for defining a SageMaker Pipeline | ||
| */ | ||
| export interface PipelineProps { | ||
| /** | ||
| * The physical name of the pipeline | ||
| * @default - CDK generated name | ||
| */ | ||
| readonly pipelineName?: string; | ||
| } | ||
|
|
||
| /** | ||
| * A SageMaker Pipeline | ||
| * | ||
| * @resource AWS::SageMaker::Pipeline | ||
| */ | ||
| export class Pipeline extends Resource implements IPipeline { | ||
| /** | ||
| * Import a pipeline from its ARN | ||
| * | ||
| * @param scope The parent construct | ||
| * @param id The construct id | ||
| * @param pipelineArn The ARN of the pipeline | ||
| */ | ||
| public static fromPipelineArn(scope: Construct, id: string, pipelineArn: string): IPipeline { | ||
| return Pipeline.fromPipelineAttributes(scope, id, { pipelineArn }); | ||
| } | ||
|
|
||
| /** | ||
| * Import a pipeline from its name | ||
| * | ||
| * For this to work, the pipeline must be in the same account and region as the stack. | ||
| * | ||
| * @param scope The parent construct | ||
| * @param id The construct id | ||
| * @param pipelineName The name of the pipeline | ||
| */ | ||
| public static fromPipelineName(scope: Construct, id: string, pipelineName: string): IPipeline { | ||
| return Pipeline.fromPipelineAttributes(scope, id, { pipelineName }); | ||
| } | ||
|
|
||
| /** | ||
| * Import a pipeline from attributes | ||
| * | ||
| * @param scope The parent construct | ||
| * @param id The construct id | ||
| * @param attrs The attributes of the pipeline to import | ||
| */ | ||
| public static fromPipelineAttributes(scope: Construct, id: string, attrs: PipelineAttributes): IPipeline { | ||
| const stack = Stack.of(scope); | ||
|
|
||
| // Determine pipeline name and ARN | ||
| let pipelineName: string; | ||
| let pipelineArn: string; | ||
|
|
||
| if (attrs.pipelineArn) { | ||
| pipelineArn = attrs.pipelineArn; | ||
| pipelineName = Arn.extractResourceName(pipelineArn, 'pipeline'); | ||
| } else if (attrs.pipelineName !== undefined) { | ||
| pipelineName = attrs.pipelineName; | ||
| // Validate pipeline name format | ||
| validatePipelineName(pipelineName, scope); | ||
|
|
||
| pipelineArn = stack.formatArn({ | ||
| service: 'sagemaker', | ||
| resource: 'pipeline', | ||
| resourceName: pipelineName, | ||
| account: attrs.account, | ||
| region: attrs.region, | ||
| }); | ||
| } else { | ||
| throw new ValidationError('Either pipelineArn or pipelineName must be provided', scope); | ||
| } | ||
|
|
||
| class Import extends Resource implements IPipeline { | ||
| public readonly pipelineArn = pipelineArn; | ||
| public readonly pipelineName = pipelineName; | ||
|
|
||
| public grantStartPipelineExecution(grantee: IGrantable): Grant { | ||
| return Grant.addToPrincipal({ | ||
| grantee, | ||
| actions: ['sagemaker:StartPipelineExecution'], | ||
| resourceArns: [this.pipelineArn], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return new Import(scope, id, { | ||
| account: attrs.account, | ||
| region: attrs.region, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * The ARN of the pipeline. | ||
| */ | ||
| public readonly pipelineArn!: string; | ||
|
|
||
| /** | ||
| * The name of the pipeline. | ||
| */ | ||
| public readonly pipelineName!: string; | ||
|
|
||
| /** | ||
| * Create a new Pipeline (not supported - use import methods instead) | ||
| * @internal | ||
| */ | ||
| constructor(scope: Construct, id: string, props?: PipelineProps) { | ||
| super(scope, id); | ||
| // Suppress unused parameter warning | ||
| void props; | ||
| throw new ValidationError('Pipeline construct cannot be instantiated directly. Use Pipeline.fromPipelineArn() or Pipeline.fromPipelineName() to import existing pipelines.', scope); | ||
| } | ||
|
|
||
| /** | ||
| * Permits an IAM principal to start this pipeline execution | ||
| * @param grantee The principal to grant access to | ||
| */ | ||
| public grantStartPipelineExecution(grantee: IGrantable): Grant { | ||
| return Grant.addToPrincipal({ | ||
| grantee, | ||
| actions: ['sagemaker:StartPipelineExecution'], | ||
| resourceArns: [this.pipelineArn], | ||
| }); | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
...est/integ.pipeline-import.js.snapshot/aws-cdk-sagemaker-alpha-pipeline-import.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
Not sure if we should duplicate the IPipeline in the alpha module. Tentatively import it from stable module for now. Please advise if we should duplicate instead.