Skip to content

Commit bd8382a

Browse files
authored
Sqs expressjs example (awslabs#348)
* Add SQS-Expressjs example * Update Dockerfile * Update example README
1 parent 1e8dee7 commit bd8382a

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Please check out [FastAPI with Response Streaming](examples/fastapi-response-str
129129

130130
**AWS_LWA_READINESS_CHECK_MIN_UNHEALTHY_STATUS** - allows you to customize which HTTP status codes are considered healthy and which ones are not
131131

132-
**AWS_LWA_PASS_THROUGH_PATH** - Path to receive events payloads passed through from non-http event triggers. The default is "/events".
132+
**AWS_LWA_PASS_THROUGH_PATH** - Path to receive events payloads passed through from non-http event triggers. The default is "/events".
133133

134134
## Request Context
135135

@@ -161,7 +161,8 @@ Please note that `sam local` starts a Lambda Runtime Interface Emulator on port
161161

162162
## Non-HTTP Event Triggers
163163

164-
The Lambda Web Adapter also supports all non-HTTP event triggers, such as SQS, SNS, S3, DynamoDB, Kinesis, Kafka, EventBridge, and Bedrock Agents. The adapter forwards the event payload to the web application via a path defined by the `AWS_LWA_PASS_THROUGH_PATH` environment variable. By default, this path is set to `/events`. Upon receiving the event payload from the request body, the web application should processes it and returns the results as a JSON response. Please checkout [SQS Express.js](examples/sqs-expressjs) on how to use it.
164+
The Lambda Web Adapter also supports all non-HTTP event triggers, such as SQS, SNS, S3, DynamoDB, Kinesis, Kafka, EventBridge, and Bedrock Agents. The adapter forwards the event payload to the web application via http post to a path defined by the `AWS_LWA_PASS_THROUGH_PATH` environment variable. By default, this path is set to `/events`. Upon receiving the event payload from the request body, the web application should processes it and returns the results as a JSON response. Please checkout [SQS Express.js](examples/sqs-expressjs) on how to use it.
165+
165166

166167
## Examples
167168

examples/sqs-expressjs/README.md

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# SQS Express.js example
22

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.
44

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.
66

77
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.
88

@@ -83,24 +83,19 @@ sam logs --tail --stack-name <replace with your stack name>
8383

8484
## Local Test
8585

86-
You can also use SAM CLI for local testing.
86+
First, start the express.js server locally.
8787

8888
```shell
89-
sam local invoke SqsExpressFunction -e events/sqs.json
89+
cd app/src
90+
npm install
91+
node index.js
9092
```
9193

92-
Here is a sample output from this command.
94+
Use `curl` to send a POST request to the express.js server.
9395

9496
```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
10698
```
99+
100+
You can also use your favorate IDE debugger to debug your application step by step.
101+

0 commit comments

Comments
 (0)