def get_accounts_and_regions_per_stack_set()

in source/aws/services/cloudformation.py [0:0]


    def get_accounts_and_regions_per_stack_set(self, stack_name):
        """
            List deployed stack instances for a stack set and returns the list
            of accounts and regions where the stack instances are deployed.
        :param stack_name: stack set name
        :return:
            list of accounts and regions where provided stack instances are
            deployed
        """
        try:
            response = self.cfn_client.list_stack_instances(
                StackSetName=stack_name,
                MaxResults=self.max_results_per_page
            )
            stack_instance_list = response.get('Summaries', [])
            # build the account and region list for the stack set
            # using list(set(LIST)) to remove the duplicate values from the list
            account_list = list(set([stack_instance['Account']
                                     for stack_instance
                                     in stack_instance_list]))
            region_list = list(set([stack_instance['Region']
                                    for stack_instance
                                    in stack_instance_list]))
            next_token = response.get('NextToken', None)

            while next_token is not None:
                self.logger.info("Next Token Returned: {}".format(next_token))
                response = self.cfn_client.list_stack_instances(
                    StackSetName=stack_name,
                    MaxResults=self.max_results_per_page,
                    NextToken=next_token
                )
                stack_instance_list = response.get('Summaries', [])
                next_token = response.get('NextToken', None)

                # update account and region lists
                additional_account_list = list(set([stack_instance['Account']
                                                    for stack_instance in
                                                    stack_instance_list]))
                additional_region_list = list(set([stack_instance['Region']
                                                   for stack_instance
                                                   in stack_instance_list]))
                account_list = account_list + additional_account_list
                region_list = region_list + additional_region_list
            return list(set(account_list)), list(set(region_list))
        except ClientError as e:
            self.logger.log_unhandled_exception(e)
            raise