From 1405b8b364002e01fb6e33a7fbfe314d0e666be3 Mon Sep 17 00:00:00 2001 From: ssnskar Date: Mon, 6 Nov 2023 11:37:11 +0530 Subject: [PATCH 1/4] Function.py Added the python code snippet of Tutorial: Using Lambda with Amazon SQS as per : https://app.asana.com/0/1203681999313912/1205789652274515 --- integration-sqs-to-lambda/Function.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 integration-sqs-to-lambda/Function.py diff --git a/integration-sqs-to-lambda/Function.py b/integration-sqs-to-lambda/Function.py new file mode 100644 index 0000000..b457b52 --- /dev/null +++ b/integration-sqs-to-lambda/Function.py @@ -0,0 +1,13 @@ +def process_message(message): + try: + print(f"Processed message {message['body']}") + # TODO: Do interesting work based on the new message + except Exception as err: + print("An error occurred") + raise err + +def lambda_handler(event, context): + + for message in event['Records']: + process_message(message) + print("done") \ No newline at end of file From 30f18b423c20b5691f193daeb8fbfdce11335205 Mon Sep 17 00:00:00 2001 From: ssnskar Date: Tue, 7 Nov 2023 19:29:24 +0530 Subject: [PATCH 2/4] Update snippet-data.json Added Python --- integration-sqs-to-lambda/snippet-data.json | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/integration-sqs-to-lambda/snippet-data.json b/integration-sqs-to-lambda/snippet-data.json index c907ab5..56f897f 100644 --- a/integration-sqs-to-lambda/snippet-data.json +++ b/integration-sqs-to-lambda/snippet-data.json @@ -3,7 +3,7 @@ "description": "Sample Amazon SQS function code", "type": "Integration", "services": ["lambda", "sqs"], - "languages": ["Node", ".NET", "TypeScript", "Java"], + "languages": ["Node", ".NET", "TypeScript", "Java","Python"], "tags": [], "introBox": { "headline": "How it works", @@ -63,6 +63,17 @@ "language": "java" } ] + }, + { + "id": "Python", + "title": "Usage Example with Python:", + "description": "Sample Amazon SQS function code using Python without batch item handling.", + "snippets": [ + { + "snippetPath": "Function.py", + "language": "py" + } + ] } ] } @@ -89,6 +100,12 @@ "name": "Girish B", "bio": "Senior Solutions Architect at AWS", "linkedin": "girishbalachandran" + }, + { + "headline": "Python Example Presented by Girish B", + "name": "Sanskar", + "bio": "Cloud Support Engineer at AWS", + "linkedin": "Sanskar05" } ] } From 86644dff2470f663cf6b4de3a13f27e84cc57fc5 Mon Sep 17 00:00:00 2001 From: ssnskar Date: Wed, 8 Nov 2023 07:31:50 +0530 Subject: [PATCH 3/4] Update Function.py Changed the position of the Lambda Handler. --- integration-sqs-to-lambda/Function.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/integration-sqs-to-lambda/Function.py b/integration-sqs-to-lambda/Function.py index b457b52..ee6404c 100644 --- a/integration-sqs-to-lambda/Function.py +++ b/integration-sqs-to-lambda/Function.py @@ -1,3 +1,9 @@ +def lambda_handler(event, context): + + for message in event['Records']: + process_message(message) + print("done") + def process_message(message): try: print(f"Processed message {message['body']}") @@ -5,9 +11,3 @@ def process_message(message): except Exception as err: print("An error occurred") raise err - -def lambda_handler(event, context): - - for message in event['Records']: - process_message(message) - print("done") \ No newline at end of file From aae8b026b7d098c70fcd8455a6832980c73828f5 Mon Sep 17 00:00:00 2001 From: ssnskar Date: Wed, 8 Nov 2023 09:48:05 +0530 Subject: [PATCH 4/4] Update Function.py Removed Blank space. --- integration-sqs-to-lambda/Function.py | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-sqs-to-lambda/Function.py b/integration-sqs-to-lambda/Function.py index ee6404c..fc7d36c 100644 --- a/integration-sqs-to-lambda/Function.py +++ b/integration-sqs-to-lambda/Function.py @@ -1,5 +1,4 @@ def lambda_handler(event, context): - for message in event['Records']: process_message(message) print("done")