# Deploy Nova LoRA to Bedrock (PySDK BedrockModelBuilder)

## Scenario

- **Model Type**: Nova
- **Fine-tuning Method**: LoRA
- **Deployment Target**: Bedrock Custom Model
- **Approach**: SageMaker PySdk `BedrockModelBuilder`

## Overview

Uses the SageMaker PySdk `BedrockModelBuilder` to deploy a Nova fine-tuned LoRA model to Bedrock as a Custom Model. The builder auto-detects Nova models and calls `CreateCustomModel`.

**Required inputs** (collected in the steps below):

- Training job name
- Custom model name
- IAM role ARN
- AWS region

## Prerequisites

Requires SageMaker Python SDK >= 3.7.0 with `BedrockModelBuilder` Nova support (installed by Cell 1).

## Workflow

### Important Instructions

- Make sure to use dedicated tools instead of bash commands whenever possible

### Step 1: Gather Training Job Name

The training job name was identified in Step 1 of the main workflow. Confirm you have it.

### Step 2: Gather Custom Model Name

For this step, you need: **a name for the deployed custom model.**

Suggest a name based on the training job or use case, e.g., `nova-micro-bedrock-<timestamp>`. Ask the user to confirm or provide their own.

⏸ Wait for user before moving on.

### Step 3: Verify IAM Role

Use the IAM role from the training job (extracted in Step 1 of the main workflow via `describe-training-job`). We'll assume this role has the necessary permissions for Bedrock deployment.

### Step 4: Confirm Region

The region was identified in Step 1 of the main workflow. Nova → Bedrock deployment is currently only supported in **us-east-1**. If the training job is in a different region, tell the user that Bedrock deployment is not supported for this model in this region.

### Step 5: Confirm Configuration

> "Here's the deployment setup:
>
> - Deployment target: Bedrock (Custom Model)
> - Training Job: [job-name]
> - Custom Model Name: [name]
> - IAM Role: [arn]
> - Region: us-east-1
>
> Does this look right?"

⏸ Wait for user approval.

### Step 6: Generate Notebook

If a project directory already exists (from earlier in the workflow), use it. Otherwise, activate the **directory-management** skill to set one up.

Check if the project notebook already exists at `<project-dir>/notebooks/<project-name>.ipynb`.

- If it exists → ask: _"Would you like me to append the deployment cells to the existing notebook, or create a new one?"_
- If it doesn't exist → create it

When appending, add a markdown header cell `## Model Deployment — Bedrock` as a section divider before the new cells.

⏸ Wait for user.

## Notebook Structure

### Markdown Header

```json
{
  "cell_type": "markdown",
  "metadata": {},
  "source": [
    "# Deploy Nova to Bedrock"
  ]
}
```

### Cells

Each cell's content comes from `../scripts/deploy-nova-bedrock.py`, split on the `# Cell N:` comments.

- **Cell 1**: Setup (pip install)
- **Cell 2**: Configuration (env vars, imports, placeholders)
- **Cell 3**: Build and Deploy to Bedrock (blocks until deployment is Active)
- **Cell 4**: Test Inference

### Placeholders

Cell 2:

- `[REGION]` → AWS region (us-east-1)
- `[TRAINING_JOB_NAME]` → SageMaker training job name
- `[ROLE_ARN]` → IAM role ARN
- `[CUSTOM_MODEL_NAME]` → Name for the custom model

All other cells have no placeholders.

### Step 7: Provide Run Instructions

```
To run:
1. Cell 1 — install SDK packages
2. Cell 2 — set configuration values
3. Cell 3 — creates custom model via BedrockModelBuilder and deploys (blocks until Active)
4. Cell 4 — test inference with a sample prompt via Converse API
```

## Common Issues

- **"ServiceQuotaExceededException: The number of custom models in Creating status has reached the quota limit"**: Too many concurrent model creations. Wait for in-progress models to finish, or delete old custom models.
- **"No module named 'sagemaker.serve.bedrock_model_builder'"**: Re-run Cell 1 to install the required packages, then restart the kernel.
- **"Access denied to S3"**: Add S3 read permissions to the IAM role for the model artifacts bucket.
- **"Provided IAM role could not be assumed"**: Ensure role has trust policy for `bedrock.amazonaws.com`.
- **Deployment status "Failed"**: Check CloudTrail for the `CreateCustomModel` event to see the failure reason.
