|
1 | 1 | # SQS Express.js example
|
2 | 2 |
|
3 |
| -This project demonstrates the integration of Amazon Simple Queue Service (SQS) with an Express.js application. It showcases how to effectively manage and process messages from an SQS queue within an Express.js application environment. |
| 3 | +This project demonstrates the integration of Amazon Simple Queue Service (SQS) with an Express.js application on AWS Lambda. It showcases how to effectively manage and process messages from an SQS queue within an serverless Express.js application environment. |
4 | 4 |
|
5 |
| -In this Express.js application integrated with Amazon SQS, there is no explicit code required to poll the SQS queue. The AWS Lambda handles the polling of the SQS queue and Lambda Web Adapter forwards the event payload to the Express.js application. This simplifies the application code and allows developers to focus on processing the event payload rather than managing the queue polling logic. |
| 5 | +In this Express.js application integrated with Amazon SQS, there is no explicit code required to poll the SQS queue. The AWS Lambda handles the polling of the SQS queue and Lambda Web Adapter forwards the event payload to the Express.js application vith a HTTP POST request. This simplifies the application code and allows developers to focus on processing the event payload rather than managing the queue polling logic. |
6 | 6 |
|
7 | 7 | The application can be deployed in an AWS account using the [Serverless Application Model](https://github.com/awslabs/serverless-application-model). The `template.yaml` file in the root folder contains the application definition.
|
8 | 8 |
|
@@ -83,24 +83,19 @@ sam logs --tail --stack-name <replace with your stack name>
|
83 | 83 |
|
84 | 84 | ## Local Test
|
85 | 85 |
|
86 |
| -You can also use SAM CLI for local testing. |
| 86 | +First, start the express.js server locally. |
87 | 87 |
|
88 | 88 | ```shell
|
89 |
| -sam local invoke SqsExpressFunction -e events/sqs.json |
| 89 | +cd app/src |
| 90 | +npm install |
| 91 | +node index.js |
90 | 92 | ```
|
91 | 93 |
|
92 |
| -Here is a sample output from this command. |
| 94 | +Use `curl` to send a POST request to the express.js server. |
93 | 95 |
|
94 | 96 | ```shell
|
95 |
| -Invoking Container created from sqsexpressfunction:v1 |
96 |
| -Building image................. |
97 |
| -Using local image: sqsexpressfunction:rapid-x86_64. |
98 |
| - |
99 |
| -START RequestId: ceaaf9bb-8d8c-42a5-828c-a5d4c8a506f1 Version: $LATEST |
100 |
| -Example app listening at http://localhost:8000 |
101 |
| -Received event: {"Records":[{"messageId":"19dd0b57-b21e-4ac1-bd88-01bbb068cb78","receiptHandle":"MessageReceiptHandle","body":"Hello from SQS!","attributes":{"ApproximateReceiveCount":"1","SentTimestamp":"1523232000000","SenderId":"123456789012","ApproximateFirstReceiveTimestamp":"1523232000001"},"messageAttributes":{},"md5OfBody":"7b270e59b47ff90a553787216d55d91d","eventSource":"aws:sqs","eventSourceARN":"arn:aws:sqs:us-east-1:123456789012:MyQueue","awsRegion":"us-east-1"}]} |
102 |
| -processing message: 19dd0b57-b21e-4ac1-bd88-01bbb068cb78 with body: Hello from SQS! |
103 |
| -END RequestId: ceaaf9bb-8d8c-42a5-828c-a5d4c8a506f1 |
104 |
| -REPORT RequestId: ceaaf9bb-8d8c-42a5-828c-a5d4c8a506f1 Init Duration: 0.10 ms Duration: 117.12 ms Billed Duration: 118 ms Memory Size: 1024 MB Max Memory Used: 1024 MB |
105 |
| -"success" |
| 97 | +curl -X POST -H "Content-Type: application/json" -d @events/sqs.json http://localhost:8080/events |
106 | 98 | ```
|
| 99 | + |
| 100 | +You can also use your favorate IDE debugger to debug your application step by step. |
| 101 | + |
0 commit comments