forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-s3-archive-from-dynamodb.py
32 lines (25 loc) · 1.05 KB
/
delete-s3-archive-from-dynamodb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import boto3
import json
import urllib.parse # pylint: disable=E0611
print('Loading function')
dynamodb_client = boto3.client('dynamodb')
table_name = 'archives.webkit.org'
s3 = boto3.client('s3')
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8') # pylint: disable=E1101
# ex: mac-sierra-x86_64-debug/218331.zip
split_key = key.split('/')
identifier = split_key[0] # mac-sierra-x86_64-debug
filename = split_key[1] # 218331.zip
revision = filename.split('.')[0] # 218331
print ("identifier: " + identifier)
print ("revision: " + revision)
try:
item = {'identifier': {'S': identifier}, 'revision': {'N': revision}}
response = dynamodb_client.delete_item(TableName=table_name, Key=item)
return response
except Exception as e:
print(e)
print('Error deleting item: {}\nfrom database: {}.'.format(item, table_name))
raise e