aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.5k stars 1.17k forks source link

Can't figure out how to get Localstack SQS and SAM Local to play nice #293

Closed zachschultz closed 6 years ago

zachschultz commented 6 years ago

Hello,

I'm running localstack to emulate SQS queues, and I've created a producer queue and a consumer queue, with the urls: http://localhost:4576/queue/producer and http://localhost:4576/queue/consumer-1.

In my lambda function, I initialize the AWS SDK config as so:

    const awsConfig = new AWS.Config({
      accessKeyId: '123',
      secretAccessKey: 'abc',
      endpoint: `${sqsHost}:${sqsPort}`,
      sslEnabled: false,
    });

where sqsHost is docker.for.mac.localhost and sqsPort is 4576, the default for SQS on Localstack. This all works fine, and when I run the listQueues function on the AWS SQS client I see both of my queues' URLs.

However, I cannot send messages to the queues, as the QueueUrl param to the sendMessage function would need to be http://localhost:4576/queue/producer, which doesn't make sense in the docker network the SAM lambda executes in. To remedy this, I've tried to pass in http://docker.for.mac.localhost:4576/queue/producer, which instead causes a 500 Internal Server Error. My guess is that when I try to use localhost, which is the actual QueueUrl, the lambda function breaks because there is nothing to access on the Docker internal network on the SQS port, but when I use docker.for.mac.localhost the SQS client doesn't understand how to find it, because there is no queue with that url.

Any advice on navigating around this issue would be greatly appreciated!

heitorlessa commented 6 years ago

Unrelated to your question but maybe helpful...

I found ElasticMQ to be a much better alternative and works great within a Docker network that I created to run alongside with SAM Local Containers.

https://github.com/adamw/elasticmq

Only issue I had with boto3 was that I wasn’t using the connection params expected but as you mentioned List Queues work it could be something else.

On Mon, 5 Feb 2018 at 08:47, Zach Schultz notifications@github.com wrote:

Hello,

I'm running localstack to emulate SQS queues, and I've created a producer queue and a consumer queue, with the urls: http://localhost:4576/queue/producer and http://localhost:4576/queue/consumer-1.

In my lambda function, I initialize the AWS SDK config as so:

const awsConfig = new AWS.Config({
  accessKeyId: '123',
  secretAccessKey: 'abc',
  endpoint: `${sqsHost}:${sqsPort}`,
  sslEnabled: false,
});

where sqsHost is docker.for.mac.localhost and sqsPort is 4576, the default for SQS on Localstack.

This all works fine, and when I run the listQueues function on the AWS SQS client I see both of my queues. However, I cannot send messages to the queues, as the QueueUrl param shows up as http://localhost:4576/queue/producer, and trying to pass in http://docker.for.mac.localhost:4576/queue/producer instead causes a 500 Internal Server Error. My guess is that when I try to use localhost, which is the actual QueueUrl, the lambda function breaks because there is nothing to access on the Docker internal network on the SQS port, but when I use docker.for.mac.localhost the SQS client doesn't understand how to find it.

Any advice on navigating around this issue would be greatly appreciated!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/awslabs/aws-sam-local/issues/293, or mute the thread https://github.com/notifications/unsubscribe-auth/ADL4BAILPozQfsEIWjQ6_C_FJUq-Q6ipks5tRzBlgaJpZM4R5vzN .

stuart-lang commented 6 years ago

localstack sits on top of elasticmq for it's sqs implementation fyi

zachschultz commented 6 years ago

I am able to use GoAWS by running it in a docker container as the same docker network that I run localstack on, so this issue seems to be specific to how localstack exposes sqs on 4576.

revelfire commented 6 years ago

Bump...same issue here. Looking for a way to tell the executing docker container about the localhost SQS services - bridge network param maybe?

jfuss commented 6 years ago

Love the discussion here but this really isn't the place for this kind of question, our slack channel, aws forums or stackoverflow are to be a better sport for questions like this). There are ways to have docker communicate to your host machine (consult docker docs) or you can run localstack in a docker network with the cli.