in force_user_mfa/ForceUserMFA.py [0:0]
def log_event(logData):
"""Summary
Args:
logData (TYPE): Description
Returns:
TYPE: Description
"""
client = boto3.client('dynamodb')
resource = boto3.resource('dynamodb')
# Verify that the table exists
tableExists = False
try:
result = client.describe_table(TableName=DynamoDBtable)
tableExists = True
except:
# Table does not exist, create it
table = resource.create_table(
TableName=DynamoDBtable,
KeySchema=[
{'AttributeName': 'userName', 'KeyType': 'HASH'},
{'AttributeName': 'eventTime', 'KeyType': 'RANGE'}
],
AttributeDefinitions=[
{'AttributeName': 'userName', 'AttributeType': 'S'},
{'AttributeName': 'eventTime', 'AttributeType': 'S'}
],
ProvisionedThroughput={'ReadCapacityUnits': 5, 'WriteCapacityUnits': 5}
)
# Wait for table creation
table.meta.client.get_waiter('table_exists').wait(TableName=DynamoDBtable)
tableExists = True
response = client.put_item(
TableName=DynamoDBtable,
Item={
'userName': {'S': logData['newUserName']},
'userArn': {'S': logData['newUserArn']},
'encryptedSeed': {'S': logData['encryptedSeed']},
'callerUserName': {'S': logData['userName']},
'callerUserArn': {'S': logData['userArn']},
'callerAccessKeyId': {'S': logData['accessKeyId']},
'region': {'S': logData['region']},
'account': {'S': logData['account']},
'eventTime': {'S': logData['eventTime']},
'userAgent': {'S': logData['userAgent']},
'sourceIP': {'S': logData['sourceIP']}
}
)
return 0