def __init__()

in resource-selector-lambda/handler.py [0:0]


    def __init__(self, **kwargs):
        cfg = kwargs['cfg']
        resource = kwargs['resource']
        # Last Error Message placeholder
        self.errorMessage=''
        # Get current Region
        self.region = kwargs['region']

        # What to do with CFN stack if resource not found - either failed or let cfn run
        self.error = (cfg['Options']['Error'] if 'Options' in cfg and 'Error' in cfg['Options']
                             else 'failed')
        # How many items return when more the one found (all, single)
        self.output = (cfg['Options']['Output'] if 'Options' in cfg and 'Output' in cfg['Options']
                             else 'all')
        # When more the one tag provided should resource match on all tags or any tag
        self.match = (cfg['Options']['Match'] if 'Options' in cfg and 'Match' in cfg['Options']
                             else 'any')
        # Return subnets that have at least X available IPs
        self.availableIp = (int(cfg['Options']['AvailableIP']) if 'Options' in cfg and 'AvailableIP' in cfg['Options']
                             else 5)
        # IAM group name
        self.groupName = (cfg['Options']['GroupName'] if 'Options' in cfg and 'GroupName' in cfg['Options']
                             else None)
        # ACM Certificate Domain name
        self.domain = (cfg['Options']['Domain'] if 'Options' in cfg and 'Domain' in cfg['Options']
                             else None)
        # KMS alias to search
        self.kmsAlias = (cfg['Options']['KMSAlias'] if 'Options' in cfg and 'KMSAlias' in cfg['Options']
                             else None)
        # In what format return key: as alias or as id
        self.kmsOutput = (cfg['Options']['KMSOutput'] if 'Options' in cfg and 'KMSOutput' in cfg['Options']
                             else 'id')
        # IAM Policy name
        self.policyName = (cfg['Options']['PolicyName'] if 'Options' in cfg and 'PolicyName' in cfg['Options']
                             else None)
        # IAM Role name
        self.roleName = (cfg['Options']['RoleName'] if 'Options' in cfg and 'RoleName' in cfg['Options']
                             else None)
        # IAM Role path
        self.rolePath = (cfg['Options']['RolePath'] if 'Options' in cfg and 'RolePath' in cfg['Options']
                             else '/')
        # Spot Price Instance Type
        self.instanceType = (cfg['Options']['InstanceType'] if 'Options' in cfg and 'InstanceType' in cfg['Options']
                             else None)
        # Spot Price Instance OS
        self.instanceOS = (cfg['Options']['InstanceOS'] if 'Options' in cfg and 'InstanceOS' in cfg['Options']
                             else None)
        # AMI Image Owner
        self.imageOwner = (cfg['Options']['ImageOwner'] if 'Options' in cfg and 'ImageOwner' in cfg['Options']
                             else None)
        # AMI Image Name
        self.imageName = (cfg['Options']['ImageName'] if 'Options' in cfg and 'ImageName' in cfg['Options']
                             else None)

        # Get VPC(s) for subnets or security group
        vpcs = (kwargs['vpc'] if 'vpc' in kwargs else None)

        # Search resources
        if resource == 'vpc':
            self.getVPCs(cfg)

        if resource == 'subnet':
            vpcList = self.convert_vps_to_list(vpcs)
            self.getSubnets(cfg, vpcList)

        if resource == 'sg':
            vpcList = self.convert_vps_to_list(vpcs)
            self.getSecurityGroup(cfg, vpcList)

        if resource == 'acm':
            self.getACM(cfg)

        if resource == 'kms':
            self.getKMS()

        if resource == 'policy':
            self.getPolicy()

        if resource == 'role':
            self.getRoles(cfg)

        if resource == 'spot':
            self.output = 'single'
            self.getSpotPrice()

        if resource == 'ami':
            self.output = 'single'
            self.getImage(cfg)