CoorpAcademy / serverless-plugins

Collection of serverless plugins :zap:
231 stars 132 forks source link

serverless-offline-sqs doesn't work on a port other than the default (9324) #161

Open gfpacheco opened 3 years ago

gfpacheco commented 3 years ago

I happen to be working on multiple microservices that depend on their own SQS queue. But if I change the port of the ElasticMQ instance the server doesn't start up:

  Unknown Endpoint ---------------------------------------

  UnknownEndpoint: Inaccessible host: `localhost'. This service may not be available in the `us-west-2' region.
      at Request.ENOTFOUND_ERROR (/Users/guilhermepacheco/Workspace/ae/brainbase/vault-backend/node_modules/aws-sdk/lib/event_listeners.js:507:46)
      at Request.callListeners (/Users/guilhermepacheco/Workspace/ae/brainbase/vault-backend/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
      at Request.emit (/Users/guilhermepacheco/Workspace/ae/brainbase/vault-backend/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
      at Request.emit (/Users/guilhermepacheco/Workspace/ae/brainbase/vault-backend/node_modules/aws-sdk/lib/request.js:688:14)
      at ClientRequest.error (/Users/guilhermepacheco/Workspace/ae/brainbase/vault-backend/node_modules/aws-sdk/lib/event_listeners.js:339:22)
      at ClientRequest.<anonymous> (/Users/guilhermepacheco/Workspace/ae/brainbase/vault-backend/node_modules/aws-sdk/lib/http/node.js:96:19)
      at ClientRequest.emit (events.js:315:20)
      at ClientRequest.EventEmitter.emit (domain.js:486:12)
      at Socket.socketErrorListener (_http_client.js:469:9)
      at Socket.emit (events.js:315:20)
      at Socket.EventEmitter.emit (domain.js:486:12)
      at emitErrorNT (internal/streams/destroy.js:106:8)
      at emitErrorCloseNT (internal/streams/destroy.js:74:3)
      at processTicksAndRejections (internal/process/task_queues.js:80:21)

If I change the port on my docker compose file and my custom config to be 9324 everything works just fine, any other port breaks the server.

iainvm commented 3 years ago

I have the same error with the default port number but also inside a docker container

custom config in serverless.yml

  serverless-offline-sqs:
    autoCreate: true    # create queue if not exists
    endpoint: http://sqs:9324
    accessKeyId: root
    secretAccessKey: root

I have my serverless project in 1 container, and the elasticmq in different container (called sqs), both on the same docker network using docker-compose.

docker-compose ps
  Name                Command                  State                    Ports              
-------------------------------------------------------------------------------------------
project    /entrypoint.sh                   Exit 1                                         
sqs        /sbin/tini -- /opt/docker/ ...   Up             0.0.0.0:9324->9324/tcp, 9325/tcp

I still seem to get the error

UnknownEndpoint: Inaccessible host: `localhost'. This service may not be available in the `eu-west-1' region.
      at Request.ENOTFOUND_ERROR (/app/node_modules/serverless-offline-sqs/node_modules/aws-sdk/lib/event_listeners.js:507:46)
      at Request.callListeners (/app/node_modules/serverless-offline-sqs/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
      at Request.emit (/app/node_modules/serverless-offline-sqs/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
      at Request.emit (/app/node_modules/serverless-offline-sqs/node_modules/aws-sdk/lib/request.js:688:14)
      at ClientRequest.error (/app/node_modules/serverless-offline-sqs/node_modules/aws-sdk/lib/event_listeners.js:339:22)
      at ClientRequest.<anonymous> (/app/node_modules/serverless-offline-sqs/node_modules/aws-sdk/lib/http/node.js:96:19)
      at ClientRequest.emit (events.js:315:20)
      at ClientRequest.EventEmitter.emit (domain.js:467:12)
      at Socket.socketErrorListener (_http_client.js:469:9)
      at Socket.emit (events.js:315:20)
      at Socket.EventEmitter.emit (domain.js:467:12)
      at emitErrorNT (internal/streams/destroy.js:106:8)
      at emitErrorCloseNT (internal/streams/destroy.js:74:3)
      at processTicksAndRejections (internal/process/task_queues.js:80:21)
esteveslima commented 3 years ago

I have the same issue, is there any solution to make this work with docker? Using from host machine it's working.

wellermiranda commented 2 years ago

To make it works, you must run an ElasticMQ container: docker run -p 9324:9324 -p 9325:9325 softwaremill/elasticmq-native