"""Amazon S3 connector.""" import boto3 from daemon_asset_copy import config from ddtrace import tracer @tracer.wrap() def get_s3_client(options=None): """Get S3 client. Returns: boto3.client.S3: S3 client. """ if not options: options = {'region_name': config.AWS_REGION} if config.S3_ENDPOINT: options['endpoint_url'] = config.S3_ENDPOINT return boto3.session.Session().client('s3', **options) @tracer.wrap() def get_url_for_s3_object(bucket, key): """Get URL for S3 Object. Args: bucket (str): S3 bucket. key (str): S3 key. Returns: str: URL for S3 object. """ s3 = get_s3_client() return s3.generate_presigned_url( ClientMethod='get_object', Params={'Bucket': bucket, 'Key': key}, ExpiresIn=86400, )