示例#1
0
def test_lambda_logger():
    from os import getcwd, environ
    cwd = getcwd()
    import logging
    override_level = environ.get('RDB_LOG_LEVEL')
    if override_level is None:
        # https://AWS CloudWatch log files.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:
        logger = lambda_logger(__name__, cwd)
        assert logger.isEnabledFor(logging.INFO)
        logger.info(
            "This info logger message should be visible in the AWS CloudWatch log files"
        )
        logger = lambda_logger(__name__, cwd, level=logging.INFO)
        assert logger.isEnabledFor(logging.INFO)
        logger.info(
            "This info logger message should be visible in the AWS CloudWatch log files"
        )
        logger = lambda_logger(__name__, cwd, level=logging.ERROR)
        assert logger.isEnabledFor(logging.ERROR)
        logger.info(
            "This info logger message should be visible in the AWS CloudWatch log files"
        )
        assert not logger.isEnabledFor(logging.INFO)
        logger.info(
            "This info logger message should NOT be visible in the AWS CloudWatch log files"
        )
    else:
        print(
            "Test can't be executed properly because RDB_LOG_LEVEL is set which overrides API setting"
        )
示例#2
0
# -*- coding: utf-8 -*-

from os import getcwd

from api.rdb.utils.lambda_logger import lambda_logger

logger = lambda_logger(__name__, getcwd())


def get_sns_attributes(sns_client, username):
    # type: ('boto3.client("sns")', str) -> dict
    logger.info("http_get")
    next_token = ""
    topics = sns_client.list_topics(NextToken=next_token)
    for topic in topics['Topics']:
        parts = topic['TopicArn'].split(":")
        if parts[len(parts) - 1] == username:
            response = sns_client.get_topic_attributes(
                TopicArn=topic['TopicArn'])
            return response['Attributes']
    raise Exception("TopicArn for username: %s not found" % username)