boto3.client("kms")But it wake up on brand-new machines, they open and also close dynamically.

if endpoint is None: if region_name is None: # raise a an ext specific error message that will provide # better guidance come the user what needs to happen. Raise NoRegionError()Why is this happening? and why only component of the time?


python linux amazon-web-services boto3 aws-kms
*

*

One means or another you need to tell boto3 in which region you wish the kms client to be created. This could be done clearly using the region_name parameter as in:

kms = boto3.client("kms", region_name="us-west-2")or you deserve to have a default region associated through your profile in her ~/.aws/config file as in:

region=us-west-2or you can use an atmosphere variable as in:

export AWS_DEFAULT_REGION=us-west-2but you do should tell boto3 which region to use.

You are watching: Botocore.exceptions.noregionerror: you must specify a region.


*

*

For Python 2 ns have uncovered that the boto3 library walk not source the an ar from the ~/.aws/config if the region is characterized in a various profile to default.So you have to define it in the session creation.

session = boto3.Session( profile_name="NotDefault", region_name="ap-southeast-2")print(session.available_profiles)client = session.client( "ec2")Where mine ~/.aws/config document looks like this:

region=ap-southeast-2region=ap-southeast-2I do this due to the fact that I use different profiles for various logins come AWS, personal and Work.


you can also set environment variables in the script itself, fairly than passing region_name parameter

os.environ<"AWS_DEFAULT_REGION"> = "your_region_name"

case sensitivity may matter.


I believe, by default, boto picks the an ar which is collection in aws cli. You deserve to run command #aws configure and press enter (it shows what creds friend have collection in aws cli through region)twice to check your region.


Alternatively you deserve to run the complying with (aws cli)

aws configure --profile $PROFILE_NAMEit"ll note you for the region.

notice in ~/.aws/config it"s:

region = ap-southeast-1output = jsonregion = ap-southeast-1output = json<profile profile name> in the square brackets


For those making use of CloudFormation template. You can collection AWS_DEFAULT_REGION atmosphere variable using UserData and also AWS::Region. For example,

MyInstance1: Type: AWS::EC2::Instance Properties: ImageId: ami-04b9e92b5572fa0d1 #ubuntu InstanceType: t2.micro UserData: Fn::Base64: !Sub | #!/bin/bash -x echo "export AWS_DEFAULT_REGION=$AWS::Region" >> /etc/profile
thanks for contributing response to ridge Overflow!

Please be sure to answer the question. Administer details and share your research!

But avoid

Asking because that help, clarification, or responding to various other answers.Making statements based on opinion; ago them increase with recommendations or an individual experience.

See more: Beautiful Girl With 8 Pack Super Abs Girl By Tupppkammm On Deviantart

To learn more, see our advice on writing great answers.


article Your price Discard

By clicking “Post your Answer”, friend agree come our regards to service, privacy policy and also cookie plan


Not the prize you're spring for? Browse various other questions tagged python linux amazon-web-services boto3 aws-kms or asking your very own question.


creating pandas DataFrame from worths in variables gives "ValueError: If making use of all scalar values, you need to pass one index"
site style / logo design © 2021 ridge Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.10.22.40552


your privacy

By click “Accept all cookies”, girlfriend agree ridge Exchange deserve to store cookie on your machine and disclose information in accordance with our Cookie Policy.