Skip to content

Commit

Permalink
Limit bucket name length in templates (awslabs#224)
Browse files Browse the repository at this point in the history
* Limit name length in model deploy template

* Updated readme

* Removed sagemaker project ID from bucket names

* Increase timeout on finetune template

* Reduced bucket name length for batch inference module

* Updating changelog
  • Loading branch information
EthanBunce authored and mahesh-balumuri committed Aug 25, 2024
1 parent cce81ee commit ec3ca44
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### **Changed**
- Added accelerate as extra for transformers in finetune llm template
- Limited bucket name length in templates to avoid pipeline failures when using long project names
- Increased timeout on finetune_llm_evaluation project from 1 hour (default) to 4 hours

## v1.4.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(
pipeline_artifact_bucket = s3.Bucket(
self,
"Pipeline Artifacts Bucket",
bucket_name=f"mlops-{sagemaker_project_name}-{sagemaker_project_id}-{Aws.ACCOUNT_ID}",
bucket_name=f"mlops-{sagemaker_project_name}-{Aws.ACCOUNT_ID}",
encryption_key=kms_key_artifact,
versioned=True,
enforce_ssl=True, # Blocks insecure requests to the bucket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def __init__(
project_name=f"{project_name}-{construct_id}",
role=codebuild_role, # figure out what actually this role would need
build_spec=codebuild.BuildSpec.from_source_filename("buildspec.yml"),
timeout=aws_cdk.Duration.hours(4),
environment=codebuild.BuildEnvironment(
build_image=codebuild.LinuxBuildImage.STANDARD_5_0,
environment_variables={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(
model_bucket = s3.Bucket(
self,
"S3 Artifact",
bucket_name=f"mlops-{sagemaker_project_name}-{sagemaker_project_id}-{Aws.ACCOUNT_ID}",
bucket_name=f"mlops-{sagemaker_project_name}-{Aws.ACCOUNT_ID}",
encryption_key=kms_key,
versioned=True,
removal_policy=RemovalPolicy.DESTROY,
Expand Down Expand Up @@ -230,7 +230,7 @@ def __init__(
pipeline_artifact_bucket = s3.Bucket(
self,
"Pipeline Bucket",
bucket_name=f"pipeline-{sagemaker_project_name}-{sagemaker_project_id}-{Aws.ACCOUNT_ID}",
bucket_name=f"pipeline-{sagemaker_project_name}-{Aws.ACCOUNT_ID}",
encryption_key=kms_key,
versioned=True,
removal_policy=RemovalPolicy.DESTROY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import json
import os

MAX_NAME_LENGTH = 63

MODEL_BUCKET_ARN = os.environ["MODEL_BUCKET_ARN"]
MODEL_PACKAGE_GROUP_NAME = os.getenv("MODEL_PACKAGE_GROUP_NAME", "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
DOMAIN_ID,
ECR_REPO_ARN,
ENABLE_NETWORK_ISOLATION,
MAX_NAME_LENGTH,
MODEL_BUCKET_ARN,
MODEL_PACKAGE_GROUP_NAME,
PROJECT_ID,
Expand Down Expand Up @@ -160,7 +161,8 @@ def __init__(
latest_approved_model_package = get_approved_package()

# Sagemaker Model
model_name = f"{MODEL_PACKAGE_GROUP_NAME}-{id}-{timestamp}"
model_name = f"-{id}-{timestamp}"
model_name = MODEL_PACKAGE_GROUP_NAME[: MAX_NAME_LENGTH - len(model_name)] + model_name

vpc_config = None
if subnet_ids:
Expand All @@ -187,7 +189,10 @@ def __init__(
)

# Sagemaker Endpoint Config
endpoint_config_name = f"{MODEL_PACKAGE_GROUP_NAME}-{id}-ec-{timestamp}"
endpoint_config_name = f"-{id}-ec-{timestamp}"
endpoint_config_name = (
MODEL_PACKAGE_GROUP_NAME[: MAX_NAME_LENGTH - len(endpoint_config_name)] + endpoint_config_name
)

endpoint_config_production_variant = EndpointConfigProductionVariant()

Expand Down Expand Up @@ -226,7 +231,8 @@ def __init__(
endpoint_config.add_dependency(model)

# Sagemaker Endpoint
endpoint_name = f"{MODEL_PACKAGE_GROUP_NAME}-{id}-endpoint"
endpoint_name = f"-{id}-endpoint"
endpoint_name = MODEL_PACKAGE_GROUP_NAME[: MAX_NAME_LENGTH - len(endpoint_name)] + endpoint_name

endpoint = sagemaker.CfnEndpoint(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(
model_bucket = s3.Bucket(
self,
"S3 Artifact",
bucket_name=f"mlops-{sagemaker_project_name}-{sagemaker_project_id}-{Aws.ACCOUNT_ID}",
bucket_name=f"mlops-{sagemaker_project_name}-{Aws.ACCOUNT_ID}",
encryption_key=kms_key,
versioned=True,
removal_policy=RemovalPolicy.DESTROY,
Expand Down Expand Up @@ -247,7 +247,7 @@ def __init__(
pipeline_artifact_bucket = s3.Bucket(
self,
"Pipeline Bucket",
bucket_name=f"pipeline-{sagemaker_project_name}-{sagemaker_project_id}-{Aws.ACCOUNT_ID}",
bucket_name=f"pipeline-{sagemaker_project_name}-{Aws.ACCOUNT_ID}",
encryption_key=kms_key,
versioned=True,
removal_policy=RemovalPolicy.DESTROY,
Expand Down

0 comments on commit ec3ca44

Please sign in to comment.