Skip to content

Commit

Permalink
Fix too long resource name (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
massi-ang authored Oct 20, 2023
1 parent c67a335 commit 360c615
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/rag-engines/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class RagEngines extends Construct {

const sageMakerRagModels = new SageMakerRagModels(
this,
"SageMakerRagModels",
"SageMaker",
{
shared: props.shared,
config: props.config,
Expand Down
13 changes: 11 additions & 2 deletions lib/sagemaker-model/deploy-custom-script-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions lib/sagemaker-model/hf-custom-script-model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 360c615

Please sign in to comment.