-
Notifications
You must be signed in to change notification settings - Fork 14
/
upload.py
43 lines (32 loc) · 881 Bytes
/
upload.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
try:
import unzip_requirements
except ImportError:
pass
import os
import json
import time
import boto3
import tensorflow as tf
import census_data
FILE_DIR = '/tmp/'
BUCKET = os.environ['BUCKET']
def uploadHandler(event, context):
# Download data to local tmp directory
census_data.download(FILE_DIR)
# Upload files to S3
epoch_now = str(int(time.time()))
boto3.Session(
).resource('s3'
).Bucket(BUCKET
).Object(os.path.join(epoch_now,census_data.TRAINING_FILE)
).upload_file(FILE_DIR+census_data.TRAINING_FILE)
boto3.Session(
).resource('s3'
).Bucket(BUCKET
).Object(os.path.join(epoch_now,census_data.EVAL_FILE)
).upload_file(FILE_DIR+census_data.EVAL_FILE)
response = {
"statusCode": 200,
"body": json.dumps({'epoch': epoch_now})
}
return response