boto3 client NoRegionError: You must specify a region error only sometimes

后端 未结 7 1652
误落风尘
误落风尘 2021-01-30 07:30

I have a boto3 client :

boto3.client(\'kms\')

But it happens on new machines, They open and close dynamically.

    if endpoint         


        
7条回答
  •  太阳男子
    2021-01-30 08:30

    For those using CloudFormation template. You can set AWS_DEFAULT_REGION environment variable using UserData and 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
    

提交回复
热议问题