{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using SageMaker pipelines for MLOps workflows\n", "\n", "This notebook contains end-to-end code to construct and execute a secure MLOps pipeline in your data science environment. It contains all necessary all code in one place. You can use and modify this code for your experiments and tests.\n", " \n" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [], "source": [ "if False:\n", " !pip install --disable-pip-version-check -q sagemaker==2.47.1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!python --version" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "if False:\n", " !pip install -U sagemaker" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import boto3\n", "import sagemaker\n", "import sagemaker.session\n", "import json\n", "\n", "print(f\"SageMaker version: {sagemaker.__version__}\")" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "sm = boto3.client(\"sagemaker\")\n", "ssm = boto3.client(\"ssm\")\n", "\n", "def get_environment(project_name, ssm_params):\n", " r = sm.describe_domain(\n", " DomainId=sm.describe_project(\n", " ProjectName=project_name\n", " )[\"CreatedBy\"][\"DomainId\"]\n", " )\n", " del r[\"ResponseMetadata\"]\n", " del r[\"CreationTime\"]\n", " del r[\"LastModifiedTime\"]\n", " r = {**r, **r[\"DefaultUserSettings\"]}\n", " del r[\"DefaultUserSettings\"]\n", "\n", " i = {\n", " **r,\n", " **{t[\"Key\"]:t[\"Value\"] \n", " for t in sm.list_tags(ResourceArn=r[\"DomainArn\"])[\"Tags\"] \n", " if t[\"Key\"] in [\"EnvironmentName\", \"EnvironmentType\"]}\n", " }\n", "\n", " for p in ssm_params:\n", " try:\n", " i[p[\"VariableName\"]] = ssm.get_parameter(Name=f\"{i['EnvironmentName']}-{i['EnvironmentType']}-{p['ParameterName']}\")[\"Parameter\"][\"Value\"]\n", " except:\n", " i[p[\"VariableName\"]] = \"\"\n", "\n", " return i\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Shutting down your kernel for this notebook to release resources.
\n", "\n", " \n", "" ] } ], "metadata": { "instance_type": "ml.t3.medium", "kernelspec": { "display_name": "Python 3 (Data Science)", "language": "python", "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0" }, "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.7.10" } }, "nbformat": 4, "nbformat_minor": 4 }