Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 2e30bd1

Browse files
Require credentials in init hooks (#1560)
1 parent ce02ebb commit 2e30bd1

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

content/en/references/credentials.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ description: >
66
Credentials for accessing LocalStack AWS API
77
---
88

9-
Like AWS, LocalStack requires access key IDs to be set in all operations.
10-
The choice of access key ID will affect [multi-account namespacing]({{< ref "multi-account-setups" >}}).
11-
Values of secret access keys are currently ignored by LocalStack.
9+
Like AWS, LocalStack requires AWS credentials to be supplied in all API operations.
10+
11+
## Access Key ID
12+
13+
For root accounts, the choice of access key ID affects [multi-account namespacing]({{< ref "multi-account-setups" >}}).
1214

1315
Access key IDs can be one of following patterns:
1416

15-
## Accounts IDs
17+
### Accounts IDs
1618

1719
You can specify a 12-digit number which will be taken by LocalStack as the account ID.
1820
For example, `112233445566`.
1921

20-
## Structured access key ID
22+
### Structured access key ID
2123

2224
You can specify a structured key like `LSIAQAAAAAAVNCBMPNSG` (which translates to account ID `000000000042`).
2325
This must be at least 20 characters in length and must be decodable to an account ID.
@@ -34,7 +36,13 @@ We strongly recommend leaving it on.
3436

3537
Please refer to the [IAM docs]({{< ref "user-guide/aws/iam" >}}) to learn how to create access keys in LocalStack.
3638

37-
## Alphanumeric string
39+
### Alphanumeric string
3840

3941
You can also specify an arbitrary alphanumeric access key ID like `test` or `foobar123`.
40-
In all such cases, the account ID will be evaluated to `000000000000`.
42+
In all such cases, the account ID is evaluated to `000000000000`.
43+
44+
## Secret Access Key
45+
46+
The value of the secret access key are currently ignored by LocalStack.
47+
48+
We recommend using the same value as access key ID or `test`

content/en/references/init-hooks.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ aliases:
77
- /localstack/init-hooks/
88
---
99

10-
## Lifecycle stages and hooks
10+
## Lifecycle Stages and Hooks
1111

1212
LocalStack has four well-known lifecycle phases or stages:
1313
* `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
4141
Scripts are by default in the `UNKNOWN` state once they have been discovered.
4242
The remaining states should be self-explanatory.
4343

44-
### Execution order and script failures
44+
### Execution Order and Script Failures
4545

4646
Scripts are sorted and executed in alphanumerical order.
4747
If you use subdirectories, scripts in parent folders are executed first, and then the directories are traversed in alphabetical order, depth first.
4848
If an init script fails, the remaining scripts will still be executed in order.
4949
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.
5050

51-
## Status endpoint
51+
## Status Endpoint
5252

5353
There is an additional endpoint at `localhost:4566/_localstack/init` which returns the state of the initialization procedure.
5454
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.
@@ -80,7 +80,7 @@ curl -s localhost:4566/_localstack/init | jq .
8080
}
8181
```
8282

83-
### Query individual stages
83+
### Querying Stages
8484

8585
You can also query a specific stage at `localhost:4566/_localstack/init/<stage>`:
8686

@@ -109,12 +109,14 @@ curl -s localhost:4566/_localstack/init/ready | jq .completed
109109

110110
which returns either `true` or `false`.
111111

112-
## Usage example
112+
## Example
113113

114114
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.
116116

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 >}}
118120

119121
To execute aws cli commands when LocalStack becomes ready,
120122
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`:
123125

124126
```bash
125127
#!/bin/bash
128+
129+
export AWS_ACCESS_KEY_ID=000000000000 AWS_SECRET_ACCESS_KEY=000000000000
130+
126131
awslocal s3 mb s3://my-bucket
127132
awslocal sqs create-queue --queue-name my-queue
128133
```
@@ -155,24 +160,20 @@ DOCKER_FLAGS='-v /path/to/init-aws.sh:/etc/localstack/init/ready.d/init-aws.sh'
155160

156161
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" >}}).
157162

158-
### Terraform configuration files as init hooks
163+
### Terraform Files as Init Hooks
159164

160165
Running Terraform configuration files as init hooks requires the installation of a special extension.
161166
For more information on how to manage [LocalStack extensions]({{< ref "user-guide/extensions/" >}}), please refer to the dedicated documentation page,
162167
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).
163168

164-
##### Usage
165-
166169
Start LocalStack with **`EXTENSION_AUTO_INSTALL="localstack-extension-terraform-init"`**.
167170
Mount a **`main.tf`** file into **`/etc/localstack/init/ready.d`**
168171
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.
169172
If one of the init stage directories contain a `main.tf` file, the extension will run `tflocal init` and `tflocal apply` on that directory.
170173

171-
##### Example
172-
173-
main.tf:
174-
175174
```terraform
175+
# main.tf
176+
176177
resource "aws_s3_bucket" "example" {
177178
bucket = "my-tf-test-bucket"
178179
@@ -183,7 +184,7 @@ Environment = "Dev"
183184
}
184185
```
185186

186-
Start LocalStack Pro with mounted main.tf:
187+
Start LocalStack Pro with mounted `main.tf`:
187188

188189
{{< tabpane >}}
189190
{{< tab header="docker-compose.yml" lang="yml" >}}
@@ -252,3 +253,5 @@ If you are having issues with your initialization hooks not being executed, plea
252253

253254
* If your script does not show up in the list of discovered init scripts, please check your Docker volume mount.
254255
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

Comments
 (0)