1. circleci/aws-sagemaker@1.0.5

circleci/aws-sagemaker@1.0.5

Certified
Sections
Orb for deploying models to Amazon SageMaker and tracking releases in CircleCI. (OPEN PREVIEW - send feedback at sagemaker-integration-feedback@circleci.com)
Created: November 16, 2023Version Published: May 1, 2024Releases: 19
Org Usage:
< 25

Orb Quick Start Guide

Use CircleCI version 2.1 at the top of your .circleci/config.yml file.

1 version: 2.1

Add the orbs stanza below your version, invoking the orb:

1 2 orbs: aws-sagemaker: circleci/aws-sagemaker@1.0.5

Use aws-sagemaker elements in your existing workflows and jobs.

Usage Examples

deploy_model

This example defines a CircleCI workflow that uses the aws-sagemaker orb to: - Create a SageMaker model - Create an endpoint configuration for the model - Deploy the model to an endpoint It shows a typical machine learning workflow using SageMaker with model releases being tracked on CircleCI.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 version: '2.1' orbs: aws-sagemaker: circleci/aws-sagemaker@1.0 workflows: ai-workflow: jobs: - aws-sagemaker/create_model: bucket: replace_with_s3_bucket_name model_name: replace_with_model_name name: create-model pipeline_id: << pipeline.id >> region_name: replace_with_region_name - aws-sagemaker/create_endpoint_configuration: bucket: replace_with_s3_bucket_name model_name: replace_with_model_name name: create-endpoint-configuration pipeline_id: << pipeline.id >> region_name: replace_with_region_name requires: - create-model - aws-sagemaker/deploy_endpoint: bucket: replace_with_s3_bucket_name model_desc: replace_with_description model_name: replace_with_model_name name: deploy-endpoint pipeline_id: <<pipeline.id>> project_id: replace_with_project_id region_name: replace_with_region_name requires: - create-endpoint-configuration

deploy_model_with_endpoint_config_name

Deploys a model to SageMaker with an existing endpoint configuration.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 version: '2.1' orbs: aws-sagemaker: circleci/aws-sagemaker@1.0 workflows: ai-workflow: jobs: - aws-sagemaker/deploy_endpoint: bucket: replace_with_s3_bucket_name endpoint_config_name: replace_with_existing_endpoint_config_name endpoint_name: replace_with_endpoint_name model_desc: replace_with_description model_name: replace_with_model_name name: deploy-endpoint pipeline_id: <<pipeline.id>> project_id: replace_with_project_id region_name: replace_with_region_name

Jobs

create_endpoint_configuration

This job creates an create an endpoint configuration.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
bucket
S3 bucket for the model
Yes
-
string
circle_pipeline_id
CircleCI Pipeline ID
Yes
-
string
circle_project_id
CircleCI project ID
Yes
-
string
endpoint_instance_count
Number of instances to run endpoint inference
No
1
integer
endpoint_instance_type
EC2 instance type to run endpoint inference
No
ml.t2.medium
string
model_name
Model name
Yes
-
string
region_name
AWS region name
Yes
-
string

create_model

This job creates sagemaker model given a model package available in registry.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
bucket
S3 bucket for the model
Yes
-
string
circle_pipeline_id
CircleCI Pipeline ID
Yes
-
string
model_name
Model name
Yes
-
string
region_name
AWS region name
Yes
-
string

deploy_endpoint

This job deploys inference endpoint by create or update

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
bucket
S3 bucket for the model
Yes
-
string
circle_pipeline_id
CircleCI Pipeline ID
Yes
-
string
circle_project_id
CircleCI project ID
Yes
-
string
enable_restore_version
Enable restoring releases on circleci
No
'true'
string
enable_scaling_component
Enable scaling release components on circleci
No
'true'
string
endpoint_config_name
Existing endpoint config name
No
''
string
endpoint_name
Existing endpoint name
No
''
string
model_desc
sagemaker model desription
Yes
-
string
model_name
Model name
Yes
-
string
region_name
AWS region name
Yes
-
string

Commands

create_endpoint_configuration

This command creates an create an endpoint configuration.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
bucket
S3 bucket for the model
Yes
-
string
circle_pipeline_id
CircleCI pipeline ID
Yes
-
string
circle_project_id
CircleCI project ID
Yes
-
string
endpoint_instance_count
Number of instances to run endpoint inference
No
1
integer
endpoint_instance_type
EC2 instance type to run endpoint inference
No
ml.t2.medium
string
model_name
Model name
Yes
-
string
region_name
AWS region name
No
us-east-1
string

create_model

This command creates a sagemaker model with latest model package.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
bucket
S3 bucket for the model
Yes
-
string
circle_pipeline_id
CircleCI pipeline ID
Yes
-
string
model_name
Model name
Yes
-
string
region_name
AWS region name
No
us-east-1
string

deploy_endpoint

This command deploys inference endpoint by create or update

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
bucket
S3 bucket for the model
Yes
-
string
circle_pipeline_id
CircleCI pipeline ID
Yes
-
string
circle_project_id
CircleCI project ID
Yes
-
string
enable_restore_version
Enable restoring releases on circleci
No
'true'
string
enable_scaling_component
Enable scaling release components on circleci
No
'true'
string
endpoint_config_name
Existing endpoint config name
No
''
string
endpoint_name
Existing endpoint name
No
''
string
model_desc
sagemaker model desription
Yes
-
string
model_name
Model name
Yes
-
string
region_name
AWS region name
Yes
-
string

setup

This command downloads the sagemaker cli binary.

Show command Source

Orb Source

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 # This code is licensed from CircleCI to the user under the MIT license. # See here for details: https://circleci.com/developer/ja/orbs/licensing version: 2.1 description: | Orb for deploying models to Amazon SageMaker and tracking releases in CircleCI. (OPEN PREVIEW - send feedback at sagemaker-integration-feedback@circleci.com) display: home_url: https://github.com/CircleCI-Public/aws-sagemaker-orb source_url: https://github.com/CircleCI-Public/aws-sagemaker-orb commands: create_endpoint_configuration: description: | This command creates an create an endpoint configuration. parameters: bucket: description: S3 bucket for the model type: string circle_pipeline_id: description: CircleCI pipeline ID type: string circle_project_id: description: CircleCI project ID type: string endpoint_instance_count: default: 1 description: Number of instances to run endpoint inference type: integer endpoint_instance_type: default: ml.t2.medium description: EC2 instance type to run endpoint inference type: string model_name: description: Model name type: string region_name: default: us-east-1 description: AWS region name type: string steps: - run: command: | cci-sagemaker sagemaker create-endpoint-configuration description: create an endpoint configuration environment: CIRCLE_PIPELINE_ID: << parameters.circle_pipeline_id >> CIRCLE_PROJECT_ID: << parameters.circle_project_id >> ENDPOINT_INSTANCE_COUNT: << parameters.endpoint_instance_count >> ENDPOINT_INSTANCE_TYPE: << parameters.endpoint_instance_type >> MODEL_NAME: << parameters.model_name >> REGION_NAME: << parameters.region_name >> S3_BUCKET_NAME: << parameters.bucket >> name: Create Endpoint Configuration create_model: description: | This command creates a sagemaker model with latest model package. parameters: bucket: description: S3 bucket for the model type: string circle_pipeline_id: description: CircleCI pipeline ID type: string model_name: description: Model name type: string region_name: default: us-east-1 description: AWS region name type: string steps: - run: command: | cci-sagemaker sagemaker create-model description: create a model for inference environment: CIRCLE_PIPELINE_ID: << parameters.circle_pipeline_id >> MODEL_NAME: << parameters.model_name >> REGION_NAME: << parameters.region_name >> S3_BUCKET_NAME: << parameters.bucket >> name: Create a model deploy_endpoint: description: | This command deploys inference endpoint by create or update parameters: bucket: description: S3 bucket for the model type: string circle_pipeline_id: description: CircleCI pipeline ID type: string circle_project_id: description: CircleCI project ID type: string enable_restore_version: default: "true" description: Enable restoring releases on circleci type: string enable_scaling_component: default: "true" description: Enable scaling release components on circleci type: string endpoint_config_name: default: "" description: Existing endpoint config name type: string endpoint_name: default: "" description: Existing endpoint name type: string model_desc: description: sagemaker model desription type: string model_name: description: Model name type: string region_name: description: AWS region name type: string steps: - run: command: | cci-sagemaker sagemaker upsert-endpoint description: create or update endpoint with new model environment: CIRCLE_PIPELINE_ID: << parameters.circle_pipeline_id >> CIRCLE_PROJECT_ID: << parameters.circle_project_id >> ENDPOINT_CONFIGURATION_NAME: << parameters.endpoint_config_name >> ENDPOINT_NAME: << parameters.endpoint_name >> MODEL_DESC: << parameters.model_desc >> MODEL_NAME: << parameters.model_name >> REGION_NAME: << parameters.region_name >> RESTORE_VERSION_ENABLED: << parameters.enable_restore_version >> S3_BUCKET_NAME: << parameters.bucket >> SCALE_COMPONENT_ENABLED: << parameters.enable_scaling_component >> name: Create or Update endpoint setup: description: | This command downloads the sagemaker cli binary. steps: - run: command: | #!/bin/sh # Hi! Based off the slack-orb-go main.sh. If you plan to have osx & windows # support go look at that file and bring it back in. # Determine the http client to use # Returns 1 if no HTTP client is found determine_http_client() { if command -v curl >/dev/null 2>&1; then HTTP_CLIENT=curl elif command -v wget >/dev/null 2>&1; then HTTP_CLIENT=wget else return 1 fi } # Download a binary file # $1: The path to save the file to # $2: The URL to download the file from # $3: The HTTP client to use (curl or wget) download_binary() { if [ "$3" = "curl" ]; then set -x curl --fail --retry 3 -L -o "$1" "$2" set +x elif [ "$3" = "wget" ]; then set -x wget --tries=3 --timeout=10 --quiet -O "$1" "$2" set +x else return 1 fi } detect_os() { detected_platform="$(uname -s | tr '[:upper:]' '[:lower:]')" case "$detected_platform" in linux*) PLATFORM=linux ;; # darwin*) PLATFORM=darwin ;; # msys* | cygwin*) PLATFORM=windows ;; *) return 1 ;; esac } detect_arch() { detected_arch="$(uname -m)" case "$detected_arch" in x86_64 | amd64) ARCH=amd64 ;; i386 | i486 | i586 | i686) ARCH=386 ;; arm64 | aarch64) ARCH=arm64 ;; arm*) ARCH=arm ;; *) return 1 ;; esac } # Confirm we have unzip available # Returns 1 if unzip not found detect_unzip() { if command -v unzip >/dev/null 2>&1; then return 0 fi return 1 } # Print a warning message # $1: The warning message to print print_warn() { yellow="\033[1;33m" normal="\033[0m" printf "${yellow}%s${normal}\n" "$1" } # Print a success message # $1: The success message to print print_success() { green="\033[0;32m" normal="\033[0m" printf "${green}%s${normal}\n" "$1" } # Print an error message # $1: The error message to print print_error() { red="\033[0;31m" normal="\033[0m" printf "${red}%s${normal}\n" "$1" } print_warn "This is an experimental version of the Sagemaker Orb." print_warn "Thank you for trying it out and please provide feedback to us at https://github.com/CircleCI-Public/sagemaker-orb-go/issues" if ! detect_os; then print_error "Unsupported operating system: $(uname -s)." exit 1 fi printf '%s\n' "Operating system: $PLATFORM." if ! detect_arch; then print_error "Unsupported architecture: $(uname -m)." exit 1 fi printf '%s\n' "Architecture: $ARCH." if ! detect_unzip; then print_error "Unzip is required to download the Sagemaker Orb binary." exit 1 fi base_dir="$(printf "%s" "$CIRCLE_WORKING_DIRECTORY" | sed "s|~|$HOME|")" orb_bin_dir="${base_dir}/.circleci/orbs/circleci/sagemaker/${PLATFORM}/${ARCH}" org="circleci" repo_name="cci-sagemaker" # binary="${orb_bin_dir}/${repo_name}" # TODO: Make the version configurable via parameter # Don't forget the v! binary_version="v0.0.14" basic_name="cci-sagemaker" binary_name="${basic_name}-${binary_version}-${PLATFORM}-${ARCH}" binary_zip="${orb_bin_dir}/${binary_name}.zip" # Where to move the binary path_destination="$HOME/bin" # Slack orb seems to put this outside the script as a parameter # https://github.com/CircleCI-Public/slack-orb-go/blob/8c4e86c9a787c240138244610aada066059b5b46/src/commands/notify.yml#L80 # TODO: keep support for this? Or will people not bother? They would have to do to the packagecloud URL and find it # when we parametize the version, we should support this as well input_sha256="" if [ ! -f "$binary_zip" ]; then mkdir -p "$orb_bin_dir" if ! determine_http_client; then printf '%s\n' "cURL or wget is required to download the Sagemaker Orb binary." printf '%s\n' "Please install cURL or wget and try again." exit 1 fi printf '%s\n' "HTTP client: $HTTP_CLIENT." binary_url="https://packagecloud.io/${org}/${repo_name}/packages/anyfile/${binary_name}.zip/download?distro_version_id=230" printf '%s\n' "Release URL: $binary_url." if ! download_binary "$binary_zip" "$binary_url" "$HTTP_CLIENT"; then printf '%s\n' "Failed to download $repo_name binary from Packagecloud." exit 1 fi printf '%s\n' "Downloaded $repo_name zip to $orb_bin_dir" else printf '%s\n' "Skipping zip download since it already exists at $binary_zip." fi # Validate binary ## This validates, even if the binary already existed before. ## This can help with cache integrity but was also a convenience for testing where the binary will never be downloaded. if [ -n "$input_sha256" ]; then actual_sha256="" actual_sha256=$(sha256sum "$binary_zip" | cut -d' ' -f1) if [ "$actual_sha256" != "$input_sha256" ]; then print_error "SHA256 checksum does not match. Expected $input_sha256 but got $actual_sha256" exit 1 else print_success "SHA256 checksum matches. Binary is valid." fi else print_warn "SHA256 checksum not provided. Skipping validation." fi # Unzip binary # Please someone explain this to me - only works if I UNZIP to the $orb_bin_dir # Can't unzip to any other dest. then it fails. bad. wtf. If you can explain it, please let me know! Really. printf '%s\n' "Unzip ${binary_zip}..." if ! unzip -q "${binary_zip}" -d "$orb_bin_dir"; then print_error "Failed to unzip $binary_zip." exit 1 fi printf '%s\n' "Making ${orb_bin_dir}/${binary_name} binary executable..." if ! chmod +x "${orb_bin_dir}/${binary_name}"; then print_error "Failed to make ${orb_bin_dir}/${binary_name} binary executable." exit 1 fi printf '%s\n' "Moving $binary_name to PATH and renaming to ${basic_name}..." mkdir -p "$path_destination" # shellcheck disable=SC2016 # shellcheck disable=SC2086 echo 'export PATH='${path_destination}':$PATH' >> "$BASH_ENV" # shellcheck disable=SC1090 # shellcheck disable=SC3046 source "$BASH_ENV" if ! mv "$orb_bin_dir/$binary_name" "${path_destination}/${basic_name}"; then print_error "Failed to move $orb_bin_dir/$binary_name binary executable." exit 1 fi print_success "Successfully installed $basic_name." exit 0 name: Download cci-sagemaker binary jobs: create_endpoint_configuration: description: | This job creates an create an endpoint configuration. docker: - image: cimg/base:current-22.04 parameters: bucket: description: S3 bucket for the model type: string circle_pipeline_id: description: CircleCI Pipeline ID type: string circle_project_id: description: CircleCI project ID type: string endpoint_instance_count: default: 1 description: Number of instances to run endpoint inference type: integer endpoint_instance_type: default: ml.t2.medium description: EC2 instance type to run endpoint inference type: string model_name: description: Model name type: string region_name: description: AWS region name type: string steps: - setup - create_endpoint_configuration: bucket: << parameters.bucket >> circle_pipeline_id: << parameters.circle_pipeline_id >> circle_project_id: << parameters.circle_project_id >> endpoint_instance_count: << parameters.endpoint_instance_count >> endpoint_instance_type: << parameters.endpoint_instance_type >> model_name: << parameters.model_name >> region_name: << parameters.region_name >> create_model: description: | This job creates sagemaker model given a model package available in registry. docker: - image: cimg/base:current-22.04 parameters: bucket: description: S3 bucket for the model type: string circle_pipeline_id: description: CircleCI Pipeline ID type: string model_name: description: Model name type: string region_name: description: AWS region name type: string steps: - setup - create_model: bucket: << parameters.bucket >> circle_pipeline_id: << parameters.circle_pipeline_id >> model_name: << parameters.model_name >> region_name: << parameters.region_name >> deploy_endpoint: description: | This job deploys inference endpoint by create or update docker: - image: cimg/base:current-22.04 parameters: bucket: description: S3 bucket for the model type: string circle_pipeline_id: description: CircleCI Pipeline ID type: string circle_project_id: description: CircleCI project ID type: string enable_restore_version: default: "true" description: Enable restoring releases on circleci type: string enable_scaling_component: default: "true" description: Enable scaling release components on circleci type: string endpoint_config_name: default: "" description: Existing endpoint config name type: string endpoint_name: default: "" description: Existing endpoint name type: string model_desc: description: sagemaker model desription type: string model_name: description: Model name type: string region_name: description: AWS region name type: string steps: - setup - deploy_endpoint: bucket: << parameters.bucket >> circle_pipeline_id: << parameters.circle_pipeline_id >> circle_project_id: << parameters.circle_project_id >> enable_restore_version: << parameters.enable_restore_version>> enable_scaling_component: << parameters.enable_scaling_component>> endpoint_config_name: << parameters.endpoint_config_name >> endpoint_name: << parameters.endpoint_name >> model_desc: << parameters.model_desc >> model_name: << parameters.model_name >> region_name: << parameters.region_name >> examples: deploy_model: description: | This example defines a CircleCI workflow that uses the aws-sagemaker orb to: - Create a SageMaker model - Create an endpoint configuration for the model - Deploy the model to an endpoint It shows a typical machine learning workflow using SageMaker with model releases being tracked on CircleCI. usage: version: "2.1" orbs: aws-sagemaker: circleci/aws-sagemaker@1.0 workflows: ai-workflow: jobs: - aws-sagemaker/create_model: bucket: replace_with_s3_bucket_name model_name: replace_with_model_name name: create-model pipeline_id: << pipeline.id >> region_name: replace_with_region_name - aws-sagemaker/create_endpoint_configuration: bucket: replace_with_s3_bucket_name model_name: replace_with_model_name name: create-endpoint-configuration pipeline_id: << pipeline.id >> region_name: replace_with_region_name requires: - create-model - aws-sagemaker/deploy_endpoint: bucket: replace_with_s3_bucket_name model_desc: replace_with_description model_name: replace_with_model_name name: deploy-endpoint pipeline_id: <<pipeline.id>> project_id: replace_with_project_id region_name: replace_with_region_name requires: - create-endpoint-configuration deploy_model_with_endpoint_config_name: description: | Deploys a model to SageMaker with an existing endpoint configuration. usage: version: "2.1" orbs: aws-sagemaker: circleci/aws-sagemaker@1.0 workflows: ai-workflow: jobs: - aws-sagemaker/deploy_endpoint: bucket: replace_with_s3_bucket_name endpoint_config_name: replace_with_existing_endpoint_config_name endpoint_name: replace_with_endpoint_name model_desc: replace_with_description model_name: replace_with_model_name name: deploy-endpoint pipeline_id: <<pipeline.id>> project_id: replace_with_project_id region_name: replace_with_region_name
開発者向け最新情報
ビルド最適化のためのヒントを手に入れましょう。
または、リサーチパネルに参加して フィードバックをお寄せください。
このフォームを送信することで、当社の利用規約およびプライバシーポリシーに同意したものと見なされます。