forked from reka193/froud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamodb.py
49 lines (35 loc) · 1.52 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from botocore.exceptions import ClientError
import common
import sys
from botocore.exceptions import EndpointConnectionError
def scan_table(table, dynamo):
try:
response = dynamo.scan(TableName=table)
except EndpointConnectionError as error:
print('The requested table could not be reached. \n{}'.format(error))
sys.exit()
except ClientError as error:
if error.response['Error']['Code'] == 'ResourceNotFoundException':
print('Requested table not found.')
print(error)
sys.exit()
else:
common.exception(error, 'Scan dynamodb table failed.')
print('Scanning the table...')
data = response['Items']
while 'LastEvaluatedKey' in response:
response = dynamo.scan(TableName=table, ExclusiveStartKey=response['LastEvaluatedKey'])
data.extend(response['Items'])
return data
def main():
description = "\n[*] Scanner for DynamoDB tables.\n" \
"[*] The results will be saved to $currentpath/dynamodb_scan folder.\n" \
"[*] If a bucket is provided, the results are uploaded to the bucket. \n\n"
arguments, dynamo_client, s3_client = common.init(description, 'dynamodb')
table = str(arguments['tableName'])
data = scan_table(table, dynamo_client)
filenames = common.write_to_file_1000('dynamodb', table, data)
if arguments['bucketName']:
common.bucket_upload(arguments['bucketName'], s3_client, filenames)
if __name__ == '__main__':
main()