def test_get(self):
     aws_clients = AwsClients(logger)
     self.assertEqual(
         'us-east-2',
         aws_clients.get('s3',
                         region='us-east-2')._client_config.region_name)
     self.assertIn(
         'default_sig_version',
         aws_clients._clients['default_role']['us-east-2']['s3'].keys())
     self.assertIn('session',
                   aws_clients._clients['default_role']['us-east-2'].keys())
示例#2
0
from awsclients import AwsClients
from cfnpipeline import CFNPipeline
from logger import Logger

loglevel = 'debug'
logger = Logger(loglevel=loglevel)
logger.info('New Lambda container initialised, logging configured.')
clients = AwsClients(logger)
pipeline_run = CFNPipeline(logger, clients)


def lambda_handler(event, context):
    try:
        logger.config(context.aws_request_id, loglevel=loglevel)
        logger.debug("Handler starting...")
        logger.debug(event)
        pipeline_run.consume_event(event, context, loglevel=loglevel)
        logger.info({'event': 'new_invoke'})
        pipeline_run.deploy_to_s3()
        pipeline_run.put_job_success("S3 bucket updated successfully")
        return

    except Exception as e:
        logger.error("Unhandled exception!", exc_info=1)
        pipeline_run.put_job_failure(str(e))
 def test_get_available_regions(self):
     aws_clients = AwsClients(logger)
     session = boto3.session.Session()
     regions = session.get_available_regions('s3')
     self.assertEqual(regions, aws_clients.get_available_regions('s3'))
 def test___init__(self):
     aws_clients = AwsClients(logger)
     self.assertEqual({"default_role": {}}, aws_clients._clients)
     self.assertEqual(type(Lock()), type(aws_clients._lock))
     self.assertEqual(logger, aws_clients.logger)