Seite 1 von 1

Variable in S3 Proxy Server Verbindung mit Boto3

Verfasst: Donnerstag 9. November 2017, 10:36
von dugjibe
Hi,
I want to use the IP and Port as Variables in my S3 Proxy Server Connect command using the boto3 module.

This is the Python AWS S3 connect, which works fine:

s3client = boto3.resource(
's3',
aws_access_key_id = args.AWS_ACCESS_KEY_ID,
aws_secret_access_key=args.AWS_SECRET_ACCESS_KEY,
config=Config(proxies={'https': '192.168.88.1:3128'}),
)

I want to use the same AWS S3 connection, but with IP and Port as Variables (e.g. args.proxy, args.port).
This is what I want to achieve:

s3client = boto3.resource(
's3',
aws_access_key_id = args.AWS_ACCESS_KEY_ID,
aws_secret_access_key=args.AWS_SECRET_ACCESS_KEY,
config=Config(proxies={'https': 'args.proxy: args.port'}),
)

Re: Variable in S3 Proxy Server Verbindung mit Boto3

Verfasst: Donnerstag 9. November 2017, 10:52
von dugjibe
Hi,
I solved it:

s3client = boto3.resource(
's3',
aws_access_key_id = args.AWS_ACCESS_KEY_ID,
aws_secret_access_key=args.AWS_SECRET_ACCESS_KEY,
#before: config=Config(proxies={'https': '192.168.88.1:3128'}),
config=Config(proxies={'https': '%s:%s' % (args.proxy, args.port)})
)

Re: Variable in S3 Proxy Server Verbindung mit Boto3

Verfasst: Donnerstag 9. November 2017, 11:07
von sls
Hi dugjibe,

Code: Alles auswählen

config=Config(proxies={'https': 'args.proxy: args.port'})
'args.proxy: args.port' is just one String though. It should rather look like:

Code: Alles auswählen

{'https': "{0}:{1}".format(proxy_ip, proxy_port)}
Oh, too late. Anyways, aforementioned solution uses the format()-function.

Cheers, sls