Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions src/content/docs/aws/tutorials/aws-proxy-localstack-extension.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,23 @@ In this tutorial, you will learn how to install the AWS Cloud Proxy extension an

## Prerequisites

- [LocalStack CLI](/aws/getting-started/installation#localstack-cli) with [`LOCALSTACK_AUTH_TOKEN`](/aws/getting-started/auth-token)
- [`lstk`](/aws/getting-started/installation#lstk) with [`LOCALSTACK_AUTH_TOKEN`](/aws/getting-started/auth-token)
- [Docker](https://docs.docker.com/)
- [AWS CLI](https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-install.html) with [`awslocal` wrapper](https://github.com/localstack/awscli-local)
- [AWS CLI](https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-install.html) with [`lstk aws`](/aws/connecting/aws-cli#localstack-aws-cli-lstk-aws)
- [LocalStack account](https://www.localstack.cloud/pricing)
- [AWS Account](https://aws.amazon.com/) with an [`AWS_ACCESS_KEY_ID` & `AWS_SECRET_ACCESS_KEY`](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey)

## Install the AWS Cloud Proxy extension

To install the AWS Cloud Proxy Extension, follow these steps:

1. Launch your LocalStack container using the `localstack` CLI, ensuring that `LOCALSTACK_AUTH_TOKEN` is available in the environment.
1. Launch your LocalStack container using the `lstk` CLI, ensuring that `LOCALSTACK_AUTH_TOKEN` is available in the environment.
2. Visit the [Extensions library](https://app.localstack.cloud/extensions/library) page on the LocalStack Web Application.
![Extensions Library](/images/aws/aws-proxy-tutorial/extensions-library.png)
3. Scroll down to find the **AWS Cloud Proxy** card, then click on the **Install on Instance** button.
![Installing AWS Cloud Proxy extension](/images/aws/aws-proxy-tutorial/installing-aws-proxy-extensions.png)

Once the installation is complete, you will notice that your LocalStack container has restarted with the AWS Cloud Proxy extension successfully installed.
To confirm the installation, execute the following command:

```bash
localstack extensions list
```

```bash title="Output"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Name ┃ Summary ┃ Version ┃ Author ┃ Plugin name ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ localstack-extension-aws-re… │ LocalStack Extension: AWS │ 0.1.11 │ LocalStack Team │ aws-proxy │
│ │ Cloud Proxy │ │ │ │
└──────────────────────────────┴──────────────────────────────┴─────────┴─────────────────┴────────────────┘
```

After verifying the successful installation, you can shut down the LocalStack container to re-start it with additional configuration variables.

## Tutorial: Working with the AWS Cloud Proxy Extension

Expand All @@ -83,15 +67,15 @@ In the following sections, you will create the SQS queue on your local machine a
Begin by running your LocalStack container with the following configuration:

```bash
EXTRA_CORS_ALLOWED_ORIGINS=https://aws-proxy.localhost.localstack.cloud:4566 \
DEBUG=1 \
localstack start
LOCALSTACK_EXTRA_CORS_ALLOWED_ORIGINS=https://aws-proxy.localhost.localstack.cloud:4566 \
LOCALSTACK_DEBUG=1 \
lstk start
```

In the above command:

- The `EXTRA_CORS_ALLOWED_ORIGINS` variable allows the AWS Cloud Proxy extension's web interface to connect with the LocalStack container.
- The `DEBUG` variable enables verbose logging allowing you to see the printed statements from the Lambda function.
- The `LOCALSTACK_EXTRA_CORS_ALLOWED_ORIGINS` variable allows the AWS Cloud Proxy extension's web interface to connect with the LocalStack container.
- The `LOCALSTACK_DEBUG` variable enables verbose logging allowing you to see the printed statements from the Lambda function.

Next, create a file named `testlambda.py` and add the following Python code to it:

Expand All @@ -104,7 +88,7 @@ Execute the following commands to create the local Lambda function:

```bash
(zip testlambda.zip testlambda.py)
awslocal lambda create-function \
lstk aws lambda create-function \
--function-name func1 \
--runtime python3.8 \
--role arn:aws:iam::000000000000:role/r1 --handler testlambda.handler \
Expand All @@ -129,7 +113,7 @@ awslocal lambda create-function \
You can create the local SQS queue named `test-queue` by executing the following command:

```bash
awslocal sqs create-queue --queue-name test-queue
lstk aws sqs create-queue --queue-name test-queue
```

```bash title="Output"
Expand All @@ -152,7 +136,7 @@ Before invoking, set up an event source mapping between the SQS queue and the La
Configure the queue for Lambda using the following command:

```bash
awslocal lambda create-event-source-mapping \
lstk aws lambda create-event-source-mapping \
--function-name func1 \
--batch-size 1 \
--event-source-arn arn:aws:sqs:us-east-1:000000000000:test-queue
Expand All @@ -172,7 +156,7 @@ awslocal lambda create-event-source-mapping \
You can then send a message to the SQS queue to trigger the local Lambda function:

```bash
awslocal sqs send-message \
lstk aws sqs send-message \
--queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/test-queue \
--message-body '{}'
```
Expand Down Expand Up @@ -227,7 +211,7 @@ You will observe the local Lambda function being invoked once again, with corres
2024-03-26T07:45:16.524 DEBUG --- [db58fad602e5] l.s.l.i.version_manager : [func1-ed938bb0-e1ee-41fb-a844-db58fad602e5] END RequestId: ed938bb0-e1ee-41fb-a844-db58fad602e5
```

You can even run the standard `awslocal` commands in your terminal that would query the remote cloud resources, instead of the local ones.
You can even run the standard `lstk aws` commands in your terminal that would query the remote cloud resources, instead of the local ones.

Upon completion, you can click **Disable** on the AWS Cloud Proxy extension web interface to deactivate the proxy configuration.
Additionally, you can delete the remote SQS queue to avoid AWS billing for long-running resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ The full sample application can be found [on GitHub](https://github.com/localsta

### **Prerequisites**

- [LocalStack CLI](/aws/getting-started/installation#localstack-cli) (preferably using `pip`)
- [`lstk`](/aws/getting-started/installation#lstk)
- [Docker](https://docs.docker.com/engine/install/)
- [Terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) or [OpenTofu](https://opentofu.org/docs/intro/install/) and [terraform-local](/aws/connecting/infrastructure-as-code/terraform#install-the-tflocal-wrapper-script)
- [Terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) or [OpenTofu](https://opentofu.org/docs/intro/install/) and [`lstk terraform`](/aws/connecting/infrastructure-as-code/terraform#lstk-terraform)
- Optional for Lambda build & editing: [Maven 3.9.4](https://maven.apache.org/install.html) & [Java 21](https://www.java.com/en/download/help/download_options.html)

- Basic knowledge of AWS services (API Gateway, Lambda, DynamoDB, IAM)
Expand Down Expand Up @@ -72,6 +72,12 @@ export LOCALSTACK_AUTH_TOKEN=<your-auth-token>
docker compose up
```

Given that you've started LocalStack via `docker-compose`, you'll need to configure the `lstk` CLI to contact your container:

```bash
export LSTK_ENDPOINT_URL=http://localhost.localstack.cloud:4566
```

### The Terraform Configuration File

The entire Terraform configuration file for setting up the application stack is available in the same repository at
Expand All @@ -81,12 +87,12 @@ navigate to the project's root folder and use the following commands:

```bash
cd terraform
tflocal init
tflocal plan
tflocal apply --auto-approve
lstk terraform init
lstk terraform plan
lstk terraform apply --auto-approve
```

`tflocal` is a small wrapper script to run Terraform against LocalStack.
`lstk terraform` runs Terraform against LocalStack, using LocalStack endpoints as AWS provider overrides.
The endpoints for all services are configured to point to the
LocalStack API, which allows you to deploy your unmodified Terraform scripts against LocalStack.

Expand Down Expand Up @@ -132,7 +138,7 @@ The Terraform configuration file outputs the REST API ID of the API Gateway.
We can capture that value and use it further to invoke the **`add-product`** Lambda:

```bash
export rest_api_id=$(cd terraform; tflocal output --raw rest_api_id)
export rest_api_id=$(cd terraform; lstk terraform output --raw rest_api_id)
```

The endpoint for the API Gateway is constructed similarly to the one on AWS:
Expand Down Expand Up @@ -186,10 +192,10 @@ The Lambda code and the configurations look fine to him.

### Creating a Cloud Pod

To share this exact environment and issue with Alice, a more experienced colleague, Bob only needs to run a simple `localstack pod` command:
To share this exact environment and issue with Alice, a more experienced colleague, Bob only needs to run a simple `lstk snapshot save` command:

```bash
localstack pod save cloud-pod-product-app
lstk snapshot save pod:cloud-pod-product-app
```

```bash title="Output"
Expand All @@ -201,31 +207,16 @@ Services: sts,iam,apigateway,dynamodb,lambda,s3,cloudwatch,logs

LocalStack provides a remote storage backend that can be used to store the state of your application and share it with your team members.

The Cloud Pods CLI is included in the LocalStack CLI installation, so there's no need for additional plugins to begin using it.
Cloud Pods are managed through the `snapshot` command, included in the `lstk` CLI installation, so there's no need for additional plugins to begin using it.
The `LOCALSTACK_AUTH_TOKEN` needs to be set as an environment variable.

Additionally, there are other commands for managing Cloud Pods included in the CLI:

```bash
localstack pod --help
```

```bash title="Output"
Usage: localstack pod [OPTIONS] COMMAND [ARGS]...

Manage the state of your instance via Cloud Pods.

Options:
-h, --help Show this message and exit.
Additionally, there are other `snapshot` subcommands for managing Cloud Pods:

Commands:
delete Delete a Cloud Pod
list List all available Cloud Pods
load Load the state of a Cloud Pod into the application runtime
remote Manage Cloud Pod remotes
save Create a new Cloud Pod
versions List all available versions for a Cloud Pod
```
- `lstk snapshot save` (alias `lstk save`) — create a new Cloud Pod
- `lstk snapshot load` (alias `lstk load`) — load the state of a Cloud Pod into the application runtime
- `lstk snapshot list` — list all available Cloud Pods
- `lstk snapshot remove` — delete a Cloud Pod
- `lstk snapshot show` — show metadata for a Cloud Pod

### Pulling and Loading the Cloud Pod

Expand All @@ -237,7 +228,7 @@ Now, in a fresh LocalStack instance, Alice can immediately load the Cloud Pod, b
same organization:

```bash
localstack pod load cloud-pod-product-app
lstk snapshot load pod:cloud-pod-product-app
```

```bash title="Output"
Expand Down Expand Up @@ -329,10 +320,10 @@ start to finish.

### Other Remote Options

For organizations with specific data regulations, LocalStack offers multiple remote storage options for Cloud Pods,
For organizations with specific data regulations, LocalStack offers an Amazon S3 storage option,
allowing full control with on-premises storage if needed.
That way, Bob, Alice and Carol could collaborate using an S3 bucket for remote storage.
The Cloud Pods command-line interface enables users to manage these remotes with ease, by following the instructions in the
The `lstk` command-line interface enables users to manage this storage with ease, by following the instructions in the
[documentation](/aws/developer-tools/snapshots/saving-snapshots-to-s3).

## Conclusion
Expand Down
28 changes: 14 additions & 14 deletions src/content/docs/aws/tutorials/ecs-ecr-container-app.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Deploying containers on Elastic Container Service (ECS) clusters using Elastic Container Registry (ECR) and AWS Fargate, with LocalStack"
description: Set up an NGINX web server via Elastic Container Service (ECS) and Elastic Container Registry (ECR) to serve a static website using LocalStack. Learn how you can use CloudFormation templates to declaratively define, create, and deploy your architecture locally with LocalStack's `awslocal` CLI.
description: Set up an NGINX web server via Elastic Container Service (ECS) and Elastic Container Registry (ECR) to serve a static website using LocalStack. Learn how you can use CloudFormation templates to declaratively define, create, and deploy your architecture locally with LocalStack's `lstk aws` CLI.
services:
- ecs
- ecr
Expand All @@ -26,7 +26,7 @@ This tutorial will showcase using LocalStack to set up an NGINX web server to se
## Prerequisites

- [LocalStack for AWS](https://localstack.cloud/pricing/)
- [awslocal](/aws/connecting/aws-cli#localstack-aws-cli-awslocal)
- [`lstk aws`](/aws/connecting/aws-cli#localstack-aws-cli-lstk-aws)
- [Docker](https://docker.io/)
- [curl](https://curl.se/download.html)

Expand All @@ -43,17 +43,17 @@ ENV foo=bar

The `Dockerfile` uses the official `nginx` image from Docker Hub, which allows us to serve the default index page.
Before building our Docker image, we need to start LocalStack and create an ECR repository to push our Docker image.
To start LocalStack with the `LOCALSTACK_AUTH_TOKEN` environment variable, run the following command:
To start LocalStack, run the following command:

```bash
LOCALSTACK_AUTH_TOKEN=<your-auth-token> localstack start -d
lstk start
```

Next, we will create an ECR repository to push our Docker image.
We will use the `awslocal` CLI to create the repository.
We will use the `lstk aws` CLI to create the repository.

```bash
awslocal ecr create-repository --repository-name sample-ecr-repo
lstk aws ecr create-repository --repository-name sample-ecr-repo
```

The output of this command will contain the `repositoryUri` value that we'll need in the next step:
Expand Down Expand Up @@ -360,13 +360,13 @@ Outputs:
To deploy the CloudFormation template we created earlier, use the following command:

```bash
awslocal cloudformation create-stack --stack-name infra --template-body file://templates/ecs.infra.yml
lstk aws cloudformation create-stack --stack-name infra --template-body file://templates/ecs.infra.yml
```

Wait until the stack status changes to `CREATE_COMPLETE` by running the following command:

```bash
awslocal cloudformation wait stack-create-complete --stack-name infra
lstk aws cloudformation wait stack-create-complete --stack-name infra
```

You can also check your deployed stack on the LocalStack Web Application by navigating to the [CloudFormation resource browser](https://app.localstack.cloud/resources/cloudformation/stacks).
Expand Down Expand Up @@ -535,36 +535,36 @@ Resources:
Next, let's deploy the CloudFormation template by running the following command:

```bash
awslocal cloudformation create-stack --stack-name ecs --template-body file://templates/ecs.sample.yml --parameters ParameterKey=ImageUrl,ParameterValue=<REPOSITORY_URI>
lstk aws cloudformation create-stack --stack-name ecs --template-body file://templates/ecs.sample.yml --parameters ParameterKey=ImageUrl,ParameterValue=<REPOSITORY_URI>
```

Replace `<REPOSITORY_URI>` with the URI of the Docker image that you want to deploy.
Wait for the stack to be created by running the following command:

```bash
awslocal cloudformation wait stack-create-complete --stack-name ecs
lstk aws cloudformation wait stack-create-complete --stack-name ecs
```

Now that the ECS service has been deployed successfully, let's access the application endpoint.
First, let's list all the ECS clusters we have deployed in our local environment by running the following command to retrieve the cluster ARN:

```bash
awslocal ecs list-clusters | jq -r '.clusterArns[0]'
lstk aws ecs list-clusters | jq -r '.clusterArns[0]'
```

Save the output of the above command as `CLUSTER_ARN`, as we will use it to list the tasks running in the cluster.
Next, run the following command to list the task ARN:

```bash
awslocal ecs list-tasks --cluster <CLUSTER_ARN> | jq -r '.taskArns[0]'
lstk aws ecs list-tasks --cluster <CLUSTER_ARN> | jq -r '.taskArns[0]'
```

Save the task ARN as `TASK_ARN`.
Let us now list the port number on which the application is running.
Run the following command:

```bash
awslocal ecs describe-tasks --cluster <CLUSTER_ARN> --tasks <TASK_ARN> | jq -r '.tasks[0].containers[0].networkBindings[0].hostPort'
lstk aws ecs describe-tasks --cluster <CLUSTER_ARN> --tasks <TASK_ARN> | jq -r '.tasks[0].containers[0].networkBindings[0].hostPort'
```

Earlier, we configured the application to run on port `45139`, in our `HostPort` parameter.
Expand All @@ -581,7 +581,7 @@ You should see the default index page of the NGINX web server.
## Conclusion

In this tutorial, we have demonstrated how to deploy a containerized service locally using Amazon ECS, ECR, and LocalStack.
We have also shown how you can use CloudFormation templates with the awslocal CLI to deploy your local AWS infrastructure.
We have also shown how you can use CloudFormation templates with the `lstk aws` CLI to deploy your local AWS infrastructure.

With LocalStack, you can easily mount code from your host filesystem into the ECS container, allowing for a quicker debugging loop that doesn't require rebuilding and redeploying the task's Docker image for each change.

Expand Down
Loading