예제 #1
0
파일: main.py 프로젝트: otsu81/aws-parseley
def fetch_role_arn(session, account_id, rolename):
    global arn_list
    iam = BotoFactory().get_capability(
        boto3.resource, session, 'iam', account_id=account_id
    )
    try:
        role = iam.Role(rolename)
        print(role.arn)
        arn_list.append(role.arn)
    except iam.meta.client.exceptions.NoSuchEntityException as e:
        log.warn(f"not found in {account_id}, {e}")
예제 #2
0
    def delete_role(self, rolename):
        try:
            # get all policies
            iam_r = BotoFactory().get_capability(boto3.resource, self.session,
                                                 'iam', self.account_id,
                                                 os.getenv('DEFAULT_ROLE'))
            role = iam_r.Role(rolename)

            itr = role.policies.all()
            for i in itr:
                i.delete()

            # delete role
            response = role.delete()
            logging.info(json.dumps(response, indent=4, default=str))

        except iam_r.meta.client.exceptions.NoSuchEntityException as e:
            logging.info(e)
            logging.info(f"{self.account_id}: role {rolename} doesn't exist")