-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jon-frame/patch-1
Created alternate function
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from datetime import datetime | ||
import json | ||
import os | ||
import boto3 | ||
|
||
DYNAMODB_TABLE = os.environ['DYNAMODB_TABLE'] | ||
|
||
dynamodb = boto3.resource('dynamodb') | ||
|
||
def lambda_handler(event, context): | ||
# Count items in the Lambda event | ||
no_messages = str(len(event['Records'])) | ||
print("Found " +no_messages +" messages to process.") | ||
|
||
for message in event['Records']: | ||
|
||
print(message) | ||
|
||
# Write message to DynamoDB | ||
table = dynamodb.Table(DYNAMODB_TABLE) | ||
|
||
response = table.put_item( | ||
Item={ | ||
'MessageId': message['messageId'], | ||
'Body': message['body'], | ||
'Timestamp': datetime.now().isoformat() | ||
} | ||
) | ||
print("Wrote message to DynamoDB:", json.dumps(response)) |