user2957674
user2957674

Reputation: 321

How to fix aws region error "ValueError: Must setup local AWS configuration with a region supported by SageMaker"

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

Upvotes: 22

Views: 32681

Answers (4)

jadianes
jadianes

Reputation: 576

This Python code is quite handy in certain scenarios where we don't have the option of defining a config file:

import os 
os.environ['AWS_DEFAULT_REGION'] = <YOUR_REGION>

Upvotes: 4

Xinyu Li
Xinyu Li

Reputation: 75

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

[default]
region = <your_aws_region>

Upvotes: 5

ricoms
ricoms

Reputation: 1007

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.

Upvotes: 7

Avi
Avi

Reputation: 450

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

Upvotes: 21

Related Questions