From e072d4cbf060204571172d4ee7ae44d45e0563fe Mon Sep 17 00:00:00 2001 From: Massimiliano Angelino <38036163+massi-ang@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:20:59 +0200 Subject: [PATCH] Fix too long resource name (#124) --- lib/rag-engines/index.ts | 2 +- lib/sagemaker-model/deploy-custom-script-model.ts | 13 +++++++++++-- lib/sagemaker-model/hf-custom-script-model/index.ts | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/rag-engines/index.ts b/lib/rag-engines/index.ts index 247574157..9901e15c5 100644 --- a/lib/rag-engines/index.ts +++ b/lib/rag-engines/index.ts @@ -40,7 +40,7 @@ export class RagEngines extends Construct { const sageMakerRagModels = new SageMakerRagModels( this, - "SageMakerRagModels", + "SageMaker", { shared: props.shared, config: props.config, diff --git a/lib/sagemaker-model/deploy-custom-script-model.ts b/lib/sagemaker-model/deploy-custom-script-model.ts index 9c882be3e..22b2829aa 100644 --- a/lib/sagemaker-model/deploy-custom-script-model.ts +++ b/lib/sagemaker-model/deploy-custom-script-model.ts @@ -2,6 +2,7 @@ import { Construct } from "constructs"; import { HuggingFaceCustomScriptModel } from "./hf-custom-script-model"; import { SageMakerModelProps, ModelCustomScriptConfig } from "./types"; +import { createHash } from "crypto"; export function deployCustomScriptModel( scope: Construct, @@ -11,9 +12,17 @@ export function deployCustomScriptModel( const { vpc, region } = props; const { modelId, instanceType, codeFolder, container, env } = modelConfig; - const endpointName = (Array.isArray(modelId) ? modelId.join(",") : modelId) + const endpointName = ( + Array.isArray(modelId) + ? `Multi${createHash("md5") + .update(modelId.join(",")) + .digest("hex") + .toUpperCase() + .slice(-5)}` + : modelId + ) .replace(/[^a-zA-Z0-9]/g, "") - .slice(-20); + .slice(-10); const llmModel = new HuggingFaceCustomScriptModel(scope, endpointName, { vpc, region, diff --git a/lib/sagemaker-model/hf-custom-script-model/index.ts b/lib/sagemaker-model/hf-custom-script-model/index.ts index e7790467f..7dd8871e8 100644 --- a/lib/sagemaker-model/hf-custom-script-model/index.ts +++ b/lib/sagemaker-model/hf-custom-script-model/index.ts @@ -49,14 +49,14 @@ export class HuggingFaceCustomScriptModel extends Construct { ? props.modelId.join(",") : props.modelId; - const buildBucket = new s3.Bucket(this, "BuildBucket", { + const buildBucket = new s3.Bucket(this, "Bucket", { blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, removalPolicy: cdk.RemovalPolicy.DESTROY, autoDeleteObjects: true, }); // Upload build code to S3 - new s3deploy.BucketDeployment(this, "BuildScriptDeployment", { + new s3deploy.BucketDeployment(this, "Script", { sources: [s3deploy.Source.asset(path.join(__dirname, "./build-script"))], retainOnDelete: false, destinationBucket: buildBucket, @@ -66,7 +66,7 @@ export class HuggingFaceCustomScriptModel extends Construct { let deployment; // Upload model folder to S3 if (codeFolder) { - deployment = new s3deploy.BucketDeployment(this, "ModelCodeDeployment", { + deployment = new s3deploy.BucketDeployment(this, "ModelCode", { sources: [s3deploy.Source.asset(codeFolder)], retainOnDelete: false, destinationBucket: buildBucket,