# Buggy code
def get_s3_bucket_details(boto3_session, bucket_data):
    """
    Iterates over all S3 buckets. Yields bucket name (string) and pairs of S3 bucket policies (JSON) and ACLs (JSON)
    """
    client = boto3_session.client("s3")
    for bucket in bucket_data["Buckets"]:
        acl = get_acl(bucket, client)
        policy = get_policy(bucket, client)
        yield bucket["Name"], acl, policy


# Traceback (botocore.exceptions.ClientError)
ERROR:cartography.sync:Unhandled exception during sync stage 'aws'
Traceback (most recent call last):
File "/usr/local/bin/cartography", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/cartography/cli.py", line 216, in main
return CLI(default_sync, prog='cartography').main(argv)
File "/usr/local/lib/python3.6/site-packages/cartography/cli.py", line 196, in main
return cartography.sync.run_with_config(self.sync, config)
File "/usr/local/lib/python3.6/site-packages/cartography/sync.py", line 135, in run_with_config
return sync.run(neo4j_driver, config)
File "/usr/local/lib/python3.6/site-packages/cartography/sync.py", line 69, in run
stage_func(neo4j_session, config)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 106, in start_aws_ingestion
_sync_multiple_accounts(neo4j_session, aws_accounts, regions, config.update_tag, common_job_parameters)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 44, in _sync_multiple_accounts
_sync_one_account(neo4j_session, boto3_session, account_id, regions, sync_tag, common_job_parameters)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 22, in _sync_one_account
s3.sync(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/s3.py", line 326, in sync
load_s3_details(neo4j_session, acl_and_policy_data_iter, current_aws_account_id, aws_update_tag)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/s3.py", line 136, in load_s3_details
for bucket, acl, policy in s3_details_iter:
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/s3.py", line 26, in get_s3_bucket_details
acl = get_acl(bucket, client)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/s3.py", line 54, in get_acl
acl = client.get_bucket_acl(Bucket=bucket['Name'])
File "/Users/drosenbloom/Library/Python/3.6/lib/python/site-packages/botocore/client.py", line 272, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/drosenbloom/Library/Python/3.6/lib/python/site-packages/botocore/client.py", line 576, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (IllegalLocationConstraintException) when calling the GetBucketAcl operation: The me-south-1 location constraint is incompatible for the region specific endpoint this request was sent to.

# Fixed code
def get_s3_bucket_details(boto3_session, bucket_data):
    """
    Iterates over all S3 buckets. Yields bucket name (string) and pairs of S3 bucket policies (JSON) and ACLs (JSON)
    """
    # a local store for s3 clients so that we may re-use clients for an AWS region
    s3_regional_clients = {}

    for bucket in bucket_data["Buckets"]:
        # Use us-east-1 region if no region was recognized for buckets
        # It was found that client.get_bucket_location does not return a region for buckets
        # in us-east-1 region
        client = s3_regional_clients.get(bucket["Region"])
        if not client:
            client = boto3_session.client("s3", bucket["Region"])
            s3_regional_clients[bucket["Region"]] = client
        acl = get_acl(bucket, client)
        policy = get_policy(bucket, client)
        yield bucket["Name"], acl, policy