skip to Main Content

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.

2

Answers


  1. Couldn’t help but notice you don’t have any SERVICES environment variable in your docker-compose file, with a comma separated list of all the services you will need enabled. e.g.

    ...
    environment:
      - DEBUG=1
      - SERVICES=sqs,s3
    ...
    

    I don’t see anything else wrong with your set up. Usually, LocalStack reports that a service needs to be enabled, but appears not to be present within your screenshot.

    If you’re still having issues, I could suggest another approach using the aws-cli to create the resources. You can find an example here in my repository. Alternatively, create your own docker image for LocalStack, which will copy the shell script to the same location, you have mounted for your volume.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search