Skip to content

Commit

Permalink
Merge pull request #3 from jon-frame/patch-1
Browse files Browse the repository at this point in the history
Created alternate function
  • Loading branch information
jon-frame authored Oct 15, 2020
2 parents 33f15a4 + 6186fe7 commit c037e4a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Triggering-Lambda-from-SQS/sqs_lambda_function.py
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))

0 comments on commit c037e4a

Please sign in to comment.