Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localstack testcontainer startup script

I'm trying to use localstack testContainer to create an S3 and SQS localy.

Here is my code to create the test container :

    @Container
static LocalStackContainer localStack =
        new LocalStackContainer(DockerImageName.parse("localstack/localstack"))
                .withClasspathResourceMapping("./localstack_bootstrap/sqs_bootstrap.sh",
                        "/etc/localstack/init/ready.d/sqs_bootstrap.sh", BindMode.READ_ONLY)
                .withServices(SQS)
                .withServices(S3)
                .waitingFor(Wait.forLogMessage("Initialized.", 1));

i tryied also with this configuration :

 .withClasspathResourceMapping("./localstack_bootstrap",
                        "/docker-entrypoint-initaws.d/", BindMode.READ_ONLY)

And here is the script i use to create localstack stuff :

c/test/resources/localstack/init.sh
#!/bin/sh
echo "start creating queue"
awslocal sqs create-queue --queue-name test-order-queue
echo "Initialized."

But it seems the script is not executed so i think i'm doing something wrong but i'm not able to figure out it.

ANy help is welcome

like image 391
zouroto Avatar asked Aug 07 '26 15:08

zouroto


1 Answers

please try using the .withFileSystemBind(hostPath, containerPath) method. The key difference is that the classpath is a runtime concept that helps the JVM find classes and resources, while the file system is where your actual files are stored. Here's a working example. Make sure you keep the /etc/localstack/init/ready.d container path. That's where init hooks go in the ready phase: https://docs.localstack.cloud/references/init-hooks/. Hope this helps.

like image 50
Anca G Avatar answered Aug 09 '26 14:08

Anca G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!