in src/lakeformation_automation/lambda_function.py [0:0]
def lambda_handler(event, context):
app = os.environ['PREFIX']
env = os.environ['ENV']
acc_id = os.environ['ACCOUNT_ID']
region = os.environ['REGION']
arn_pattern = '^arn:(?P<Partition>[^:\n]*):(?P<Service>[^:\n]*):(?P<Region>[^:\n]*):(?P<AccountID>[^:\n]*):(?P<Ignore>(?P<ResourceType>[^:\/\n]*)[:\/])?(?P<Resource>.*)$'
arn_regex = re.compile(arn_pattern)
try:
logger.info('Received {} messages'.format(len(event['Records'])))
logger.info('messages {}'.format(event))
for record in event['Records']:
event_body = json.loads(record['body'])['Records'][0]
message = parse_s3_event(event_body)
s3_content = read_s3_content(message['bucket'], message['key'])
for perm_record in s3_content['Records']:
regex_obj = arn_regex.match(perm_record['Principal'])
if perm_record['AccessType'] == 'grant':
if regex_obj.group(4) != acc_id:
response = publish_sns(generate_db_perm(perm_record))
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
logger.info('DB Perm Record Published to sns {}'.format(s3_content))
time.sleep(3)
response = publish_sns(perm_record)
logger.info('response of actual perm block -- {}'.format(response))
logger.info('Processing Permissions for perm json started --> {} '.format(s3_content))
except Exception as e:
raise e