We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 33f15a4 + 6186fe7 commit c037e4aCopy full SHA for c037e4a
Triggering-Lambda-from-SQS/sqs_lambda_function.py
@@ -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