How to use docker for sqs locally
Asked Answered
C

1

15

I am using AWS SQS in my project. I want to use this for local setup. For SQS, I have added docker_local on my project.

I have updated Dockerfile by adding this as suggested in the link.

FROM java:8

ADD https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-0.13.8.jar /
COPY custom.conf /
ENTRYPOINT ["/usr/bin/java", "-Dconfig.file=custom.conf", "-jar", "/elasticmq-server-0.13.8.jar"]

EXPOSE 9324

CMD ["-help"]

When I execute command docker ps I get this on my screen:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
48e934fc6c43        mysql:5.7.16        "docker-entrypoint.s…"   24 minutes ago      Up 24 minutes       0.0.0.0:10612->3306/tcp   xyz_mysql_1
0af050bd3332        vsouza/sqs-local    "/usr/bin/java -Dcon…"   2 hours ago         Up 2 hours          0.0.0.0:9324->9324/tcp    wizardly_yalow

I have added entry for sqs in my docker-compose.yml file too as:

sqs:
    image: s12v/elasticmq
    ports:
    - "9324:9324".

Now I am unable to understand how to use SQS in my console after going in shell of SQS using this command sudo docker exec -it 0af050bd3332 sh. When I try to list queue it is printing sh: 2: list-queues: not found error.

I have tried lots of things but nothing seems to work.

Closelipped answered 5/7, 2018 at 7:23 Comment(1)
I need to use docker to set up sqs in local envCloselipped
F
11

What your Dockerfile is doing is creating an ElasticMQ server. The latter is a "message queue system" which is compatible with SQS. So, you can use it the same exact way you use SQS, except you have to change the endpoint parameter when using the AWS CLI or SDK.

Let's do an interactive example here:

  1. Run the following Docker command:
$ docker run -p 9324:9324 -p 9325:9325 softwaremill/elasticmq
  1. Now, in another tab, execute the following AWS CLI command (notice the --endpoint parameter pointing to the locally running ElasticMQ server created above):
$ aws --region=us-west-2 --endpoint=http://localhost:9324 sqs list-queues

The result should be empty.

  1. Now try to create a queue:
$ aws --region=us-west-2 --endpoint=http://localhost:9324 sqs create-queue --queue-name=test

{
    "QueueUrl": "http://localhost:9324/000000000000/test"
}
  1. Now execute list-queues again and notice that you have a new queue:
$ aws --region=us-west-2 --endpoint=http://localhost:9324 sqs list-queues

{
    "QueueUrls": [
        "http://localhost:9324/000000000000/test"
    ]
}

Hope this helps!

Rafid

Failure answered 3/6, 2022 at 18:40 Comment(2)
I feel this answer will be complete if you add how to push a message to the queue using aws-cli. eg : aws --region=us-east-1 --endpoint=localhost:9324 sqs send-message --queue-url localhost:9324/queue/test --message-body "{object:[{key:value, anotherkey:anothervalue}]}" --delay-seconds 5x`Horseplay
It is asking for credentials. Unable to locate credentials. You can configure credentials by running "aws configure".Sogdian

© 2022 - 2024 — McMap. All rights reserved.