Click here to Skip to main content
15,888,454 members
Articles / Hosted Services / AWS
Article

AWS LocalStack - Installing & Configuring Locally on Windows for SQS

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
5 Apr 2024CPOL5 min read 3.5K   5   1
This article explains how to install and configure AWS LocalStack on a Windows machine for SQS (Simple Queue Service).

Contents

What is AWS LocalStack

LocalStack is a popular open-source project that provides a fully functional local AWS cloud stack for testing and development purposes. It allows developers to emulate the AWS cloud environment locally on their machines, enabling them to develop and test AWS applications without incurring any costs associated with the real AWS services.

Key features of LocalStack include:

  1. Emulation of AWS Services: LocalStack provides emulations of various AWS services, including S3 (Simple Storage Service), SQS (Simple Queue Service), SNS (Simple Notification Service), DynamoDB (NoSQL database), Lambda (serverless compute), and many more.
  2. Easy Setup and Configuration: LocalStack is easy to set up and configure, typically requiring only a single command to start the local AWS environment.
  3. Testing and Development: It enables developers to test their applications locally against AWS services, facilitating rapid development and debugging cycles without needing to deploy to the real AWS cloud.
  4. Offline Development: Developers can work offline or in environments without internet connectivity by using LocalStack to simulate the AWS cloud locally.
  5. Customization and Extensibility: LocalStack allows customization and extensibility, enabling developers to add or modify features to better suit their testing and development needs.
  6. Integration with AWS SDKs: LocalStack seamlessly integrates with AWS SDKs and command-line tools, allowing developers to use familiar tools and APIs to interact with the local AWS environment.

Overall, LocalStack is a tool for AWS developers and teams looking to streamline their development workflows, improve productivity, and reduce costs associated with AWS development and testing.

Prerequisites

Start Desktop Docker

Image 1

Download & Run LocalStack Using Docker

You’ll run and connect to LocalStack locally using Docker, which has a LocalStack image. Run the following docker CLI command within a Command prompt:

BAT
docker run --rm -it -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack

Image 2

When you run the docker command for the first time, it may take a couple of minutes to download, but every time after that it will start within seconds.

Configure for Local Environment

Run the following CLI command to edit your configure file:

AWS-CLI
aws configure
  1. Enter test for the Access Secret ID and Access Secret Key
  2. Enter us-east-1 for the Region
  3. Enter json for the Format

Image 3

Edit the config file located at C:\Users\USERNAME\.aws\config, with

  1. endpoint_url = http://localhost:4566

    Image 4

    Image 5

Create Queues

AWS LocalStack has two different types of queues, FIFO (First-In-First-Out) queues and Standard queues. Overview of the differences between FIFO and Standard queues within LocalStack:

  1. Message Ordering:
    • FIFO queues ensure that messages are delivered in the order they are sent. This ordering is maintained even in a distributed system or in cases of high throughput.
    • Standard queues do not guarantee strict message ordering. Messages might be delivered out of order, and ordering is not preserved across multiple message sends.
  2. Deduplication:
    • FIFO queues support exactly-once processing and deduplication of messages. Each message must have a unique message deduplication ID.
    • Standard queues do not provide built-in deduplication mechanisms. You may need to implement deduplication logic in your application if required.
  3. Throughput:
    • FIFO queues have a maximum throughput of 300 transactions (API calls) per second per action (send message, receive message, delete message, etc.).
    • Standard queues support higher throughput compared to FIFO queues, but the exact limits can vary depending on factors such as message size, message retention period, and other attributes.
  4. Attribute Support:
    • FIFO queues support additional attributes such as message group ID and message deduplication ID, which are used for message ordering and deduplication.
    • Standard queues have fewer attributes compared to FIFO queues.
  5. Delay Queues:
    • FIFO queues support message delay queues, allowing you to delay the delivery of messages for a specified period.
    • Standard queues also support message delay queues.
  6. Supported Operations:
    • FIFO queues support all operations available in the real AWS environment, including sending, receiving, deleting messages, changing message visibility, and others.
    • Standard queues support similar operations to FIFO queues, but with potential differences in behaviour and limitations.

To start, with we can create Standard queues, and if there is a need for the messages to be delivered in a certain order, the Standard queues can be deleted and FIFO queues created (they just have an extra switch).

Run the following AWS CLI commands:

AWS-CLI
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name xhibit_DocAndEvents --region us-east-1
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name xhibit_BusinessLayer --region us-east-1
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name xhibit_DocProcessor --region us-east-1
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name xhibit_Notifications --region us-east-1

NB: To create a FIFO queue:

AWS-CLI
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name xhibit_DocAndEvents --region us-east-1 --attributes fifoqueue=true

List Queues

To view the queues, run the following CLI command:

AWS-CLI
aws --endpoint-url=http://sqs.us-east-1.localhost.localstack.cloud:4566 sqs list-queues

Image 6

Publish a Message Using a Command Prompt

To test that your (xhibit_DocAndEvents) queue is running you can send a message using the CLI:

AWS-CLI
aws --endpoint-url=http://sqs.us-east-1.localhost.localstack.cloud:4566 sqs send-message --queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/xhibit_DocAndEvents --message-body "hello world…."

NB: Note the double quotes around the message body contents.

Subscribe to a Queue and Consume Message Using a Command Prompt

To test that you can consume a message from your (xhibit_DocAndEvents) queue, run the following CLI:

AWS-CLI
aws --endpoint-url=http://sqs.us-east-1.localhost.localstack.cloud:4566 sqs receive-message --queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/xhibit_DocAndEvents

Publish and Subscribe windows below:

Image 7

Read the last 10 messages

AWS-CLI
aws --endpoint-url=http://sqs.us-east-1.localhost.localstack.cloud:4566 sqs receive-message --queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/xhibit_DocAndEvents --max-number-of-messages 10

Delete a Message from the Queue

Subscribing to a message will not remove the message form the queue automatically, you or your application must delete the message. Once you have read a message, use the ReceiptHandle property to identify a specific message.

Image 8

Use that handle in the delete message CLI command:

AWS-CLI
aws sqs delete-message --queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/xhibit_DocAndEvents --receipt-handle YWEwODNkNTgtOTk1OS00M2E3LWE1ZjctZGZmOWRiY2E2MjRjIGFybjphd3M6c3FzOnVzLWVhc3QtMTowMDAwMDAwMDAwMDA6eGhpYml0X0RvY0FuZEV2ZW50cyA4MDdiODlkNi1mNDgxLTQ2ZDItOGJmZi1hZmRkY2MyZWJkZjcgMTcxMDk0NzE0Ni42NTkwMTEx

Message removed:

Image 9

Delete a Queue

To delete a queue, run the following CLI command:

AWS-CLI
aws --endpoint-url=http://localhost:4566 sqs delete-queue --queue-url http://localhost:4566/000000000000/xhibit_BusinessLayer

Below, I have listed the queues, deleted a queue and then relisted the queues again:

Image 10

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Ireland Ireland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA5-Apr-24 11:38
professionalȘtefan-Mihai MOGA5-Apr-24 11:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.