Created
April 3, 2020 19:42
-
-
Save praveenc/bc30414f37ec5c1b0cdd02b45fa3334e to your computer and use it in GitHub Desktop.
boto3 create a s3 session client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def setup_s3_client(job_data): | |
| """Creates an S3 client | |
| Uses the credentials passed in the event by CodePipeline. These | |
| credentials can be used to access the artifact bucket. | |
| :param job_data: The job data structure | |
| :return: An S3 client with the appropriate credentials | |
| """ | |
| try: | |
| key_id = job_data['artifactCredentials']['accessKeyId'] | |
| key_secret = job_data['artifactCredentials']['secretAccessKey'] | |
| session_token = job_data['artifactCredentials']['sessionToken'] | |
| session = Session(aws_access_key_id=key_id, | |
| aws_secret_access_key=key_secret, | |
| aws_session_token=session_token) | |
| except Exception as e: | |
| logger.warn('No credentials in artifact - using default role access: {}'.format(e)) | |
| session = Session() | |
| return session.client('s3', config=botocore.client.Config(signature_version='s3v4')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment