| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "Licensed to the Apache Software Foundation (ASF) under one\nor more contributor license agreements. See the NOTICE file\ndistributed with this work for additional information\nregarding copyright ownership. The ASF licenses this file\nto you under the Apache License, Version 2.0 (the\n\"License\"); you may not use this file except in compliance\nwith the License. You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing,\nsoftware distributed under the License is distributed on an\n\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, either express or implied. See the License for the\nspecific language governing permissions and limitations\nunder the License." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# Execute this cell to install dependencies\n", | |
| "%pip install apache-hamilton[visualization]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "# Sagemaker tutorial [](https://colab.research.google.com/github/dagworks-inc/hamilton/blob/main/examples/aws/sagemaker/notebook.ipynb) [](https://github.com/apache/hamilton/blob/main/examples/aws/sagemaker/notebook.ipynb)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from sagemaker.processing import ProcessingInput, ProcessingOutput, ScriptProcessor" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "script_processor = ScriptProcessor(\n", | |
| " command=[\"python3\"],\n", | |
| " image_uri=\"<account_number>.dkr.ecr.<region>.amazonaws.com/aws-sagemaker-hamilton:latest\", # Change to the actual URI\n", | |
| " role=\"arn:aws:iam::<account_number>:role/SageMakerScriptProcessorRole\", # Change to the actual URI\n", | |
| " instance_count=1,\n", | |
| " instance_type=\"ml.t3.medium\",\n", | |
| ")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# All inputs and outputs should be located in /opt/ml/processing/\n", | |
| "script_processor.run(\n", | |
| " code=\"processing.py\",\n", | |
| " inputs=[\n", | |
| " ProcessingInput(source=\"data/\", destination=\"/opt/ml/processing/input/data\"),\n", | |
| " ProcessingInput(source=\"app/\", destination=\"/opt/ml/processing/input/code/app\"),\n", | |
| " ],\n", | |
| " outputs=[\n", | |
| " ProcessingOutput(\n", | |
| " source=\"/opt/ml/processing/output/\",\n", | |
| " destination=\"s3://path/to/output/directory\", # Change to the actual URI\n", | |
| " )\n", | |
| " ],\n", | |
| ")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "After job finishes, the new files will appear in `s3://path/to/output/directory`:\n", | |
| "- `output_table.csv`\n", | |
| "- `dag_visualization.svg`" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "hamilton", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.11.8" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |