Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sdks/python/apache_beam/io/aws/clients/s3/boto3_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# pytype: skip-file

from apache_beam import version as beam_version
from apache_beam.io.aws.clients.s3 import messages
from apache_beam.options import pipeline_options
from apache_beam.utils import retry
Expand All @@ -25,6 +26,7 @@
# pylint: disable=wrong-import-order, wrong-import-position
# pylint: disable=ungrouped-imports
import boto3
from botocore.config import Config

except ImportError:
boto3 = None
Expand Down Expand Up @@ -72,7 +74,9 @@ def __init__(self, options):
endpoint_url=endpoint_url,
aws_access_key_id=access_key_id,
aws_secret_access_key=secret_access_key,
aws_session_token=session_token)
aws_session_token=session_token,
config=Config(
user_agent_extra='apache-beam/%s' % beam_version.__version__))

self._download_request = None
self._download_stream = None
Expand Down
18 changes: 18 additions & 0 deletions sdks/python/apache_beam/io/aws/clients/s3/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@
import os
import unittest

from apache_beam import version as beam_version
from apache_beam.io.aws import s3io
from apache_beam.io.aws.clients.s3 import fake_client
from apache_beam.io.aws.clients.s3 import messages
from apache_beam.options import pipeline_options

# Protect against environments where boto3 library is not available.
# pylint: disable=wrong-import-order, wrong-import-position
try:
from apache_beam.io.aws.clients.s3 import boto3_client
except ImportError:
boto3_client = None # type: ignore[assignment]
# pylint: enable=wrong-import-order, wrong-import-position


class ClientErrorTest(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -222,6 +231,15 @@ def test_complete_multipart_upload_too_many(self):
self.assertEqual(e.code, 400)


@unittest.skipIf(boto3_client is None, 'AWS dependencies are not installed')
class ClientUserAgentTest(unittest.TestCase):
def test_user_agent_contains_beam_version(self):
client = boto3_client.Client(pipeline_options.S3Options())
self.assertIn(
'apache-beam/%s' % beam_version.__version__,
client.client.meta.config.user_agent)


if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO)
unittest.main()
Loading