localstack / awscli-local

💲 "awslocal" - Thin wrapper around the "aws" command line interface for use with LocalStack
Apache License 2.0
1.09k stars 86 forks source link

awslocal fails with the instance name #69

Closed naquad closed 1 year ago

naquad commented 1 year ago

The setup. I've LocalStack in a docker-compose environment, to configure the services I'm using a side cart pattern:

Here's my docker-compose.yml:

version: "3.8"

services:
  localstack:
    container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}"
    image: localstack/localstack
    ports:
      - "127.0.0.1:4566:4566"            # LocalStack Gateway
      - "127.0.0.1:4510-4559:4510-4559"  # external services port range
      - "127.0.0.1:53:53"                # DNS config (only required for Pro)
      - "127.0.0.1:53:53/udp"            # DNS config (only required for Pro)
      - "127.0.0.1:443:443"              # LocalStack HTTPS Gateway (only required for Pro)
    environment:
      - DEBUG=${DEBUG-}
      - PERSISTENCE=${PERSISTENCE-}
      - LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-}
      - LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY-}  # only required for Pro
      - DOCKER_HOST=unix:///var/run/docker.sock
    volumes:
      - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
  localstack_sidecar:
    image: localstack/localstack
    depends_on:
      - localstack
    entrypoint: >
      awslocal --endpoint-url=http://localstack_main:4566 sqs create-queue --queue-name sample-queue2

The problem is that endpoint-url fails with the "localstack_main" hostname:

check-localstack_sidecar-1  | Invalid endpoint: http://localstack_main:4566

Forcing the container IP and replacing localstack_main with the IP yields the expected result:


check-localstack_sidecar-1  | {
check-localstack_sidecar-1  |     "QueueUrl": "http://192.168.80.2:4566/000000000000/sample-queue2"
check-localstack_sidecar-1  | }
check-localstack_sidecar-1 exited with code 0

P. S. Setting FQDN hostname for the service works too.

dfangl commented 1 year ago

Hi! Hostnames cannot contain an underscore character. This is not a restriction of awscli-local, but a general one. This is the reason why it is (currectly) labeled as an invalid endpoint. Please use the docker compose service name (in this case, localstack) to connect from your sidecar to localstack itself.