Skip to content

Commit fb6d641

Browse files
docs(aws): migrate /aws/connecting section to use lstk (#792)
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 parent c20165c commit fb6d641

11 files changed

Lines changed: 384 additions & 196 deletions

File tree

src/content/docs/aws/connecting/aws-cli.md

Lines changed: 24 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ sidebar:
88

99
## Introduction
1010

11-
The [AWS Command Line Interface (CLI)](https://aws.amazon.com/cli/) is a unified tool for creating and managing AWS services via a command line interface.
12-
All CLI commands applicable to services implemented within [LocalStack](/aws/connecting/aws-cli/) can be executed when operating against LocalStack.
11+
The [AWS Command Line Interface (CLI)](https://aws.amazon.com/cli/) is the standard tool from Amazon for creating and managing AWS services via a command line interface.
12+
Due to LocalStack's compatibility with the AWS APIs, this tool can also access LocalStack's emulated services.
1313

14-
You can use the AWS CLI with LocalStack using either of the following approaches:
14+
You can use the AWS CLI with LocalStack using one or more of the following approaches:
1515

16-
[AWS CLI](#aws-cli)
16+
- [AWS CLI](#aws-cli) - Use the standard `aws` command with hand-crafted configuration options necessary to communicate with LocalStack.
17+
- [LocalStack AWS CLI](#localstack-aws-cli-lstk-aws) - Use the `lstk aws` command to set the configuration options for you.
18+
- [Using AWS CLI from a pre-built container](#using-aws-cli-from-a-pre-built-container) - Use Amazon's pre-built AWS CLI container image instead of installing `aws` locally.
1719

18-
[LocalStack AWS CLI](#localstack-aws-cli-awslocal)
20+
:::note
21+
`lstk aws` supersedes the older [`awslocal` wrapper script](/aws/connecting/infrastructure-as-code/deprecated-wrapper-scripts#awslocal), which is deprecated but still available if you need it.
22+
:::
1923

2024
## AWS CLI
2125

22-
You can install `aws` by using the following command if it's not already installed.
23-
24-
```bash
25-
pip install awscli
26-
```
26+
If you don't already have `aws` (version 2) installed, follow the [official AWS CLI installation instructions](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html).
2727

28-
You can configure the AWS CLI to redirect AWS API requests to LocalStack using two approaches:
28+
Once installed, you can configure the AWS CLI to redirect AWS API requests to LocalStack using two approaches:
2929

3030
- [Configuring an endpoint URL](#configuring-an-endpoint-url)
3131
- [Configuring a custom profile](#configuring-a-custom-profile)
3232

3333
### Configuring an endpoint URL
3434

35-
You can use AWS CLI with an endpoint URL by configuring test environment variables and include the `--endpoint-url=<localstack-url>` flag in your `aws` CLI commands.
35+
You can use AWS CLI with an endpoint URL by configuring environment variables and including the `--endpoint-url=<localstack-url>` flag in your `aws` CLI commands.
3636
For example:
3737

3838
```bash
@@ -80,86 +80,32 @@ aws s3 ls --profile localstack
8080
Alternatively, you can also set the `AWS_PROFILE=localstack` environment variable, in which case the `--profile localstack` parameter can be omitted in the commands above.
8181
:::
8282

83-
## LocalStack AWS CLI (`awslocal`)
83+
## LocalStack AWS CLI (`lstk aws`)
8484

85-
`awslocal` serves as a thin wrapper and a substitute for the standard `aws` command, enabling you to run AWS CLI commands within the LocalStack environment without specifying the `--endpoint-url` parameter or a profile.
85+
`lstk aws` serves as a thin wrapper and a substitute for the standard `aws` command, enabling you to run AWS CLI commands within the LocalStack environment without specifying the `--endpoint-url` parameter or a profile.
8686

8787
### Installation
8888

89-
Install the `awslocal` command using the following command:
90-
91-
```bash
92-
pip install awscli-local[ver1]
93-
```
89+
To make use of `lstk aws`, you must install both the `lstk` CLI and the standard `aws` command from Amazon.
9490

95-
:::tip
96-
97-
The above command installs the most recent version of the underlying AWS CLI version 1 (`awscli`) package.
98-
If you would rather manage your own `awscli` version (e.g., `v1` or `v2`) and only install the wrapper script, you can use the following command:
99-
100-
```bash
101-
pip install awscli-local
102-
```
103-
104-
:::
105-
106-
:::note
107-
108-
Automatic installation of AWS CLI version 2 is currently not supported yet (at the time of writing there is no official pypi package for `v2` available), but the `awslocal` technically also works with AWS CLI v2 (see [this section](#current-limitations) for more details).
109-
:::
91+
1. To install `lstk`, follow the [`lstk` installation instructions](/aws/developer-tools/running-localstack/lstk/#installation).
92+
2. To install `aws`, follow the [official AWS CLI installation instructions](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html).
11093

11194
### Usage
11295

113-
The `awslocal` command shares identical usage with the standard `aws` command.
114-
For comprehensive usage instructions, refer to the manual pages by running `awslocal help`.
115-
116-
```bash
117-
awslocal kinesis list-streams
118-
```
119-
120-
### Configuration
121-
122-
| Variable Name | Description |
123-
| ---------------- | ----------------------------------------------------------------------------------- |
124-
| AWS_ENDPOINT_URL | The endpoint URL to connect to (takes precedence over USE_SSL/LOCALSTACK_HOST) |
125-
| LOCALSTACK_HOST | (deprecated) A variable defining where to find LocalStack (default: localhost:4566) |
126-
| USE_SSL | (deprecated) Whether to use SSL when connecting to LocalStack (default: False) |
127-
128-
### Current Limitations
129-
130-
Please note that there is a known limitation for using the `cloudformation package ...` command with the AWS CLI v2.
131-
The problem is that the AWS CLI v2 is [not available as a package on pypi.org](https://github.com/aws/aws-cli/issues/4947), but is instead shipped as a binary package that cannot be easily patched from `awslocal`.
132-
To work around this issue, you have 2 options:
133-
134-
- Downgrade to the v1 AWS CLI (this is the recommended approach)
135-
- There is an unofficial way to install AWS CLI v2 from sources.
136-
We do not recommend this, but it is technically possible.
137-
Also, you should install these libraries in a Python virtualenv, to avoid version clashes with other libraries on your system:
96+
The `lstk aws` command shares identical usage with the standard `aws` command.
97+
For comprehensive usage instructions, refer to the manual pages by running `lstk aws help`.
13898

13999
```bash
140-
virtualenv .venv
141-
. .venv/bin/activate
142-
pip install https://github.com/boto/botocore/archive/v2.zip https://github.com/aws/aws-cli/archive/v2.zip
100+
lstk aws kinesis list-streams
143101
```
144102

145-
Please also note there is a known limitation for issuing requests using
146-
`--no-sign-request` with the AWS CLI.
147-
LocalStack's routing mechanism depends on
148-
the signature of each request to identify the correct service for the request.
149-
Thus, adding the flag `--no-sign-requests` provokes your request to reach the
150-
wrong service.
151-
One possible way to address this is to use the `awslocal` CLI
152-
instead of AWS CLI.
153-
154-
## AWS CLI v2
155-
156-
Automatic installation of AWS CLI version 2 is currently not supported (at the time of writing there is no official pypi package for v2 available), but the awslocal technically also works with AWS CLI v2 (see this section for more details).
157103

158-
### AWS CLI v2 with Docker and LocalStack
104+
## Using AWS CLI from a pre-built container
159105

160-
By default, the container running [amazon/aws-cli](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-docker.html) is isolated from `0.0.0.0:4566` on the host machine, that means that aws-cli cannot reach localstack through your shell.
106+
As an alternative to installing the `aws` command directly on your local machine, Amazon provides a [pre-built container image with the AWS CLI pre-installed](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-docker.html). This approach is most suitable when working in multi-container environments, rather than single-machine installations. If you take this approach, an extra step is required for communication with LocalStack, also running inside a container.
161107

162-
To ensure that the two docker containers can communicate create a network on the docker engine:
108+
By default, the AWS CLI container is isolated from `0.0.0.0:4566` on the host machine, which means the AWS CLI cannot reach LocalStack. To ensure the two docker containers can communicate create a network on the docker engine:
163109

164110
```bash
165111
docker network create localstack
@@ -175,7 +121,7 @@ networks:
175121
name: 'localstack'
176122
```
177123
178-
Run AWS Cli v2 docker container using this network (example):
124+
Run the AWS CLI v2 docker container using this network (example):
179125
180126
```bash
181127
docker run --network localstack --rm -it amazon/aws-cli --endpoint-url=http://localstack:4566 lambda list-functions

src/content/docs/aws/connecting/infrastructure-as-code/aws-cdk.md

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,43 @@ The AWS Cloud Development Kit (CDK) is an Infrastructure-as-Code (IaC) tool usin
1414

1515
## AWS CDK CLI for LocalStack
1616

17-
`cdklocal` is a thin wrapper script for using the [AWS CDK](https://github.com/aws/aws-cdk) library against local APIs provided by LocalStack.
17+
[`lstk cdk`](/aws/developer-tools/running-localstack/lstk/#cdk) proxies the [AWS CDK](https://github.com/aws/aws-cdk) library against local APIs provided by LocalStack. It requires the AWS CDK CLI version `2.177.0` or newer on your `PATH`.
18+
19+
:::note
20+
`lstk cdk` supersedes the older [`cdklocal` wrapper script](/aws/connecting/infrastructure-as-code/deprecated-wrapper-scripts#cdklocal), which is deprecated but still available if you need it.
21+
:::
1822

1923
### Installation
2024

21-
The `cdklocal` command line is published as an [npm library](https://www.npmjs.com/package/aws-cdk-local):
25+
Install `lstk` by following the [`lstk` installation instructions](/aws/developer-tools/running-localstack/lstk/#installation).
26+
You'll also need the AWS CDK CLI installed separately:
2227

2328
```bash
2429
# Install globally
25-
npm install -g aws-cdk-local aws-cdk
30+
npm install -g aws-cdk
2631

2732
# Verify it installed correctly
28-
cdklocal --version
29-
# e.g. 1.65.5
33+
cdk --version
3034
```
3135

32-
:::note
33-
34-
Using `cdklocal` locally (e.g. within the `node_modules` of your repo instead of globally installed) does not work at the moment for some setups, so make sure you install both `aws-cdk` and `aws-cdk-local` with the `-G` flag.
35-
:::
36-
3736
### Usage
3837

39-
`cdklocal` can be used as a drop-in replacement of where you would otherwise use `cdk` when targeting the AWS Cloud.
38+
`lstk cdk` can be used as a drop-in replacement of where you would otherwise use `cdk` when targeting the AWS Cloud.
4039

4140
```bash
42-
cdklocal --help
41+
lstk cdk --help
4342
```
4443

4544
### Configuration
4645

46+
`lstk cdk`'s only lstk-specific flag (before the CDK action) is `--region <region>` (default `us-east-1`); CDK always targets the default LocalStack account `000000000000`, so there is no `--account` flag.
47+
4748
The following environment variables can be configured:
4849

4950
- `AWS_ENDPOINT_URL`: The endpoint URL (i.e., protocol, host, and port) to connect to LocalStack (default: `http://localhost.localstack.cloud:4566`)
50-
- `LAMBDA_MOUNT_CODE`: Whether to use local Lambda code mounting (via setting `hot-reload` S3 bucket name)
51+
- `AWS_ENDPOINT_URL_S3`: The S3-specific endpoint URL, required alongside `AWS_ENDPOINT_URL` and must include `.s3.` to correctly identify S3 API calls
52+
- `LSTK_CDK_CMD`: Binary to invoke (default `cdk`)
53+
- `AWS_REGION`: Fallback for `--region`
5154

5255
### Example
5356

@@ -62,20 +65,20 @@ The CDK command line ships with a sample app generator to run a quick test for g
6265
```bash
6366
# create sample app
6467
mkdir /tmp/test; cd /tmp/test
65-
cdklocal init sample-app --language=javascript
68+
lstk cdk init sample-app --language=javascript
6669

6770
# bootstrap localstack environment
68-
cdklocal bootstrap
71+
lstk cdk bootstrap
6972

7073
# deploy the sample app
71-
cdklocal deploy
74+
lstk cdk deploy
7275
> Do you wish to deploy these changes (y/n)? y
7376
```
7477

75-
Once the deployment is done, you can inspect the created resources via the [`awslocal`](https://github.com/localstack/awscli-local) command line
78+
Once the deployment is done, you can inspect the created resources via the [`lstk aws`](/aws/developer-tools/running-localstack/lstk/#aws) command line
7679

7780
```bash
78-
awslocal sns list-topics
81+
lstk aws sns list-topics
7982
{
8083
"Topics": [
8184
{
@@ -107,21 +110,5 @@ When this lambda is executed locally from the `/tmp` folder, the package can not
107110

108111
## CDK Version Compatibility
109112

110-
`cdklocal` works with all installed versions of the Node.js `aws-cdk` package.
111-
However, issues exist for `aws-cdk >= 2.177.0`.
112-
113-
For these versions:
114-
115-
- We unset AWS-related environment variables like `AWS_PROFILE` before calling `cdk`.
116-
- We explicitly set `AWS_ENDPOINT_URL` and `AWS_ENDPOINT_URL_S3` to point to LocalStack.
117-
118-
Some environment variables may cause conflicting config, such as wrong region or accidental deploys to real AWS.
119-
To allow specific variables (e.g., `AWS_REGION`), use `AWS_ENVAR_ALLOWLIST`:
120-
121-
```bash
122-
AWS_ENVAR_ALLOWLIST=AWS_REGION,AWS_DEFAULT_REGION AWS_DEFAULT_REGION=eu-central-1 AWS_REGION=eu-central-1 cdklocal ...
123-
```
124-
125-
If you manually set `AWS_ENDPOINT_URL`, it will be used.
126-
You must also set `AWS_ENDPOINT_URL_S3`, and it must include `.s3.` to correctly identify S3 API calls.
127-
See full configuration details [on our configuration docs](https://github.com/localstack/aws-cdk-local?tab=readme-ov-file#configurations).
113+
`lstk cdk` requires AWS CDK CLI `2.177.0` or newer, as noted in [Installation](#installation).
114+
If you're using an older `aws-cdk` version, or the legacy `cdklocal` wrapper script, see [CDK Version Compatibility](/aws/connecting/infrastructure-as-code/deprecated-wrapper-scripts#cdklocal) on the deprecated wrapper scripts page for the relevant environment-variable workarounds.

src/content/docs/aws/connecting/infrastructure-as-code/aws-chalice.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Using LocalStack, you can kick-start your development process, create a new Chal
2020
Start LocalStack inside a Docker container by running:
2121

2222
```bash
23-
localstack start -d
23+
lstk start
2424
```
2525

2626
Install the `chalice-local` package by running:

src/content/docs/aws/connecting/infrastructure-as-code/aws-sam.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ The AWS Serverless Application Model (SAM) is an open-source framework for devel
1212
It uses a simplified syntax to define functions, APIs, databases, and event source mappings.
1313
When you deploy, SAM converts its syntax into AWS CloudFormation syntax, helping you create serverless applications more quickly.
1414

15-
LocalStack can work with SAM using the AWS SAM CLI for LocalStack.
16-
This CLI comes in the form of a `samlocal` wrapper script, which lets you deploy SAM applications on LocalStack.
17-
This guide explains how to set up local AWS resources using the `samlocal` wrapper script.
15+
LocalStack can work with SAM using [`lstk sam`](/aws/developer-tools/running-localstack/lstk/#sam), which lets you deploy SAM applications on LocalStack.
16+
This guide explains how to set up local AWS resources using `lstk sam`.
1817

19-
## `samlocal` wrapper script
18+
## `lstk sam`
2019

21-
`samlocal` is a wrapper for the `sam` command line interface, facilitating the use of SAM framework with LocalStack.
22-
When executing deployment commands like `samlocal ["build", "deploy", "validate", "package"]`, the script configures the SAM settings for LocalStack and runs the specified SAM command.
20+
`lstk sam` proxies the `sam` command line interface, facilitating the use of the SAM framework with LocalStack.
21+
When executing deployment commands like `lstk sam [ build | deploy | validate | package ]`, it configures the SAM settings for LocalStack and runs the specified SAM command.
2322

24-
### Install the `samlocal` wrapper script
23+
:::note
24+
`lstk sam` supersedes the older [`samlocal` wrapper script](/aws/connecting/infrastructure-as-code/deprecated-wrapper-scripts#samlocal), which is deprecated but still available if you need it.
25+
:::
2526

26-
You can install the `samlocal` wrapper script by running the following command:
27+
### Install lstk
2728

28-
```bash
29-
pip install aws-sam-cli-local
30-
```
29+
To use `lstk sam`, install `lstk` by following the [`lstk` installation instructions](/aws/developer-tools/running-localstack/lstk/#installation).
30+
You'll also need the [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) (version `1.95.0` or newer) installed and on your `PATH`.
3131

3232
### Create a new SAM project
3333

3434
You can initialize a new SAM project using the following command:
3535

3636
```bash
37-
samlocal init
37+
lstk sam init
3838
```
3939

4040
Select `1` to create a new SAM application using an AWS Quick Start template.
@@ -50,19 +50,29 @@ Then, enter the project name and press `Enter`.
5050
After initializing the SAM project, enter the project directory and deploy the application using the following command:
5151

5252
```bash
53-
samlocal deploy --guided
53+
lstk sam deploy --guided
5454
```
5555

5656
Enter the default values for the deployment, such as the stack name, region, and confirm the changes.
57-
The `samlocal` wrapper will package and deploy the application to LocalStack.
57+
`lstk sam` will package and deploy the application to LocalStack.
5858

5959
### Configuration
6060

61-
| Environment Variable | Default value | Description |
62-
|------------------------|--------------------------------------------------|-------------------------------------------------------------------------|
63-
| AWS_ENDPOINT_URL | `http://localhost.localstack.cloud:4566` | URL at which the `boto3` client can reach LocalStack |
64-
| EDGE_PORT (Deprecated) | `4566` | Port number under which the LocalStack edge service is available |
65-
| LOCALSTACK_HOSTNAME (Deprecated) | `localhost` | Host under which the LocalStack edge service is available
61+
The `lstk sam` command supports several options and environment variables beyond what is available with the standard `sam` command.
62+
| Option | Default | Description |
63+
|----------------------|-----------------|--------------|
64+
| `--region <region>` | `us-east-1` | Deployment region |
65+
| `--account <id>` | `000000000000` | Target AWS account id (12 digits) |
66+
67+
`lstk sam`-specific flags must appear **before** the SAM action (for example, `lstk sam --region us-west-2 build`)
68+
69+
| Environment Variable | Default value | Description |
70+
|-------------------------|----------------|--------------|
71+
| `AWS_ENDPOINT_URL` | - | Override the auto-resolved LocalStack endpoint |
72+
| `AWS_ENDPOINT_URL_S3` | - | Override the auto-resolved LocalStack S3 endpoint |
73+
| `LSTK_SAM_CMD` | `sam` | Binary to invoke |
74+
| `AWS_REGION` | - | Fallback for `--region` |
75+
| `AWS_ACCESS_KEY_ID` | - | Fallback for `--account` |
6676

6777
## Debugging on VS Code
6878

src/content/docs/aws/connecting/infrastructure-as-code/cloud-custodian.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can use Cloud Custodian with LocalStack by just specifying the Cloud Custodi
1616

1717
## Getting started
1818

19-
This guide is designed for users who are new to Cloud Custodian and assumes basic knowledge of the AWS CLI and our [`awslocal`](https://github.com/localstack/awscli-local) wrapper script.
19+
This guide is designed for users who are new to Cloud Custodian and assumes basic knowledge of the AWS CLI and our [`lstk aws`](/aws/developer-tools/running-localstack/lstk/#aws) command.
2020

2121
Start your LocalStack container using your preferred method.
2222
We will demonstrate how you can spin up an EC2 instance and tag it with the key `Custodian`, and then use Cloud Custodian to stop the instance.
@@ -33,12 +33,12 @@ After installing Cloud Custodian, you can configure a [custom LocalStack profile
3333

3434
### Create an EC2 instance
3535

36-
You can create an EC2 instance using the `awslocal` wrapper script.
36+
You can create an EC2 instance using `lstk aws`.
3737
You can use the [`RunInstances`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html) API to create an EC2 instance.
3838
The following example creates an EC2 instance with the tag `Custodian` (any value):
3939

4040
```bash
41-
awslocal ec2 run-instances \
41+
lstk aws ec2 run-instances \
4242
--image-id ami-ff0fea8310f3 \
4343
--count 1 \
4444
--instance-type t3.nano \

0 commit comments

Comments
 (0)