amazon-web-serviceslocalstack

Error setting up LocalStack through docker-compose with shell script on ready


Trying to setup LocalStack for local development in a project that will be using aws services down the line. Trying to set it up for s3 and sqs, but it fails during setup.

I used this example for docker compose as a template, but still cannot get it to work. https://docs.localstack.cloud/references/init-hooks/#usage-example

Running on a Windows machine, using Docker Desktop.

Here is the log from inside the localstack container.

Log from container

docker-compose.yml

version: '3.8'

name: test

services:
  localstack:
    container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
    image: localstack/localstack:latest
    command: chmod +x /etc/localstack/init/ready.d/init-localstack.sh
    ports:
      - "4566:4566"
    environment:
      - DEBUG=1
    volumes:
      - "./init-localstack.sh:/etc/localstack/init/ready.d/init-localstack.sh"
      - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
     

init-localstack.sh

#!/bin/bash

awslocal s3 mb s3://my-bucket
awslocal sqs create-queue --queue-name my-queue

  1. The file does appear inside the container, and i can run it manually there.
  2. I have tried with #!/bin/sh as well, still gets the same issue.
  3. Both sh and bash is in bin.
  4. I have checked that there are only LF and no CRLF in the shell file
  5. The command in compose file is trying to make sure that execute permission is there.

This seems like such a basic copy paste from the example in the docs, so its odd to me that the shell file cannot be executed.

I know I can get it to work by running commands from within the container manually, but this is not viable at scale, so would want it to work via compose.


Solution

  • I've encountered the same error in starting LocalStack and executing the script only when the CRLF was still set for the init-localstack.sh file.

    I recommend recreating the init-localstack.sh and ensuring that the LF lines endings are correctly set. This can be done in VSCode or Notepad++.

    The SERVICES variable can be disregarded since it is not required. LocalStack initiates services with lazy loading, eliminating the need for this variable.

    LocalStack running Init Script