Skip to content

Commit c037e4a

Browse files
authored
Merge pull request #3 from jon-frame/patch-1
Created alternate function
2 parents 33f15a4 + 6186fe7 commit c037e4a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from datetime import datetime
2+
import json
3+
import os
4+
import boto3
5+
6+
DYNAMODB_TABLE = os.environ['DYNAMODB_TABLE']
7+
8+
dynamodb = boto3.resource('dynamodb')
9+
10+
def lambda_handler(event, context):
11+
# Count items in the Lambda event
12+
no_messages = str(len(event['Records']))
13+
print("Found " +no_messages +" messages to process.")
14+
15+
for message in event['Records']:
16+
17+
print(message)
18+
19+
# Write message to DynamoDB
20+
table = dynamodb.Table(DYNAMODB_TABLE)
21+
22+
response = table.put_item(
23+
Item={
24+
'MessageId': message['messageId'],
25+
'Body': message['body'],
26+
'Timestamp': datetime.now().isoformat()
27+
}
28+
)
29+
print("Wrote message to DynamoDB:", json.dumps(response))

0 commit comments

Comments
 (0)