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 9 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 @@ -16,6 +16,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.

### **Changed**

Expand Down
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/sagemaker-model-event-bus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: event-bus
path: modules/sagemaker/sagemaker-model-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
53 changes: 53 additions & 0 deletions modules/sagemaker/sagemaker-model-event-bus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SageMaker Model Event Bus

## Description

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

### Architecture

![SageMaker Model Event Bus Architecture](docs/_static/architecture.drawio.png "SageMaker Model 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: sagemaker-model-event-bus
path: modules/sagemaker/sagemaker-model-event-bus/sagemaker_model_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/sagemaker/sagemaker-model-event-bus/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""Create a Sagemaker Model Event Bus Stack."""

import aws_cdk as cdk

from sagemaker_model_event_bus.settings import ApplicationSettings
from sagemaker_model_event_bus.stack import SagemakerModelEventBusStack

# 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 = SagemakerModelEventBusStack(
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/sagemaker/sagemaker-model-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/oDBawlpmCSxajhRjRLNF2xjjPIcxbdkAIXjVdpti1J51AVKoGcYxQLr1a5bQWW3t+1ZjfwezdCZnti1xZg6kszAUM5Dg1Y7Jvem4EcGY1kfzdQQRD56MS91vtOfsdmEE5vSYDt8+p/H9YDkduGH/LkjourQersQoS4BKccGDr2NmGMQxLtm49crpRoZjgbOcViH1Q/bPZoysjs/ORLzVdXzFoLZ7bYOtt/gYbYPa7rUNtjq8rcxvqwvcMWit1vCWMr+1s0D274a4pCjLYbQFn8WMKQFJxjYlwggTZstxzqIXzugcsZbNDlezjMLxAsQ8qiuWOMw2xTkV8Lcd2RaB56MygFPA5iJijGonILlZwnpDah+EwKLIHre9CIxLUmRL+AUW9eDcyqC44MfzdcqztgtWhddNCS4X1fL/YHMZz07Y4SRGuEwmAFE+ECX4CcoL7Tgu+xtx+IXTDCElAEtIaMYya4CylI9PMZ8OiBaC02pEFpUsT++q1tC1RCRMUySgmMFEXJKeDRLabFa43jGJ7LiFeA4p2TAXcdaVSS2oSjZXTd47MrtnOznvygwHgmvS7dBNOrIDkZF7snOJ4M37+O774Gmw/vihWP91i65cLTu1hDTEWduUaOgEQbB3B1SkKfH2B0HUD7Yh1uLZjvp+ltkbd0cJu6+F3Q4MYXds/yeF3TOEPUACnXkr/sH3kvN3yEJCrwSUB8xDoLlxYEcp/67yNWRSx2THsaoW+w7LQk7BVlzPUvtrG148QRrPxFYZ6dhIySZaNlKzTs8tt4owDTOoRpOtpxtt3U1yrG402UyCova2Db1tpfd+Ot9HPyrNs3OjkTfqhzvnhhkjYJpVdJpjwvHcYkbWJ4xs1w9MaTutPirRyRy+A48Q3eMiE8PPsyRBJprdnlCYdkePDmkPKBZ1PKbZmi/ELCAEFrgkMazlg0lPYRISyCH/WCeAGyLlKkid34oMOL+UfRzfQD4n4J74A3g/nz2FydPD6mMwgJMp+mEoyCRHPHKOeI4MXoReoR0qOC2r7w01cArno3D5iCnF84PyH0NezbwQlmpNZO+D6g4IJwmcghLRSWWbsChPJJD5iJBkbGMhGdeAZAN5xmrj2er66BKk53Wv+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.
41 changes: 41 additions & 0 deletions modules/sagemaker/sagemaker-model-event-bus/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[tool.ruff]
exclude = [
".eggs",
".git",
".hg",
".mypy_cache",
".ruff_cache",
".tox",
".venv",
"_build",
"buck-out",
"build",
"dist",
"codeseeder",
]
line-length = 120
target-version = "py38"

[tool.ruff.lint]
select = ["F", "I", "E", "W"]
fixable = ["ALL"]

[tool.mypy]
python_version = "3.8"
strict = true
ignore_missing_imports = true
disallow_untyped_decorators = false
exclude = "codeseeder.out/|example/|tests/|.venv"
warn_unused_ignores = false

[tool.pytest.ini_options]
addopts = "-v --cov=. --cov-report term"
pythonpath = [
"."
]

[tool.coverage.run]
omit = ["tests/*"]

[tool.coverage.report]
fail_under = 80
6 changes: 6 additions & 0 deletions modules/sagemaker/sagemaker-model-event-bus/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
aws-cdk-lib~=2.126.0
cdk-nag~=2.28.27
constructs~=10.3.0
pydantic~=2.5.3
pydantic-settings~=2.0.3
configobj~=5.0.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Defines the stack settings."""
from abc import ABC
from typing import Dict, List, Optional

from pydantic import Field, computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict


class CdkBaseSettings(BaseSettings, ABC):
"""Defines common configuration for settings."""

model_config = SettingsConfigDict(
case_sensitive=False,
env_nested_delimiter="__",
protected_namespaces=(),
extra="ignore",
populate_by_name=True,
)


class SeedFarmerParameters(CdkBaseSettings):
"""Seedfarmer Parameters.

These parameters are required for the module stack.
"""

model_config = SettingsConfigDict(env_prefix="SEEDFARMER_PARAMETER_")

event_bus_name: str

source_accounts: Optional[List[str]] = Field(default=None)
tags: Optional[Dict[str, str]] = Field(default=None)
lccasagrande marked this conversation as resolved.
Show resolved Hide resolved


class SeedFarmerSettings(CdkBaseSettings):
"""Seedfarmer Settings.

These parameters comes from seedfarmer by default.
"""

model_config = SettingsConfigDict(env_prefix="SEEDFARMER_")

project_name: str = Field(default="")
deployment_name: str = Field(default="")
module_name: str = Field(default="")

@computed_field # type: ignore
@property
def app_prefix(self) -> str:
"""Application prefix."""
prefix = "-".join([self.project_name, self.deployment_name, self.module_name])
return prefix


class CdkDefaultSettings(CdkBaseSettings):
"""CDK Default Settings.

These parameters comes from AWS CDK by default.
"""

model_config = SettingsConfigDict(env_prefix="CDK_DEFAULT_")

account: str
region: str


class ApplicationSettings(CdkBaseSettings):
"""Application settings."""

settings: SeedFarmerSettings = Field(default_factory=SeedFarmerSettings)
parameters: SeedFarmerParameters = Field(default_factory=SeedFarmerParameters)
default: CdkDefaultSettings = Field(default_factory=CdkDefaultSettings)
Loading