This example demonstrates how to setup a SQS Standard and send messages through the message body and attributes.
The queue was created by using the queue construct from the Lift plugin.
- Decouple message producers from message consumers.
- This is one way to architect for scale and reliability.
npm install to install all needed packages.
In order to deploy the service run:
sls deployfor deploying with a specific profile (located in ~/.aws/credentials) you can simply use the command:
AWS_PROFILE=YOUR_PROFILE_NAME sls deployfor deploying to the specific stage, let's say staging do:
sls deploy --stage stagingThe expected result should be similar to:
✔ Service deployed to stack aws-node-typescript-sqs-standard-dev (345s)
endpoint: POST - https://XXXXXXXXX.execute-api.REGION.amazonaws.com/sender
functions:
sender: aws-node-typescript-sqs-standard-STAGE-sender (8 MB)
receiver: aws-node-typescript-sqs-standard-dev-receiver (8 MB)
mySimpleQueueWorker: aws-node-typescript-sqs-standard-YOUR-STAGE-mySimpleQueueWorker (8 MB)
updateData: https://sqs.REGION.amazonaws.com/XXXXXXXXXXX/aws-node-typescript-sqs-standard-dev-mySimpleQueue- Send a HTTP POST request to the sender lambda with a JSON payload (The response will be
{"message":"Message placed in the Queue!"}) - To print out the logs of the receiver sqs handler on the terminal.
sls logs -f mySimpleQueueWorker -tIt will look like:serverless logs -f mySimpleQueueWorker Running "serverless" from node_modules START 2022-08-06 16:24:46.022 INFO Message Attributtes --> Attribute Value Here 2022-08-06 16:24:46.023 INFO Message Body --> "test" END Duration: 2.83 ms (init: 155.47 ms) Memory Used: 56 MB
- Alternatively you can check cloudwatch logs.