First I will cover the init script and how it is setup
Keep in mind all logs were generated after ALL images, volumes, and containers were pruned from docker. As well as all local volume files deleted.
I really hope this is something silly I’m missing, but I feel like I have done my best to review as much as I can find in the documentation before reaching out for help. Some of the settings in this docker-compose file are planned for future use with another container. (4th volume listed which is referenced in the init script and the use of a docker network for communication between containers)
Here is my docker-compose file:
version: '3.8'
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}"
image: localstack/localstack:2.3.0
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
- AWS_DEFAULT_REGION=us-east-1
- AWS_ACCESS_KEY_ID=foo
- AWS_SECRET_ACCESS_KEY=bar
- DEBUG=1
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "./init-aws.sh:/etc/localstack/init/ready.d/init-aws.sh"
- "./lambda-builder/container-volumes/localstack-volume:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
- "./lambda-builder/container-volumes/shared-files/dist:/lambda-builder/dist"
working_dir: /lambda-builder
env_file:
- ./localstack.env
networks:
- localstack
networks:
localstack:
external: false
driver: bridge
name: localstack
I have confirmed that localstack says the config is valid:
~/Projects/localstack_poc/localstack/poc_function localstack config validate
✔ config valid
As you can see, the init-aws.sh
file is in the correct location as far as it is referenced in the docker-compose file, and it is listed as executable:
~/Projects/localstack_poc/localstack/poc_function ls -la
total 24
drwxr-xr-x@ 6 myusername staff 192 Oct 7 07:55 .
drwxr-xr-x@ 3 myusername staff 96 Oct 6 17:40 ..
-rw-r--r--@ 1 myusername staff 1950 Oct 7 07:44 docker-compose.yml
-rwxr-xr-x@ 1 myusername staff 1251 Oct 7 07:55 init-aws.sh
drwxr-xr-x@ 8 myusername staff 256 Oct 7 07:41 lambda-builder
-rw-r--r--@ 1 myusername staff 40 Oct 7 07:38 localstack.env
~/Projects/localstack_poc/localstack/poc_function
Here are the internals of the init script:
#!/bin/bash
echo "Create Queue"
aws \
sqs create-queue \
--queue-name sqsQueue \
--endpoint-url http://localhost:4566
echo "Create Lambda"
aws \
lambda create-function \
--endpoint-url=http://localhost:4566 \
--function-name lambdaHandler \
--role arn:aws:iam::000000000000:role/lambda-role \
--code S3Bucket=hot-reload,S3Key="/lambda-builder/dist" \
--handler index.handler \
--runtime nodejs18.x \
echo "Bind Queue to Lambda"
aws \
lambda create-event-source-mapping \
--function-name lambdaHandler \
--batch-size 1 \
--event-source-arn "arn:aws:sqs:us-east-1:000000000000:sqsQueue" \
--endpoint-url=http://localhost:4566
I should interject here that I have also reduced this script to only creating an s3 bucket and minimized the docker-compose file to contain exactly what is shown in the docs here: Installation | Docs with the addition of the initialization hook volume, and I get the same results.
Results
The Init scripts discovered: {BOOT: [], START: [], READY: ...
log never shows up.
I have repeatedly stepped through what is recommended here: Initialization Hooks | Docs with no luck.
Here are the logs when standing the container up:
~/Projects/localstack_poc/localstack/poc_function docker-compose up
[+] Building 0.0s (0/0) docker:desktop-linux
[+] Running 1/0
✔ Container localstack_main Created 0.0s
Attaching to localstack_main
localstack_main | LocalStack supervisor: starting
localstack_main | LocalStack supervisor: localstack process (PID 15) starting
localstack_main |
localstack_main | LocalStack version: 2.3.0
localstack_main | LocalStack Docker container id: 602ba73bc407
localstack_main | LocalStack build date: 2023-09-28
localstack_main | LocalStack build git hash: d53f3a49
localstack_main |
localstack_main | 2023-10-07T14:22:49.289 DEBUG --- [ MainThread] stevedore._cache : reading /root/.cache/python-entrypoints/f1cf862cc3589e48f44b8987620df99ac8015595fb5b101c80bca52ba3cadf40
localstack_main | 2023-10-07T14:22:49.289 DEBUG --- [ MainThread] stevedore.extension : found extension EntryPoint(name='register_pickle_patches_runtime', value='localstack_persistence.pickling.__plugins__:register_pickle_patches_runtime', group='localstack.hooks.on_infra_start')
localstack_main | 2023-10-07T14:22:49.289 DEBUG --- [ MainThread] stevedore.extension : found extension EntryPoint(name='register_public_cloudpods_endpoints', value='localstack_persistence.pods.__plugins__:register_public_cloudpods_endpoints', group='localstack.hooks.on_infra_start')
localstack_main | 2023-10-07T14:22:49.290 DEBUG --- [ MainThread] stevedore.extension : found extension EntryPoint(name='register_reset_state_resource', value='localstack_persistence.reset.__plugins__:register_reset_state_resource', group='localstack.hooks.on_infra_start')
localstack_main | 2023-10-07T14:22:49.290 DEBUG --- [ MainThread] stevedore.extension : found extension EntryPoint(name='register_state_load_strategy', value='localstack_persistence.snapshot.__plugins__:register_state_load_strategy', group='localstack.hooks.on_infra_start')
localstack_main | 2023-10-07T14:22:49.381 WARN --- [ MainThread] l.services.internal : Enabling diagnose endpoint, please be aware that this can expose sensitive information via your network.
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] stevedore.extension : found extension EntryPoint(name='register_state_resource', value='localstack_persistence.snapshot.__plugins__:register_state_resource', group='localstack.hooks.on_infra_start')
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] stevedore.extension : found extension EntryPoint(name='register_state_save_strategy', value='localstack_persistence.snapshot.__plugins__:register_state_save_strategy', group='localstack.hooks.on_infra_start')
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : instantiating plugin PluginSpec(localstack.hooks.on_infra_start.register_pickle_patches_runtime = <function register_pickle_patches_runtime at 0xffff8c9b0180>)
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : loading plugin localstack.hooks.on_infra_start:register_pickle_patches_runtime
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : instantiating plugin PluginSpec(localstack.hooks.on_infra_start.register_public_cloudpods_endpoints = <function register_public_cloudpods_endpoints at 0xffff8c9b04a0>)
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : loading plugin localstack.hooks.on_infra_start:register_public_cloudpods_endpoints
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : instantiating plugin PluginSpec(localstack.hooks.on_infra_start.register_reset_state_resource = <function register_reset_state_resource at 0xffff8c9b14e0>)
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : plugin localstack.hooks.on_infra_start:register_reset_state_resource is disabled
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : instantiating plugin PluginSpec(localstack.hooks.on_infra_start.register_state_load_strategy = <function register_state_load_strategy at 0xffff8bfb2b60>)
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : plugin localstack.hooks.on_infra_start:register_state_load_strategy is disabled
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : instantiating plugin PluginSpec(localstack.hooks.on_infra_start.register_state_resource = <function register_state_resource at 0xffff8bfb2a20>)
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : plugin localstack.hooks.on_infra_start:register_state_resource is disabled
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : instantiating plugin PluginSpec(localstack.hooks.on_infra_start.register_state_save_strategy = <function register_state_save_strategy at 0xffff8bfb2e80>)
localstack_main | 2023-10-07T14:22:49.382 DEBUG --- [ MainThread] plugin.manager : plugin localstack.hooks.on_infra_start:register_state_save_strategy is disabled
localstack_main | 2023-10-07T14:22:49.430 DEBUG --- [ MainThread] localstack.utils.threads : start_thread called without providing a custom name
localstack_main | 2023-10-07T14:22:49.431 DEBUG --- [-functhread1] localstack.utils.run : Executing command: whoami
localstack_main | 2023-10-07T14:22:49.436 DEBUG --- [-functhread1] localstack.utils.ssl : Using cached SSL certificate (less than 6hrs since last update).
localstack_main | 2023-10-07T14:22:49.441 INFO --- [-functhread2] hypercorn.error : Running on https://0.0.0.0:4566 (CTRL + C to quit)
localstack_main | 2023-10-07T14:22:49.441 INFO --- [-functhread2] hypercorn.error : Running on https://0.0.0.0:4566 (CTRL + C to quit)
localstack_main | 2023-10-07T14:22:49.735 DEBUG --- [ MainThread] plugin.manager : no extensions found in namespace localstack.aws.provider
localstack_main | Ready.
localstack_main | 2023-10-07T14:22:49.739 DEBUG --- [ MainThread] stevedore.extension : found extension EntryPoint(name='do_run_state_load_all', value='localstack_persistence.snapshot.__plugins__:do_run_state_load_all', group='localstack.hooks.on_infra_ready')
localstack_main | 2023-10-07T14:22:49.740 DEBUG --- [ MainThread] plugin.manager : instantiating plugin PluginSpec(localstack.hooks.on_infra_ready.do_run_state_load_all = <function do_run_state_load_all at 0xffff8bfb2ca0>)
localstack_main | 2023-10-07T14:22:49.740 DEBUG --- [ MainThread] plugin.manager : plugin localstack.hooks.on_infra_ready:do_run_state_load_all is disabled
This is what I see when running an exec (inside container)
# cd /etc/localstack/init/ready.d
# ls -la
total 12
drwxr-xr-x 2 root root 4096 Oct 7 13:51 .
drwxr-xr-x 1 root root 4096 Oct 7 13:51 ..
-rwxr-xr-x 1 root root 1251 Oct 7 13:55 init-aws.sh
#
Errors when manually triggering script
I found out that the status endpoint will actually trigger the script, I am sure that is already known by everyone here, but I will use it to trigger the script so show the data it returns, and the logs from inside the container.
Response from status endpoint:
{
"completed": {
"BOOT": false,
"START": false,
"READY": false,
"SHUTDOWN": false
},
"scripts": [
{
"stage": "READY",
"name": "init-aws.sh",
"state": "UNKNOWN"
}
]
}
Logs when script is triggered by status endpoint:
localstack_main | 2023-10-07T14:27:01.445 DEBUG --- [ asgi_gw_0] l.a.p.service_router : loading service catalog index cache file /var/lib/localstack/cache/service-catalog-2_3_0-1_31_56.pickle
localstack_main | 2023-10-07T14:27:01.465 DEBUG --- [ asgi_gw_0] localstack.runtime.init : Init scripts discovered: {BOOT: [], START: [], READY: [Script(path='/etc/localstack/init/ready.d/init-aws.sh', stage=READY, state=UNKNOWN)], SHUTDOWN: []}
localstack_main | 2023-10-07T14:27:01.466 INFO --- [ asgi_gw_0] localstack.request.http : GET /_localstack/init => 200
localstack_main | 2023-10-07T14:27:01.580 ERROR --- [ asgi_gw_0] l.aws.handlers.logging : exception during call chain
localstack_main | Traceback (most recent call last):
localstack_main | File "/opt/code/localstack/localstack/aws/chain.py", line 90, in handle
localstack_main | handler(self, self.context, response)
localstack_main | File "/opt/code/localstack/localstack/aws/handlers/service_plugin.py", line 36, in __call__
localstack_main | return self.require_service(chain, context, response)
localstack_main | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
localstack_main | File "/opt/code/localstack/localstack/aws/handlers/service_plugin.py", line 44, in require_service
localstack_main | raise NotImplementedError
localstack_main | NotImplementedError
localstack_main | 2023-10-07T14:27:01.582 INFO --- [ asgi_gw_0] l.aws.handlers.service : API for service 's3' not yet implemented or pro feature - please check https://docs.localstack.cloud/references/coverage/ for further information
localstack_main | 2023-10-07T14:27:01.584 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.ListObjects => 501 (InternalFailure)
I can produce more logs if I trigger the script directly in the container:
# cd /etc/localstack/init/ready.d
# ls
init-aws.sh
# bash init-aws.sh
Create Queue
An error occurred (InternalFailure) when calling the CreateQueue operation: API for service 'sqs' not yet implemented or pro feature - please check https://docs.localstack.cloud/references/coverage/ for further information
Create Lambda
An error occurred (InternalFailure) when calling the CreateFunction operation: API for service 'lambda' not yet implemented or pro feature - please check https://docs.localstack.cloud/references/coverage/ for further information
Bind Queue to Lambda
An error occurred (InternalFailure) when calling the CreateEventSourceMapping operation: API for service 'lambda' not yet implemented or pro feature - please check https://docs.localstack.cloud/references/coverage/ for further information
I followed the reference to the coverage docs and I honestly do not think I am trying to create anything that is not covered in the community edition. Even if I was trying to do something that was not covered, I would expect the error to show up when mounting the container into docker.
Any help would be much appreciated, I hope I provided enough information to paint the full picture.
Thanks