SST SQS Queue Example

...
  • SQS
  • Lambda
  • CloudWatch Logs
About 2 min

# SST SQS Queue Example

This example derives from the SST SQS Queue example. Since Commandeer allows you to easily test an SQS Queue that is attached to a lambda, we can actually add a message to the SQS queue without having to use an API Gateway endpoint. We have still included the endpoint in the code though to match the example on SST.

In this example we will add a message to the SQS queue and then view the Lambda's invocation CloudWatch logs.


# Commandeer SQS Testing Tool

Below you can see where you can access the tester for this queue on the main dashboard of your account.

SQS Test

Clicking on this item will then take you to the testing tool page.

SQS Tester

# Add Message Section

The first section is the add message. This allows you to add either a JSON object or plain text message to the queue. If you are doing this with a FIFO queue, you will also be able to add the message deduplication id and message group id.

Add Message

# Resources Section

Under this is the Resources section. This will give you a list of related AWS resources that are associated with this test. In our case, we have 4 resources.

  • CloudWatch Log - aws/lambda/dev-commandeer-queue... - this is where all logging from your Lambda goes
  • Lambda - dev-commandeer-consumerHandler... - this is the lambda that is invoked when a message is added to the queue
  • IAM Execution Role - dev-commandeer-queue-... - this is the IAM role that is assumed by the lambda. This is important, especially if the lambda is going to save data to another AWS resource like S3, DynamoDB, or SQS. It will need to be configured with the proper permissions. You normally do this in the SST code
  • SQS Queue - dev-commandeer-queue-Queue - this is the SQS Queue that the message is sent to

Resources

Each of these can be clicked on to view the resource, and make any changes to it.

# Results Section

On the right-hand side is where the results reside. Before you run it, you will see the brief explanation for the tool. Once you add your message, this is where you will see the CloudWatch log information. Below you can see the results of sending a message to the queue.

CloudWatch Logs

If you write out an object to the console, you can also view that, or click the 'show data' toggle, to view them all inline. Below you can see the body of the message that we sent over.

CloudWatch Logs results data

This is also where the resources are shown. You can then simply close any resource, to return back to the results.


# Conclusion

Combining the Commandeer testing tools with the auto-refreshing of Lambda's that SST provides really makes for a magical testing experience. Not to mention how easiy SST makes it to deploy your IaC. (We have used many other IaC tools in the past, and nothing compares to the ease of SST.) You now have a really good way to repeatedly test out adding messages to an SQS queue and viewing the lambda invocation logs.

Last update: July 9, 2022 17:06