Skip to content

Instantly share code, notes, and snippets.

@gleeb
gleeb / invoke_async_endpoint.py
Last active August 11, 2022 11:23
sagemaker invoke async endpoint
import boto3
sm_client = boto3.client('sagemaker', region_name='us-east-1')
sagemaker_runtime = boto3.client("sagemaker-runtime", region_name='us-east-1')
# Specify the location of the input.
input_location = "<Path to your csv file in S3>"
# The name of the endpoint. The name must be unique within an AWS Region in your AWS account.
endpoint_name='titanic-survival-async-endpoint'
@gleeb
gleeb / deploy-async.py
Last active August 11, 2022 11:12
sagemaker deploy async endpoint
import boto3
sm_client = boto3.client('sagemaker', region_name='us-east-1')
endpoint_config_name = 'titanic-survival-async-endpoint-config'
print(endpoint_config_name)
create_endpoint_config_response = sm_client.create_endpoint_config(
EndpointConfigName=endpoint_config_name, # You will specify this name in a CreateEndpoint request.
# List of ProductionVariant objects, one for each model that you want to host at this endpoint.
@gleeb
gleeb / deploy_serverless.py
Created August 11, 2022 08:13
sagemaker deploy serverless endpoint
import boto3
sm_client = boto3.client('sagemaker', region_name='us-east-1')
endpoint_config_name = 'titanic-survival-serverless-endpoint-config'
print(endpoint_config_name)
create_endpoint_config_response = sm_client.create_endpoint_config(
EndpointConfigName = endpoint_config_name,
ProductionVariants=[ {
"ModelName": "titanic-survival-v1",
@gleeb
gleeb / invoke_realtime.py
Created August 11, 2022 08:00
sagemaker invoke real time endpoint
import boto3
sm_client = boto3.client('sagemaker', region_name='us-east-1')
sagemaker_runtime = boto3.client("sagemaker-runtime", region_name='us-east-1')
# The name of the endpoint. The name must be unique within an AWS Region in your AWS account.
endpoint_name='titanic-survival-endpoint1'
# After you deploy a model into production using SageMaker hosting
# services, your client applications use this API to get inferences
@gleeb
gleeb / create_endpoint.py
Created August 8, 2022 11:56
sagemaker create a real time endpoint
import boto3
sm_client = boto3.client('sagemaker', region_name='us-east-1')
endpoint_name = 'titanic-survival-endpoint'
endpoint_config_name = 'titanic-survival-endpoint-config'
print("EndpointName={}".format(endpoint_name))
create_endpoint_response = sm_client.create_endpoint(
EndpointName=endpoint_name,
EndpointConfigName=endpoint_config_name)
@gleeb
gleeb / create_endpoint_config.py
Created August 8, 2022 11:52
sagemaker reate endpoint config
import boto3
sm_client = boto3.client('sagemaker', region_name='us-east-1')
endpoint_config_name = 'titanic-survival-endpoint-config'
print(endpoint_config_name)
create_endpoint_config_response = sm_client.create_endpoint_config(
EndpointConfigName = endpoint_config_name,
ProductionVariants=[{
'InstanceType':'ml.m4.xlarge',
'InitialVariantWeight':1,
@gleeb
gleeb / create_model_from_registry.py
Created August 8, 2022 10:00
Sagemaker create model from registry
import boto3
from datetime import datetime
sm_client = boto3.client('sagemaker', region_name='us-east-1')
model_name = 'titanic-survival-v1'
print("Model name : {}".format(model_name))
container_list = [{'ModelPackageName': 'arn:aws:sagemaker:us-east-1:...:model-package/titanic-survival/3'}]
@gleeb
gleeb / regiter_model.py
Last active August 11, 2022 07:43
register a model to sagemaker model group
import boto3
sm_client = boto3.client('sagemaker', region_name='us-east-1')
model_url = "s3://sagemaker-us-east-1-.../sagemaker-scikit-learn-.../output/model.tar.gz"
modelpackage_inference_specification = {
"InferenceSpecification": {
"Containers": [
@gleeb
gleeb / create_group.py
Created August 7, 2022 17:46
Sagemaker reate package group
import os
import sagemaker
import boto3
iam_client = boto3.client('iam')
role = iam_client.get_role(RoleName='AmazonSageMaker-ExecutionRole-xyz')['Role']['Arn']
sm_client = boto3.client('sagemaker', region_name="us-east-1")
model_package_group_name = "Titanic-survival"
model_package_group_input_dict = {
@gleeb
gleeb / titanic-train-invoke-notebook.ipynb
Last active August 7, 2022 11:08
titanic-train-invoke-notebook.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.