AWS - Amazon Workspaces & AWS boto3 cannot run script

1.2k views Asked by At

I get an error when trying to execute a boto3 (python3) script in Amazon Workspaces (Windows Server) at work. Here are the script and steps.

Environment: Windows Server Datacenter

Script:

import boto3

s3 = boto3.resource('s3')

my_bucket = s3.Bucket('bucket_name')

for my_bucket_object in my_bucket.objects.all():
    print(my_bucket_object)

Steps:

  • install boto3
  • Run the python script using python your_script.py
  • Get the following error

"botocore.exceptions.HTTPClientError: An HTTP Client raised an unhandled exception: check_hostname requires server_hostname"

I can execute AWS CLI commands in the workspace with no issues e.g. aws s3 commands all work properly. Any pointers appreciated.

1

There are 1 answers

0
user1811107 On

I found a way to solve the issue

Replace

s3 = boto3.resource('s3')

with

s3 = boto3.resource('s3', config=Config(proxies={'https':'your_proxy_server_ip:3128'})})