Skip to content

Commit

Permalink
add IPipeline
Browse files Browse the repository at this point in the history
using IPipeline

grantStartPipelineExecution

tweak

tweak

tweak

fix eslint error

tweak
  • Loading branch information
go-to-k committed Feb 7, 2024
1 parent bb687e6 commit 0e29910
Show file tree
Hide file tree
Showing 12 changed files with 644 additions and 764 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-scheduler-targets-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ called every hour by Event Bridge Scheduler.
```ts
import * as sagemaker from 'aws-cdk-lib/aws-sagemaker';

declare const pipeline: sagemaker.CfnPipeline;
declare const pipeline: sagemaker.IPipeline;

new Schedule(this, 'Schedule', {
schedule: ScheduleExpression.rate(Duration.minutes(60)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 { 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';

Expand Down Expand Up @@ -40,20 +40,11 @@ export interface SageMakerStartPipelineExecutionProps extends ScheduleTargetBase
* 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 pipeline: IPipeline,
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;
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}`);
Expand All @@ -73,13 +64,10 @@ export class SageMakerStartPipelineExecution extends ScheduleTargetBase implemen
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],
}));
this.pipeline.grantStartPipelineExecution(role);
}

protected bindBaseTargetConfig(_schedule: ISchedule): ScheduleTargetConfig {
protected bindBaseTargetConfig(schedule: ISchedule): ScheduleTargetConfig {
const sageMakerPipelineParameters = this.props.pipelineParameterList ? {
pipelineParameterList: this.props.pipelineParameterList.map(param => {
return {
Expand All @@ -89,7 +77,7 @@ export class SageMakerStartPipelineExecution extends ScheduleTargetBase implemen
}),
} : undefined;
return {
...super.bindBaseTargetConfig(_schedule),
...super.bindBaseTargetConfig(schedule),
sageMakerPipelineParameters,
};
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Resources": {
"SourceBucketDDD2130A": {
"PipelineSourceBucket23FDFC28": {
"Type": "AWS::S3::Bucket",
"Properties": {
"Tags": [
Expand All @@ -13,11 +13,11 @@
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"SourceBucketPolicy703DFBF9": {
"PipelineSourceBucketPolicy017B174D": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "SourceBucketDDD2130A"
"Ref": "PipelineSourceBucket23FDFC28"
},
"PolicyDocument": {
"Statement": [
Expand All @@ -40,7 +40,7 @@
"Resource": [
{
"Fn::GetAtt": [
"SourceBucketDDD2130A",
"PipelineSourceBucket23FDFC28",
"Arn"
]
},
Expand All @@ -50,7 +50,7 @@
[
{
"Fn::GetAtt": [
"SourceBucketDDD2130A",
"PipelineSourceBucket23FDFC28",
"Arn"
]
},
Expand All @@ -65,7 +65,7 @@
}
}
},
"SourceBucketAutoDeleteObjectsCustomResourceC68FC040": {
"PipelineSourceBucketAutoDeleteObjectsCustomResource041F2E1E": {
"Type": "Custom::S3AutoDeleteObjects",
"Properties": {
"ServiceToken": {
Expand All @@ -75,74 +75,16 @@
]
},
"BucketName": {
"Ref": "SourceBucketDDD2130A"
"Ref": "PipelineSourceBucket23FDFC28"
}
},
"DependsOn": [
"SourceBucketPolicy703DFBF9"
"PipelineSourceBucketPolicy017B174D"
],
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
},
"ManagedPolicyArns": [
{
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
]
}
},
"CustomS3AutoDeleteObjectsCustomResourceProviderHandler9D90184F": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "2ec8ad9e91dcd6e7ad6a5c84ffc6c9c05c408aca3b26ceb2816d81043e6c4dc3.zip"
},
"Timeout": 900,
"MemorySize": 128,
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092",
"Arn"
]
},
"Runtime": "nodejs18.x",
"Description": {
"Fn::Join": [
"",
[
"Lambda function for auto-deleting objects in ",
{
"Ref": "SourceBucketDDD2130A"
},
" S3 bucket."
]
]
}
},
"DependsOn": [
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092"
]
},
"OutputBucket7114EB27": {
"PipelineOutputBucket98EA5F71": {
"Type": "AWS::S3::Bucket",
"Properties": {
"Tags": [
Expand All @@ -155,11 +97,11 @@
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"OutputBucketPolicyAE009DDC": {
"PipelineOutputBucketPolicy4566E5A8": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "OutputBucket7114EB27"
"Ref": "PipelineOutputBucket98EA5F71"
},
"PolicyDocument": {
"Statement": [
Expand All @@ -182,7 +124,7 @@
"Resource": [
{
"Fn::GetAtt": [
"OutputBucket7114EB27",
"PipelineOutputBucket98EA5F71",
"Arn"
]
},
Expand All @@ -192,7 +134,7 @@
[
{
"Fn::GetAtt": [
"OutputBucket7114EB27",
"PipelineOutputBucket98EA5F71",
"Arn"
]
},
Expand All @@ -207,7 +149,7 @@
}
}
},
"OutputBucketAutoDeleteObjectsCustomResource6C7A161F": {
"PipelineOutputBucketAutoDeleteObjectsCustomResource0CB6E67C": {
"Type": "Custom::S3AutoDeleteObjects",
"Properties": {
"ServiceToken": {
Expand All @@ -217,16 +159,16 @@
]
},
"BucketName": {
"Ref": "OutputBucket7114EB27"
"Ref": "PipelineOutputBucket98EA5F71"
}
},
"DependsOn": [
"OutputBucketPolicyAE009DDC"
"PipelineOutputBucketPolicy4566E5A8"
],
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"SageMakerPipelineRole4BE63DC1": {
"PipelineSageMakerPipelineRole7D1FE5F8": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
Expand Down Expand Up @@ -257,7 +199,7 @@
]
}
},
"Pipeline": {
"PipelineC660917D": {
"Type": "AWS::SageMaker::Pipeline",
"Properties": {
"PipelineDefinition": {
Expand All @@ -267,11 +209,11 @@
[
"{\"Version\":\"2020-12-01\",\"Metadata\":{},\"Parameters\":[{\"Name\":\"ParameterName\",\"Type\":\"String\",\"DefaultValue\":\"Value\"}],\"Steps\":[{\"Name\":\"TrainingStep\",\"Type\":\"Training\",\"Arguments\":{\"AlgorithmSpecification\":{\"TrainingImage\":\"382416733822.dkr.ecr.us-east-1.amazonaws.com/linear-learner:1\",\"TrainingInputMode\":\"File\"},\"InputDataConfig\":[{\"DataSource\":{\"S3DataSource\":{\"S3Uri\":\"s3://",
{
"Ref": "SourceBucketDDD2130A"
"Ref": "PipelineSourceBucket23FDFC28"
},
"\"}}}],\"OutputDataConfig\":{\"S3OutputPath\":\"s3://",
{
"Ref": "OutputBucket7114EB27"
"Ref": "PipelineOutputBucket98EA5F71"
},
"\"},\"ResourceConfig\":{\"InstanceCount\":1,\"InstanceType\":\"ml.m5.large\",\"VolumeSizeInGB\":50},\"StoppingCondition\":{\"MaxRuntimeInSeconds\":3600}}}]}"
]
Expand All @@ -281,12 +223,70 @@
"PipelineName": "my-pipeline",
"RoleArn": {
"Fn::GetAtt": [
"SageMakerPipelineRole4BE63DC1",
"PipelineSageMakerPipelineRole7D1FE5F8",
"Arn"
]
}
}
},
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
},
"ManagedPolicyArns": [
{
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
]
}
},
"CustomS3AutoDeleteObjectsCustomResourceProviderHandler9D90184F": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "2ec8ad9e91dcd6e7ad6a5c84ffc6c9c05c408aca3b26ceb2816d81043e6c4dc3.zip"
},
"Timeout": 900,
"MemorySize": 128,
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092",
"Arn"
]
},
"Runtime": "nodejs18.x",
"Description": {
"Fn::Join": [
"",
[
"Lambda function for auto-deleting objects in ",
{
"Ref": "PipelineSourceBucket23FDFC28"
},
" S3 bucket."
]
]
}
},
"DependsOn": [
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092"
]
},
"Schedule83A77FD1": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0e29910

Please sign in to comment.