Skip to content

Commit 90b5b68

Browse files
committed
bug fixes
1 parent 4076434 commit 90b5b68

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
AWS lambda functions
2-
======
1+
## AWS lambda functions
32

4-
### Python 2.7:
53

6-
* kinesis_stream_put_partitioned_s3.py (process data from kinesis stream and put to s3, partitioning the data for Athena)
4+
### python2.7/:
5+
6+
- Name: **kinesis_stream_put_to_s3_athena_partitioning.py**
7+
8+
Description: process data from kinesis stream and put to s3, partitioning the data for Athena
9+
10+
Environment Variables:
11+
S3_BUCKET -> name of the s3 bucket (es. 'bucket')
12+
S3_PATH -> custom path (es. 'test')
13+
14+
Example minimum data:
15+
{
16+
"_id":"asdasdasdasd",
17+
"d":{"sec":1498746471}
18+
}

python 2.7/kinesis_stream_put_partitioned_s3.py renamed to python2.7/kinesis_stream_put_to_s3_athena_partitioning.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from __future__ import print_function
22

3+
import os
34
import base64
45
import json
56
import boto3
67
from datetime import datetime
78

8-
S3_BUCKET = "bcc-s3"
9-
S3_PATH = "test"
9+
S3_BUCKET = os.environ['S3_BUCKET']
10+
S3_PATH = os.environ['S3_PATH']
1011

1112
print('Loading function')
1213

@@ -26,11 +27,11 @@ def lambda_handler(event, context):
2627

2728
date = datetime.fromtimestamp(json_payload['d']['sec'])
2829

29-
filePath = "year=" + str(date.year) + "/month=" + str(date.month) + "/day=" + str(date.day) + "/hour=" + str(date.hour) + "/minute=" + str(date.minute) + "/" + str(json_payload['d']['sec']) + "_" + str(json_payload['_id']) + ".json"
30+
filePath = S3_PATH + "/year=" + str(date.year) + "/month=" + str(date.month) + "/day=" + str(date.day) + "/hour=" + str(date.hour) + "/minute=" + str(date.minute) + "/" + str(json_payload['d']['sec']) + "_" + str(json_payload['_id']) + ".json"
3031

31-
print("path: " + filePath)
32+
#print("path: " + filePath)
3233

33-
r = s3.put_object(ContentType="application/json", Bucket=S3_BUCKET, Key=filePath, Body=str_payload)
34+
s3.put_object(ContentType="application/json", Bucket=S3_BUCKET, Key=filePath, Body=str_payload)
3435

3536

36-
return 'Successfully processed {} records.'.format(len(event['Records']))
37+
return 'Successfully processed {} records.'.format(len(event['Records']))

0 commit comments

Comments
 (0)