I've been wrapped around this problem for a while and can't seem to understand where this issue is coming from. I'm deploying a model on Sagemaker and I get the error on this line of code:
sm_model.deploy(initial_instance_count=1, instance_type='ml.m4.2xlarge', endpoint_name=endpoint_name)
Jupyter Notebook outputs the error below. Note: Line 269 isn't code in my Notebook, it is just a reference I get as a result of my model.deploy command above.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
267 return self.image
268
--> 269 region_name = self.sagemaker_session.boto_region_name
270 return create_image_uri(
271 region_name,
AttributeError: 'NoneType' object has no attribute 'boto_region_name'
Edit: This is just an example dataset that I'm using to create this pipeline. This is on a sagemaker notebook instance. I'm adding the entire code for clarification below.
from sagemaker.model import Model
from sagemaker.pipeline import PipelineModel
import boto3
from time import gmtime, strftime
import boto3
import s3fs
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn as sns
%matplotlib inline
sns.set()
import boto3
import sagemaker
from sagemaker import get_execution_role
# Using Amazon S3
s3 = boto3.client('s3')
sage = boto3.client('sagemaker')
session = boto3.session.Session()
sagemaker_session = sagemaker.Session()
# Get a SageMaker-compatible role used by this Notebook Instance.
role = get_execution_role()
#Upload file using AWS session
# S3 prefix
prefix = 'Scikit-keras-NLP-pipeline-Boston-Housing-example-June08-test1'
train_input = sagemaker_session.upload_data(
path='housing.csv',
bucket=bucket,
key_prefix='{}/{}'.format(prefix, 'train'))
from sagemaker.sklearn.estimator import SKLearn
output_dir = 's3://sagemaker-us-east-1-819182027957/Scikit-keras-NLP-pipeline-Boston-Housing-example-July08-test1/train'
model_dir = 's3://sagemaker-us-east-1-819182027957/Scikit-keras-NLP-pipeline-Boston-Housing-example-June08-test1/train'
script_path = 'Boston.py'
sklearn_preprocessor = SKLearn(
entry_point=script_path,
role=role,
train_instance_type="ml.c4.xlarge",
sagemaker_session=sagemaker_session,
output_path=output_dir)
sklearn_preprocessor.fit({'train': train_input,'model-dir':model_dir,'output-data-dir':output_dir})
from sagemaker.tensorflow.serving import Model
sagemaker_estimator = Model(model_data = 's3://' + sagemaker_session.default_bucket() + '/Scikit-keras-NLP-pipeline-Boston-Housing-example-June08-test1/train/Bostonmodel.tar.gz',
role = role)
#####
scikit_learn_inference_model = sklearn_preprocessor.create_model()
#sagemaker_model = sagemaker_estimator.create_model() # Does Not have create_model method
sagemaker_model = sagemaker_estimator
model_name = 'Boston-inf-pipeline-July08-model'
endpoint_name = 'Boston-inf-pipeline-July08-endpoint'
#Build Inference Pipeline
sm_model = PipelineModel(
name=model_name,
role=role,
models=[
scikit_learn_inference_model,
sagemaker_model],
sagemaker_session=sagemaker_session)
sm_model.deploy(initial_instance_count=1, instance_type='ml.c4.xlarge', endpoint_name=endpoint_name)