17

I am running sagemaker for the first time from my laptop. When I try to start the session I get this error ValueError: Must setup local AWS configuration with a region supported by SageMaker

Local config is set to eu-west-1 which is supported by Sagemaker.

I changed the region to us-west-2 and back and nothing changed. Of course I restarted the notebook kernel after each change just in case.

import boto3

import re

import os

import numpy as np

import pandas as pd

import sagemaker as sage

boto_session = boto3.Session(profile_name="bennu")

session = sage.Session(boto_session=boto_session) #this is where the error appears

I expect the session to start and to move on to the next step. The full notebook is here https://github.com/PacktPublishing/Hands-On-Machine-Learning-Using-Amazon-SageMaker-v-/blob/master/section_1/train_and_deploy_your_first_model_on_sagemaker.ipynb

Vasil Dininski
  • 2,368
  • 1
  • 19
  • 31
user2957674
  • 171
  • 1
  • 1
  • 5
  • 1
    What do you mean by running SageMaker from your laptop? Are you running a notebook that should start a training job on SageMaker, or are you running on SageMaker notebook instance? – Guy Apr 26 '19 at 15:48
  • 1
    Thanks for using Amazon SageMaker! Are you running the above code from your local laptop or from within SageMaker Notebook Instance? – Neelam Gehlot Apr 29 '19 at 18:02

3 Answers3

17

You need to set the Region in the config file as asked by AWS documentation. You can find the location here:

~/.aws/config on Linux, macOS, or Unix

C:\Users\USERNAME\.aws\config on Windows

This file should contain lines in the following format:

[default]
region = your_aws_region

Example, in my case, it needs to be region = ap-southeast-2

Avi
  • 410
  • 3
  • 14
  • 1
    why if it uses boto3 client under it, and boto3 is capable of using the environment variable `AWS_DEFAULT_REGION` ? I have the same problem and that environment variable is correctly set – ricoms Dec 13 '19 at 21:01
5

In my case I solved it by creating sagemaker session by doing this:

import boto3
import sagemaker

sagemaker.Session(boto3.session.Session())

and having the AWS_DEFAULT_REGION environment variable set as us-east-1.

ricoms
  • 952
  • 15
  • 22
2

Continued to @Avi's answer. In MacOS. Should modify in ~/.aws/credentials with

[default]
region = <your_aws_region>
Xinyu Li
  • 45
  • 5