diff --git a/cartography/intel/aws/__init__.py b/cartography/intel/aws/__init__.py index c378ddd93..e211a5080 100644 --- a/cartography/intel/aws/__init__.py +++ b/cartography/intel/aws/__init__.py @@ -144,6 +144,7 @@ def _sync_multiple_accounts( sync_tag: int, common_job_parameters: Dict[str, Any], aws_best_effort_mode: bool, + aws_sync_all_profiles: bool, aws_requested_syncs: List[str] = [], ) -> bool: logger.info("Syncing AWS accounts: %s", ', '.join(accounts.values())) @@ -152,16 +153,13 @@ def _sync_multiple_accounts( failed_account_ids = [] exception_tracebacks = [] - num_accounts = len(accounts) - for profile_name, account_id in accounts.items(): logger.info("Syncing AWS account with ID '%s' using configured profile '%s'.", account_id, profile_name) common_job_parameters["AWS_ID"] = account_id - if num_accounts == 1: - # Use the default boto3 session because boto3 gets confused if you give it a profile name with 1 account - boto3_session = boto3.Session() - else: + if aws_sync_all_profiles: boto3_session = boto3.Session(profile_name=profile_name) + else: + boto3_session = boto3.Session() _autodiscover_accounts(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters) @@ -301,6 +299,7 @@ def start_aws_ingestion(neo4j_session: neo4j.Session, config: Config) -> None: config.update_tag, common_job_parameters, config.aws_best_effort_mode, + config.aws_sync_all_profiles, requested_syncs, )