It will only try to parse the messages from that queue and will try to parse based on the Message Class in the function parse_messages. The ideia is to create a object which will be receiving a ARN_SOURCE variable, the ARN of the SQS queue. For this example, we want to receive messages in the format ofĪ parser must be created to extract the data and put it in a object called Message. First of all, the eventSourceARN, which is the address of the SQS Queue. To create the SQS handler, we first need to undestand how our Lambda will receive the SQS message. The full “main.py” will be Creating the SQS handler The new route retrives all of the messages in the file. When the API receives a SQS message, it writes it down on a. Inside the main.py file, we’ll create another route called “/records”. To create a health check route:Ĭalling the file main.py, Uvicorn can run this API by running the following code: The package has a simple syntax and makes easy to create APIs. We’ll be using FastAPI as the backend tool for this project. As always, the code of the project is on my Github. Python’s library FastAPI will be used to create the API, Docker to containerize it and Poetry will be the library manager. We’ll be using AWS Lambda because it is a serverless framework, in which the idea is you don’t have to worry about servers. txt file and return all the messages when receives a HTTP call to a certain endpoint. As a example of this process, we’ll create a microservice in a AWS Lambda that will act when receive a SQS message. This project will be a example of a system that can receive a SQS message from a client, process it, and give the information to another client. This communication can be through messages and a tool for this communication can be SQS (Simple Queue Service), a messaging service by AWS. In the context of microservices, the communication of them must be fast and realiabe. Trigger a AWS Lambda with a SQS message with Python Introduction
0 Comments
Leave a Reply. |