# Buggy code
def get_tgw_vpc_attachments(boto3_session, region):
    client = boto3_session.client(
        "ec2", region_name=region, config=get_botocore_config()
    )
    paginator = client.get_paginator("describe_transit_gateway_vpc_attachments")
    tgw_vpc_attachments = []
    for page in paginator.paginate():
        tgw_vpc_attachments.extend(page["TransitGatewayVpcAttachments"])
    return tgw_vpc_attachments


# Traceback (botocore.exceptions.ClientError)
$ cartography --neo4j-uri bolt://localhost:7687
INFO:cartography.sync:Starting sync with update tag '1603410623'
INFO:cartography.sync:Starting sync stage 'create-indexes'
INFO:cartography.intel.create_indexes:Creating indexes for cartography node types.
INFO:cartography.sync:Finishing sync stage 'create-indexes'
INFO:cartography.sync:Starting sync stage 'aws'
INFO:cartography.intel.aws:Syncing AWS account with ID '123456789012' using configured profile 'default'.
INFO:cartography.intel.aws:Trying to autodiscover accounts.
INFO:cartography.intel.aws.iam:Syncing IAM for account '123456789012'.
INFO:cartography.intel.aws.s3:Syncing S3 for account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'eu-north-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'ap-south-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'eu-west-3' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'eu-west-2' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'eu-west-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'ap-northeast-3' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'ap-northeast-2' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'ap-northeast-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'sa-east-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'ca-central-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'ap-east-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'ap-southeast-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'ap-southeast-2' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'eu-central-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'us-east-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'us-east-2' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'us-west-1' in account '123456789012'.
INFO:cartography.intel.aws.dynamodb:Syncing DynamoDB for region in 'us-west-2' in account '123456789012'.
INFO:cartography.intel.aws.ec2:Syncing EC2 for account '123456789012'.
WARNING:cartography.intel.aws.ec2.tgw:Could not retrieve Transit Gateways due to boto3 error InvalidAction: The action DescribeTransitGateways is not valid for this web service.. Skipping.
ERROR:cartography.sync:Unhandled exception during sync stage 'aws'
Traceback (most recent call last):
File "/fakepath/.local/lib/python3.6/site-packages/cartography/sync.py", line 71, in run
stage_func(neo4j_session, config)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 63, in timed
return method(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 148, in start_aws_ingestion
_sync_multiple_accounts(neo4j_session, aws_accounts, config.update_tag, common_job_parameters)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 96, in _sync_multiple_accounts
_sync_one_account(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 44, in _sync_one_account
ec2.sync(neo4j_session, boto3_session, regions, account_id, sync_tag, common_job_parameters)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 63, in timed
return method(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/ec2/__init__.py", line 37, in sync
sync_transit_gateways(neo4j_session, boto3_session, regions, account_id, sync_tag, common_job_parameters)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 63, in timed
return method(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/ec2/tgw.py", line 228, in sync_transit_gateways
tgw_attachments = get_tgw_attachments(boto3_session, region)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 63, in timed
return method(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 78, in inner_function
return func(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/ec2/tgw.py", line 36, in get_tgw_attachments
for page in paginator.paginate():
File "/fakepath/.local/lib/python3.6/site-packages/botocore/paginate.py", line 255, in __iter__
response = self._make_request(current_kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/botocore/paginate.py", line 332, in _make_request
return self._method(**current_kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/botocore/client.py", line 676, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidAction) when calling the DescribeTransitGatewayAttachments operation: The action DescribeTransitGatewayAttachments is not valid for this web service.
Traceback (most recent call last):
File "/fakepath/.local/bin/cartography", line 11, in <module>
sys.exit(main())
File "/fakepath/.local/lib/python3.6/site-packages/cartography/cli.py", line 348, in main
return CLI(default_sync, prog='cartography').main(argv)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/cli.py", line 328, in main
return cartography.sync.run_with_config(self.sync, config)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/sync.py", line 145, in run_with_config
return sync.run(neo4j_driver, config)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/sync.py", line 71, in run
stage_func(neo4j_session, config)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 63, in timed
return method(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 148, in start_aws_ingestion
_sync_multiple_accounts(neo4j_session, aws_accounts, config.update_tag, common_job_parameters)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 96, in _sync_multiple_accounts
_sync_one_account(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 44, in _sync_one_account
ec2.sync(neo4j_session, boto3_session, regions, account_id, sync_tag, common_job_parameters)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 63, in timed
return method(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/ec2/__init__.py", line 37, in sync
sync_transit_gateways(neo4j_session, boto3_session, regions, account_id, sync_tag, common_job_parameters)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 63, in timed
return method(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/ec2/tgw.py", line 228, in sync_transit_gateways
tgw_attachments = get_tgw_attachments(boto3_session, region)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 63, in timed
return method(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/util.py", line 78, in inner_function
return func(*args, **kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/cartography/intel/aws/ec2/tgw.py", line 36, in get_tgw_attachments
for page in paginator.paginate():
File "/fakepath/.local/lib/python3.6/site-packages/botocore/paginate.py", line 255, in __iter__
response = self._make_request(current_kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/botocore/paginate.py", line 332, in _make_request
return self._method(**current_kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/fakepath/.local/lib/python3.6/site-packages/botocore/client.py", line 676, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidAction) when calling the DescribeTransitGatewayAttachments operation: The action DescribeTransitGatewayAttachments is not valid for this web service.

# Fixed code
def get_tgw_vpc_attachments(boto3_session, region):
    client = boto3_session.client(
        "ec2", region_name=region, config=get_botocore_config()
    )
    tgw_vpc_attachments = []
    try:
        paginator = client.get_paginator("describe_transit_gateway_vpc_attachments")
        for page in paginator.paginate():
            tgw_vpc_attachments.extend(page["TransitGatewayVpcAttachments"])
    except botocore.exceptions.ClientError as e:
        logger.warning(
            "Could not retrieve Transit Gateway VPC Attachments due to boto3 error %s: %s. Skipping.",
            e.response["Error"]["Code"],
            e.response["Error"]["Message"],
        )
    return tgw_vpc_attachments