Esempio n. 1
0
    def get_instances():
        """
        Get the information for all instances with the relevant roles.

        This function will assume that it's running on an EC2 instance with the correct IAM role.
        See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#iam
        -role for details.

        :raises: botocore.exceptions.ClientError if can't describe local instance information.
        :return: All visible instances from this instance
        """
        current_instance = AwsInstance()
        local_ssm_client = boto3.client("ssm", current_instance.get_region())
        try:
            response = local_ssm_client.describe_instance_information()

            filtered_instances_data = filter_instance_data_from_aws_response(response)
            return filtered_instances_data
        except botocore.exceptions.ClientError as e:
            logger.warning("AWS client error while trying to get instances: " + e)
            raise e
Esempio n. 2
0
File: aws.py Progetto: zkbupt/monkey
class AwsEnvironment(Environment):

    _credentials_required = True

    def __init__(self, config):
        super(AwsEnvironment, self).__init__(config)
        # Not suppressing error here on purpose. This is critical if we're on AWS env.
        self.aws_info = AwsInstance()
        self._instance_id = self._get_instance_id()
        self.region = self._get_region()

    def _get_instance_id(self):
        return self.aws_info.get_instance_id()

    def _get_region(self):
        return self.aws_info.get_region()

    def get_auth_users(self):
        if self._is_registered():
            return self._config.get_users()
        else:
            return []