-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
79 lines (68 loc) · 1.79 KB
/
lambda_function.py
File metadata and controls
79 lines (68 loc) · 1.79 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import json
import boto3
import os
import codecs
import sys
import urllib3
import io
http = urllib3.PoolManager()
dynamodb = boto3.resource('dynamodb')
client = boto3.client('dynamodb')
tableName = os.environ['table']
p1 = client.get_item(
Key={
'name': {
'S': 'XSRF-TOKEN',
},
},
TableName='lodge104-keys',
)
p2 = client.get_item(
Key={
'name': {
'S': 'ai_session',
},
},
TableName='lodge104-keys',
)
p3 = client.get_item(
Key={
'name': {
'S': 'OA.LM.Lodge.Auth',
},
},
TableName='lodge104-keys',
)
p4 = client.get_item(
Key={
'name': {
'S': 'ai_user',
},
},
TableName='lodge104-keys',
)
url = "https://lodgemaster-client.oa-bsa.org/api/users"
print(p1)
headers = {
'Cookie': p1['Item']['name']['S'] + '=' + p1['Item']['value']['S'] + '; ' + p2['Item']['name']['S'] + '=' + p2['Item']['value']['S'] + '; ' + p3['Item']['name']['S'] + '=' + p3['Item']['value']['S'] + '; ' + p4['Item']['name']['S'] + '=' + p4['Item']['value']['S'] + ';',
'X-Xsrf-Token': p1['Item']['value']['S']
}
def lambda_handler(event, context):
#get() does not store in memory
try:
table = dynamodb.Table(tableName)
except Exception as error:
print(error)
print("Error loading DynamoDB table. Check if table was created correctly and environment variable.")
#DictReader is a generator; not stored in memory
obj = http.request('GET', url, headers=headers)
body = obj.data
content = json.loads(body)
try:
with table.batch_writer() as batch:
for item in content:
print(item)
batch.put_item(Item=item)
except Exception as error:
print(error)
print("Error executing batch_writer")