Configuring BOTO for ECS

Boto is an AWS (Amazon Web Services) SDK for Pyton, giving developers a way to write object-oriented applications for S3 and EC2 services while allowing for low-level direct service access as necessary.


To configure the latest version - boto3 - for use with ECS, be sure to use the absolute address of the host system, including the scheme and S3 services port, e.g.


ecs_access_key_id = 'ecs_user'
ecs_secret_key = 'secret'


and provide them to the S3 session and resource constructors.


session = Session(aws_access_key_id=ecs_access_key_id, aws_secret_access_key=ecs_secret_key)
s3 = session.resource('s3', endpoint_url=ecs_endpoint, verify=False,
                      config=Config(signature_version='s3', s3={'addressing_style': 'path'}))


Be sure to import Session and Config to avoid any conflicts at runtime:


from boto3.session import Session, Config


Regarding additional options:


Specifying s3 as the signature_version implies usage of AWS v2 authentication, which provides better compatibility with ECS than the default authentication version used by boto3.


Indicating path-style addressing eliminates the need for any particular configuration in place on the ECS or DNS.


The verify=False option is only necessary when using HTTPS, and may be omitted when using ECS Test Drive ( as the target endpoint.


If using HTTPS, it is recommended that you use the -W command to clean the output (e.g. python -W once ) .