You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 7, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: content/en/references/init-hooks.md
+18-15Lines changed: 18 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ aliases:
7
7
- /localstack/init-hooks/
8
8
---
9
9
10
-
## Lifecycle stages and hooks
10
+
## Lifecycle Stages and Hooks
11
11
12
12
LocalStack has four well-known lifecycle phases or stages:
13
13
*`BOOT`: the container is running but the LocalStack runtime has not been started
@@ -41,14 +41,14 @@ A script can be in one of four states: `UNKNOWN`, `RUNNING`, `SUCCESSFUL`, `ERRO
41
41
Scripts are by default in the `UNKNOWN` state once they have been discovered.
42
42
The remaining states should be self-explanatory.
43
43
44
-
### Execution order and script failures
44
+
### Execution Order and Script Failures
45
45
46
46
Scripts are sorted and executed in alphanumerical order.
47
47
If you use subdirectories, scripts in parent folders are executed first, and then the directories are traversed in alphabetical order, depth first.
48
48
If an init script fails, the remaining scripts will still be executed in order.
49
49
A script is considered in `ERROR` state if it is a shell script and returns with a non-zero exit code, or if a Python script raises an exception during its execution.
50
50
51
-
## Status endpoint
51
+
## Status Endpoint
52
52
53
53
There is an additional endpoint at `localhost:4566/_localstack/init` which returns the state of the initialization procedure.
54
54
Boot scripts (scripts placed in `boot.d`) are currently always in the `UNKNOWN` state, since they are executed outside the LocalStack process and we don't know whether they have been successfully executed or not.
A common use case for init hooks is pre-seeding LocalStack with custom state.
115
-
If you have more complex state, [Cloud Pods]({{< ref "user-guide/state-management/cloud-pods" >}}) and [how to auto-load them on startup]({{< ref "user-guide/state-management/cloud-pods#auto-loading-cloud-pods" >}}) may be a good option to look into!
115
+
For example if you want to have a certain S3 bucket or DynamoDB table created when starting LocalStack, init hooks can be very useful.
116
116
117
-
But for simple state, for example if you want to have a certain S3 bucket or DynamoDB table created when starting LocalStack, init hooks can be very useful.
117
+
{{< callout "tip" >}}
118
+
If you have more complex states, [Cloud Pods]({{< ref "user-guide/state-management/cloud-pods" >}}) and [how to auto-load them on startup]({{< ref "user-guide/state-management/cloud-pods#auto-loading-cloud-pods" >}}) may be a good option to look into!
119
+
{{< /callout >}}
118
120
119
121
To execute aws cli commands when LocalStack becomes ready,
120
122
simply create a script `init-aws.sh` and mount it into `/etc/localstack/init/ready.d/`.
@@ -123,6 +125,9 @@ You can use anything available inside the container, including `awslocal`:
Another use for init hooks can be seen when [adding custom TLS certificates to LocalStack]({{< ref "custom-tls-certificates#custom-tls-certificates-with-init-hooks" >}}).
157
162
158
-
### Terraform configuration files as init hooks
163
+
### Terraform Files as Init Hooks
159
164
160
165
Running Terraform configuration files as init hooks requires the installation of a special extension.
161
166
For more information on how to manage [LocalStack extensions]({{< ref "user-guide/extensions/" >}}), please refer to the dedicated documentation page,
162
167
and for more details on running init hooks in development mode, you can check out the [extension repository description](https://github.com/localstack/localstack-extensions/tree/main/terraform-init).
163
168
164
-
##### Usage
165
-
166
169
Start LocalStack with **`EXTENSION_AUTO_INSTALL="localstack-extension-terraform-init"`**.
167
170
Mount a **`main.tf`** file into **`/etc/localstack/init/ready.d`**
168
171
When LocalStack starts up, it will install the extension, which in turn installs Terraform and [`tflocal`](https://github.com/localstack/terraform-local) into the container.
169
172
If one of the init stage directories contain a `main.tf` file, the extension will run `tflocal init` and `tflocal apply` on that directory.
@@ -252,3 +253,5 @@ If you are having issues with your initialization hooks not being executed, plea
252
253
253
254
* If your script does not show up in the list of discovered init scripts, please check your Docker volume mount.
254
255
Most likely the scripts are not properly mounted into the Docker container.
256
+
* Are resources not being created?
257
+
* Ensure that AWS [credentials]({{< ref "references/credentials">}}) are set, e.g. through `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables.
0 commit comments