def testAwsAccountId(self, patched_boto): """Tests the output of Helpers.aws_account_id.""" patched_boto.return_value.get_caller_identity.return_value = { 'Arn': 'arn:aws:iam::123456654321:user/dliggat' } # Query for the account id; first to generate, second for a cache hit. self.assertEqual(Helpers.aws_account_id(), '123456654321') self.assertEqual(Helpers.aws_account_id(), '123456654321') # We should only ever the boto code once; the account value should # be memoized in the class after the initial invocation. patched_boto.assert_called_once_with('sts') patched_boto.return_value.get_caller_identity.assert_called_once_with()
def testAwsAccountId(self, patched_boto): """Tests the output of Helpers.aws_account_id.""" patched_boto.return_value.describe_security_groups.return_value = { 'SecurityGroups': [{ 'OwnerId': '123456654321' }] } # Query for the account id; first to generate, second for a cache hit. self.assertEqual(Helpers.aws_account_id(), 123456654321) self.assertEqual(Helpers.aws_account_id(), 123456654321) # We should only ever the boto code once; the account value should # be memoized in the class after the initial invocation. patched_boto.assert_called_once_with('ec2') patched_boto.return_value.describe_security_groups.assert_called_once_with( GroupNames=['default'])
def handler(event, context): """Entry point for the Lambda function.""" logger = setup_logging(context.aws_request_id) config = configuration() # Used to differentiate local vs Lambda. if bool(os.getenv('IS_LOCAL')): logger.debug('$IS_LOCAL set; likely running in development') else: logger.debug('No $IS_LOCAL set; likely running in Lambda') logger.info('This is being invoked from AWS account: {0}'.format( Helpers.aws_account_id())) return {'Success': True}
def invoked_function_arn(self): """Simulate the Lambda ARN that comes into the context object. """ return 'arn:aws:lambda:us-east-1:{0}:function:func-name'.format( Helpers.aws_account_id())