Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SageMaker model package promote modules #61

Merged
merged 21 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- added batch inference project template to `sagemaker-templates-service-catalog` module
- added EFS removal policy to `mlflow-fargate` module
- added `mwaa` module with example dag which demonstrates the MLOps in Airflow
- added `sagemaker-model-event-bus` module.
- added `sagemaker-model-package-group` module.
- added `sagemaker-model-package-promote-pipeline` module.
- added `sagemaker-hugging-face-endpoint` module

### **Changed**
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ See deployment steps in the [Deployment Guide](DEPLOYMENT.md).

### SageMaker Modules

| Type | Description |
|---------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SageMaker Studio Module](modules/sagemaker/sagemaker-studio/README.md) | Provisions secure SageMaker Studio Domain environment, creates example User Profiles for Data Scientist and Lead Data Scientist linked to IAM Roles, and adds lifecycle config |
| [SageMaker Endpoint Module](modules/sagemaker/sagemaker-endpoint/README.md) | Creates SageMaker real-time inference endpoint for the specified model package or latest approved model from the model package group |
| Type | Description |
|---------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SageMaker Studio Module](modules/sagemaker/sagemaker-studio/README.md) | Provisions secure SageMaker Studio Domain environment, creates example User Profiles for Data Scientist and Lead Data Scientist linked to IAM Roles, and adds lifecycle config |
| [SageMaker Endpoint Module](modules/sagemaker/sagemaker-endpoint/README.md) | Creates SageMaker real-time inference endpoint for the specified model package or latest approved model from the model package group |
| [SageMaker Project Templates via Service Catalog Module](modules/sagemaker/sagemaker-templates-service-catalog/README.md) | Provisions SageMaker Project Templates for an organization. The templates are available using SageMaker Studio Classic or Service Catalog. Available templates:<br/> - [Train a model on Abalone dataset using XGBoost](modules/sagemaker/sagemaker-templates-service-catalog/README.md#train-a-model-on-abalone-dataset-with-xgboost-template)<br/>- [Perform batch inference](modules/sagemaker/sagemaker-templates-service-catalog/README.md#batch-inference-template)<br/>- [Multi-account model deployment](modules/sagemaker/sagemaker-templates-service-catalog/README.md#multi-account-model-deployment-template) |
| [SageMaker Notebook Instance Module](modules/sagemaker/sagemaker-notebook/README.md) | Creates secure SageMaker Notebook Instance for the Data Scientist, clones the source code to the workspace |
| [SageMaker Custom Kernel Module](modules/sagemaker/sagemaker-custom-kernel/README.md) | Builds custom kernel for SageMaker Studio from a Dockerfile |
| [SageMaker Notebook Instance Module](modules/sagemaker/sagemaker-notebook/README.md) | Creates secure SageMaker Notebook Instance for the Data Scientist, clones the source code to the workspace |
| [SageMaker Custom Kernel Module](modules/sagemaker/sagemaker-custom-kernel/README.md) | Builds custom kernel for SageMaker Studio from a Dockerfile |
| [SageMaker Model Package Group Module](modules/sagemaker/sagemaker-model-package-group/README.md) | Creates a SageMaker Model Package Group to register and version SageMaker Machine Learning (ML) models and setups an Amazon EventBridge Rule to send model package group state change events to an Amazon EventBridge Bus |
| [SageMaker Model Package Promote Pipeline Module](modules/sagemaker/sagemaker-model-package-promote-pipeline/README.md) | Deploy a Pipeline to promote SageMaker Model Packages in a multi-account setup. The pipeline can be triggered through an EventBridge rule in reaction of a SageMaker Model Package Group state event change (Approved/Rejected). Once the pipeline is triggered, it will promote the latest approved model package, if one is found. |


### Mlflow Modules
Expand All @@ -56,3 +58,9 @@ See deployment steps in the [Deployment Guide](DEPLOYMENT.md).
### Industry Data Framework (IDF) Modules

The modules in this repository are compatible with [Industry Data Framework (IDF) Modules](https://github.com/awslabs/idf-modules) and can be used together within the same deployment. Refer to `examples/manifests` for examples.

### Events Modules

| Type | Description |
|-------------------------------------------------------------------------|------------------------------------------------------------------------|
| [Event Bus Module](modules/examples/events/event-busREADME.md) | Creates an Amazon EventBridge Bus for cross-account events. |
13 changes: 13 additions & 0 deletions examples/manifests/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ groups:
path: examples/manifests/networking-modules.yaml
- name: sagemaker-endpoints
path: examples/manifests/sagemaker-endpoints-modules.yaml
- name: events
path: manifests/sagemaker-model-event-bus.yaml
- name: registry
path: manifests/sagemaker-model-package-group-modules.yaml
- name: promote-models
path: manifests/sagemaker-model-package-promote-pipeline-modules.yaml
targetAccountMappings:
- alias: primary
accountId:
Expand All @@ -17,3 +23,10 @@ targetAccountMappings:
regionMappings:
- region: us-east-1
default: true
- alias: tooling
accountId:
valueFrom:
envVariable: TOOLING_ACCOUNT
regionMappings:
- region: us-east-1
default: true
10 changes: 10 additions & 0 deletions examples/manifests/event-bus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: event-bus
path: modules/examples/events/event-bus
targetAccount: tooling
parameters:
- name: event_bus_name
value: mlops-bus
- name: source_accounts
value: '["123123123123"]' # Accounts that must have permissions to put events (source accounts)
- name: tags
value: '{"test": "test"}'
33 changes: 33 additions & 0 deletions examples/manifests/sagemaker-model-package-group-modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: source-model-package-group
path: modules/sagemaker/sagemaker-model-package-group
targetAccount: primary
parameters:
- name: model_package_group_name
value: mlops-test-model-group-source
- name: target_event_bus_arn
valueFrom:
moduleMetadata:
group: events
name: event-bus
key: EventBusArn
- name: target_account_ids
value: '["444333222555"]' # Accounts that must have read-only permissions on the model pkg group
- name: sagemaker_project_id
value: 123123
- name: sagemaker_project_name
value: test
---
name: target-model-package-group
path: modules/sagemaker/sagemaker-model-package-group
targetAccount: tooling
parameters:
- name: model_package_group_name
value: mlops-test-model-group-tooling
- name: model_package_group_description
value: Test model package group module - Target
- name: target_account_ids
value: '["111222333444"]' # Accounts that must have read-only permissions on the model pkg group
- name: sagemaker_project_id
value: 123123
- name: sagemaker_project_name
value: test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: rappi-b2
path: modules/sagemaker/sagemaker-model-package-promote-pipeline
targetAccount: tooling
parameters:
- name: source_model_package_group_arn
valueFrom:
moduleMetadata:
group: registry
name: source-model-package-group
key: SagemakerModelPackageGroupArn
- name: target_bucket_name
value: my-bucket-name
- name: event_bus_name
valueFrom:
moduleMetadata:
group: events
name: event-bus
key: EventBusName
- name: target_model_package_group_name
valueFrom:
moduleMetadata:
group: registry
name: target-model-package-group
key: SagemakerModelPackageGroupName
51 changes: 51 additions & 0 deletions modules/examples/events/event-bus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Event Bus

## Description

This module creates an Amazon EventBridge Bus for cross-account events.

### Architecture

![Event Bus Architecture](docs/_static/architecture.drawio.png "Event Bus Architecture")

## Inputs/Outputs

### Input Paramenters

#### Required

- `event_bus_name`: EventBridge Bus name.

#### Optional

- `source_accounts`: A list of account ids which shall have write access to the event bridge bus. Defaults None.
- `tags`: A dictionary of tags. Defaults None.

### Sample manifest declaration

```yaml
name: event-bus
path: modules/examples/events/event-bus
targetAccount: primary
parameters:
- name: event_bus_name
value: mlops-bus
- name: source_accounts
value: '["111222333444", "555666777888"]'
- name: tags
value: '{"key": "value"}'
```

### Module Metadata Outputs

- `EventBusArn`: the EventBridge bus ARN.
- `EventBusName`: the EventBridge bus name.

#### Output Example

```json
{
"EventBusArn": "arn:aws:events:xx-xxxx-x:xxxxxxxxxx:event-bus/mlops-bus",
"EventBusName": "mlops-bus",
}
```
26 changes: 26 additions & 0 deletions modules/examples/events/event-bus/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""Create a Event Bus Stack."""

import aws_cdk as cdk

from event_bus.settings import ApplicationSettings
from event_bus.stack import EventBusStack

# Load application settings from env vars.
app_settings = ApplicationSettings()

env = cdk.Environment(
account=app_settings.default.account,
region=app_settings.default.region,
)

app = cdk.App()

stack = EventBusStack(
scope=app,
construct_id=app_settings.settings.app_prefix,
env=env,
**app_settings.parameters.model_dump(),
)

app.synth()
26 changes: 26 additions & 0 deletions modules/examples/events/event-bus/deployspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
publishGenericEnvVariables: true
deploy:
phases:
install:
commands:
- env
# Install whatever additional build libraries
- npm install -g [email protected]
- pip install -r requirements.txt
build:
commands:
# execute the CDK
- cdk deploy --require-approval never --progress events --app "python app.py" --outputs-file ./cdk-exports.json
# Export metadata
- seedfarmer metadata convert -f cdk-exports.json || true
destroy:
phases:
install:
commands:
# Install whatever additional build libraries
- npm install -g [email protected]
- pip install -r requirements.txt
build:
commands:
# execute the CDK
- cdk destroy --force --app "python app.py"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="Electron" modified="2024-03-23T13:09:48.468Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.2.3 Chrome/102.0.5005.167 Electron/19.0.11 Safari/537.36" etag="0olYNljB-bfJTNhMpkqE" version="20.2.3" type="device"><diagram id="nOkpBZcZqbjnXywVXBLF" name="Page-1">7Vpbc9o4FP41PIbxHfKITUi3Tbtp2dlO9oVRbGHcCIvKMpf++pVsCWNJBHZC07CFZAbr+Ojio+9837Fxx43m61sCFrOPOIGo41jJuuMOO45j216ffXHLprZ4Pbc2pCRLhFNjGGc/oDBawlpmC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hGdeAZAN5xmrj2er66BKk53Wv+y082tdW19r52J6GT595uIayxPtJ8hhoEP0iA+ZY9xhl8eb1gTqy+rbOomcPVIa/eVYUbIVFw4qtkvf0jNj3uvw2toFcG5C2Xha7drd3rSPQO0FdvLaG9/Ok9zn6B7yL0J8Pn9LobwNJjiX+lNtXufjLLezlFvY3uIW1vYO3sHbPcC+1fWp1+lS19hU0l1LmdKWMoZLerqINR0uTkaNLnGep+GiIBn4Loa6OUM8A0FNIibGY6R0vJfrDl4uUXKTkDUvJgdLwv0nJ9hncq2iJMVdt56IlZ6wlh+5U9tLzuWjJ9fFa8umiJRct+W21xOn9ei3Rf1u7aMn/W0uuz0lL5HPeHSTCJIVyb/hvSTjFOUA3jTVkTJInW7g0PneYA6Haq2+Q0o3YcVBS3IZDPSdMtHditGcS8gn5wQSjgKRQ9N3/i4e+LQQiQBm9tmY1hbnqOiAEbHYchJo2I99zQ7PbrttmJFd9eeaAv2SwZovrFTQbvr2UF2DAP3cMOG8aA8pPf/Kds70YUP2D18BAcD4YePYB4BvFgJLXsuA4mgf8F2GANZsXAGv35jVK9+Zf</diagram></mxfile>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading