Skip to content

Latest commit

 

History

History
193 lines (127 loc) · 8.31 KB

SAMPLE10-MLOps-SageMaker-GitHub-Codepipeline-CodeBuild-CodeDeploy.md

File metadata and controls

193 lines (127 loc) · 8.31 KB

SAMPLE-10: Implementing MLOps Pipeline using GitHub, AWS CodePipeline, AWS CodeBuild, AWS CodeDeploy, and AWS Sagemaker (Endpoint)

This sample shows:

  • how to create MLOps Pipeline
  • how to use GitHub Hooks (Getting Source Code from Github to CodePipeline)
  • how to create Build CodePipeline (Source, Build), CodeBuild (modelbuild_buildspec.yml), Deploy CodePipeline (Source, Build, DeployStaging, DeployProd), CodeBuild (modeldeploy_buildspec.yml)
  • how to save the model and artifacts on S3
  • how to create and test models using Notebooks

Notes:

Code: https://github.com/omerbsezer/Fast-Terraform/tree/main/samples/mlops-sagemaker-github-codepipeline-codebuild-codedeploy

Architecture:

Prerequisite

Steps

  • Before running Terraform, upload "Modelbuild_Pipeline" and "Modeldeploy_Pipeline" in your GitHub account.
  • Run:
cd terraform
terraform init
terraform validate
terraform plan
terraform apply
  • After run:

    image

  • AWS CodePipeline:

    image

  • ModelBuild:

    image

  • ModelBuild Log:

    image

  • AWS S3:

    image

  • ModelBuild was done successfully:

    image

  • CloudWatch to see the training accuracy:

    image

  • CloudWatch, Log Groups, Train Error:

    image

  • ModelDeploy:

    image

    image

  • CloudFormation, stack: deploy-staging

    image

  • SageMaker Dashboard, staging endpoint in service:

    image

  • SageMaker, Model:

    image

  • S3, Model, possible to download:

    image

  • Try Staging Endpoint with notebook (end2end.ipynb, last cell, enter the endpointname):

import pandas as pd
import numpy as np
import sagemaker
import boto3
from sagemaker import get_execution_role

test_data=pd.read_csv('test.csv',header=None)
testdata1=test_data.iloc[0:1,1:]

runtime = boto3.client("sagemaker-runtime")
Endpoint_name='aws-ml-11052023-staging-0306' #<your endpoint name> # update to your own endpoint name

prediction = runtime.invoke_endpoint(
    EndpointName=Endpoint_name,
    Body=testdata1.to_csv(header=False, index=False).encode("utf-8"),
    ContentType="text/csv",
    Accept= "text/csv",
)

print(prediction["Body"].read())
  • Endpoint returned the result:

    image

  • Approve the Product on the CodePipeline:

    image

  • SageMaker Dashboard, 2 Endpoints are in-service:

    image

  • SageMaker, Prod Endpoint:

    image

  • CloudFormation:

    image

  • Test Prod Endpoint, returns results:

    image

  • Delete Endpoints manually, if the endpoints are in-service, you have to pay their cost:

    image

  • Delete stacks manually in Cloudformation.

  • Download artifacts on S3:

aws s3 sync s3://artifact-ml-11052023 C:\Users\oesezer\Desktop\aws-artifacts
  • Downloaded to the local PC:

    image

  • Destroy with "terraform destroy":

    image

  • Check whether all created artifacts are deleted on CodePipeline, S3, CloudFormation, SageMaker, and CloudWatch (LogGroups) or not. If still some of the artifacts are in the AWS, please delete them all.

References