|
| 1 | +import { IInputTransformation, IPipe, ITarget, TargetConfig } from '@aws-cdk/aws-pipes-alpha'; |
| 2 | +import { IRole } from 'aws-cdk-lib/aws-iam'; |
| 3 | +import { IPipeline } from 'aws-cdk-lib/aws-sagemaker'; |
| 4 | + |
| 5 | +/** |
| 6 | + * SageMaker target properties. |
| 7 | + */ |
| 8 | +export interface SageMakerTargetParameters { |
| 9 | + /** |
| 10 | + * The input transformation to apply to the message before sending it to the target. |
| 11 | + * |
| 12 | + * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargetparameters.html#cfn-pipes-pipe-pipetargetparameters-inputtemplate |
| 13 | + * @default - none |
| 14 | + */ |
| 15 | + readonly inputTransformation?: IInputTransformation; |
| 16 | + |
| 17 | + /** |
| 18 | + * List of parameter names and values for SageMaker Model Building Pipeline execution. |
| 19 | + * |
| 20 | + * The Name/Value pairs are passed to start execution of the pipeline. |
| 21 | + * |
| 22 | + * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargetsagemakerpipelineparameters.html#cfn-pipes-pipe-pipetargetsagemakerpipelineparameters-pipelineparameterlist |
| 23 | + * @default - none |
| 24 | + */ |
| 25 | + readonly pipelineParameters?: Record<string, string>; |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * An EventBridge Pipes target that sends messages to a SageMaker pipeline. |
| 30 | + */ |
| 31 | +export class SageMakerTarget implements ITarget { |
| 32 | + private pipeline: IPipeline; |
| 33 | + private sageMakerParameters?: SageMakerTargetParameters; |
| 34 | + private pipelineParameters?: Record<string, string>; |
| 35 | + public readonly targetArn: string; |
| 36 | + |
| 37 | + constructor(pipeline: IPipeline, parameters?: SageMakerTargetParameters) { |
| 38 | + this.pipeline = pipeline; |
| 39 | + this.targetArn = pipeline.pipelineArn; |
| 40 | + this.sageMakerParameters = parameters; |
| 41 | + this.pipelineParameters = this.sageMakerParameters?.pipelineParameters; |
| 42 | + } |
| 43 | + |
| 44 | + grantPush(grantee: IRole): void { |
| 45 | + this.pipeline.grantStartPipelineExecution(grantee); |
| 46 | + } |
| 47 | + |
| 48 | + bind(pipe: IPipe): TargetConfig { |
| 49 | + if (!this.sageMakerParameters) { |
| 50 | + return { targetParameters: {} }; |
| 51 | + } |
| 52 | + |
| 53 | + return { |
| 54 | + targetParameters: { |
| 55 | + inputTemplate: this.sageMakerParameters.inputTransformation?.bind(pipe).inputTemplate, |
| 56 | + sageMakerPipelineParameters: { |
| 57 | + pipelineParameterList: this.pipelineParameters ? |
| 58 | + Object.entries(this.pipelineParameters).map(([key, value]) => ({ |
| 59 | + name: key, |
| 60 | + value: value, |
| 61 | + })) : undefined, |
| 62 | + }, |
| 63 | + }, |
| 64 | + }; |
| 65 | + } |
| 66 | +} |
0 commit comments