### LocalStack Extensions Install Examples Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/developer-tools/running-localstack/localstack-cli.md Install a LocalStack extension by name, from a Git repository, or from a local file distribution. ```bash Usage: localstack extensions install [OPTIONS] NAME Install a LocalStack extension. This command installs a LocalStack extension, where the name can be any valid pip dependency identifier. Additionally, we support the installation of distribution files from disk, which you can indicate by a ``file://`` prefix in the name Example invocations: localstack extensions install localstack-extension-stripe localstack extensions install "git+https://github.com/localstack/localstack-stripe.git#egg=localstack-stripe" localstack extensions install file://./dist/localstack-extension-hello-world-0.1.0.tar.gz localstack extensions install file://. # assumes the current directory is a source distribution Options: -h, --help Show this message and exit. ``` -------------------------------- ### Install Dependencies, Deploy, and Run DMS Tasks Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/dms.mdx Execute make commands to install project dependencies, deploy the CDK stack with DMS resources (replication instances, tasks, endpoints), and start the replication tasks. ```bash # install dependencies make install # deploys cdk stack with all required resources (replication instances, tasks, endpoints) make deploy # starts the tasks make run ``` -------------------------------- ### Setup Python Virtual Environment (Windows) Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/getting-started/quickstart.mdx Create and activate a Python virtual environment, then install development dependencies from requirements-dev.txt. ```shell python -m venv .venv .venv\Scripts\activate pip install -r requirements-dev.txt ``` -------------------------------- ### Start LocalStack in GitHub Actions Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/continuous-integration/github-actions.md Use the setup-localstack action to start a LocalStack instance with a specified image tag and install the awslocal CLI. ```yaml - name: Start LocalStack uses: LocalStack/setup-localstack@v0.2.2 with: image-tag: 'latest' install-awslocal: 'true' ``` -------------------------------- ### Start LocalStack with Podman (Rootfull, podman-docker) Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/config/podman.md Run LocalStack with Podman using the 'podman-docker' package. This method requires root privileges and assumes 'podman-docker' is installed. ```bash sudo sh -c 'DEBUG=1 localstack start --network podman' ``` -------------------------------- ### Setup Python Virtual Environment (macOS/Linux) Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/getting-started/quickstart.mdx Create and activate a Python virtual environment, then install development dependencies from requirements-dev.txt. ```shell python -m venv .venv source .venv/bin/activate pip install -r requirements-dev.txt ``` -------------------------------- ### Travis CI Configuration for LocalStack Pro Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/continuous-integration/travis-ci.md Example Travis CI configuration for using LocalStack Pro, including installing the CLI, pulling the Pro image, starting LocalStack with a CI Auth Token, and waiting for readiness. ```yaml before_install: # Install the LocalStack CLI and awslocal - python -m pip install localstack awscli-local[ver1] # Make sure to pull the latest version of the image - docker pull localstack/localstack-pro # Start LocalStack in the background - localstack start -d # Wait 30 seconds for the LocalStack container to become ready before timing out - echo "Waiting for LocalStack startup..." - localstack wait -t 30 - echo "Startup complete" ``` -------------------------------- ### Terraform Init Hook Log Output Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/config/initialization-hooks.mdx Example log output showing the Terraform init hook extension installing Terraform and applying the configuration. ```bash 2024-06-26T20:36:19.946 INFO --- [ady_monitor)] l.extension : Applying terraform project from file /etc/localstack/init/ready.d/main.tf 2024-06-26T20:36:19.946 DEBUG --- [ady_monitor)] localstack.utils.run : Executing command: ['tflocal', '-chdir=/etc/localstack/init/ready.d', 'init', '-input=false'] 2024-06-26T20:36:26.864 DEBUG --- [ady_monitor)] localstack.utils.run : Executing command: ['tflocal', '-chdir=/etc/localstack/init/ready.d', 'apply', '-auto-approve'] ``` -------------------------------- ### Start Docker Compose Environment Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/opensearch.mdx Command to launch the Docker Compose setup for OpenSearch and LocalStack. ```bash docker-compose up -d ``` -------------------------------- ### LocalStack Startup Output Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/getting-started/installation.mdx This is an example of the output you will see when LocalStack successfully starts. It includes the CLI version, profile, app URL, and status messages for environment preparation, container configuration, and startup. ```bash __ _______ __ __ / / ____ _________ _/ / ___// /_____ ______/ /__ / / / __ \/ ___/ __ \`/ /\__ \/ __/ __ andomIndex: 1248 / /___/ /_/ / /__/ /_/ / /___/ / /_/ /_/ / /__/ ,< /_____/\____/\___/\__,_/_//____/\__/\__,_/\___/_/|_| - LocalStack CLI 1.0.0 - Profile: default - App: https://app.localstack.cloud [12:47:13] starting LocalStack in Docker mode 🐳 localstack.py:494 preparing environment bootstrap.py:1240 configuring container bootstrap.py:1248 starting container bootstrap.py:1258 [12:47:15] detaching bootstrap.py:1262 ``` -------------------------------- ### S3 Tables Setup Script Output Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/snowflake/tutorials/s3-tables-iceberg-integration.md Example output from the Python script, confirming table creation, data insertion, and listing tables in the namespace. ```bash Created table: my_namespace.customer_orders Inserted sample data into table Tables in namespace: [('my_namespace', 'customer_orders')] ``` -------------------------------- ### Start LocalStack with a Specific Profile Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/config/configuration.md Demonstrates how to start LocalStack using a specific configuration profile ('dev.env' in this case) via the CLI. This allows for loading predefined environment variables for a particular setup. ```bash python -m localstack.cli.main --profile=dev start ``` -------------------------------- ### VNC Output Example Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/ec2.mdx Example output showing the VNC display address. ```bash 127.0.0.1:0 ``` -------------------------------- ### Initialization Status JSON Response Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/config/initialization-hooks.mdx Example JSON response from the `/_localstack/init` endpoint, showing the completion status of different initialization stages (BOOT, START, READY, SHUTDOWN) and the state of individual scripts. ```json { "completed": { "BOOT": false, "START": true, "READY": true, "SHUTDOWN": false }, "scripts": [ { "stage": "BOOT", "name": "booting.sh", "state": "UNKNOWN" }, { "stage": "READY", "name": "pre_seed.py", "state": "SUCCESSFUL" } ] } ``` -------------------------------- ### Install wscat Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/appsync.mdx Install the `wscat` tool globally using npm, which is used for creating WebSocket connections. ```bash npm install -g wscat ``` -------------------------------- ### Set Up Python Virtual Environment and Install Dependencies Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/serverless-quiz-app.mdx Create a Python virtual environment and install the necessary development dependencies. ```bash python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r tests/requirements-dev.txt ``` -------------------------------- ### Clone Webpack Example Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/developer-tools/lambda-tools/hot-reloading.mdx Clone the LocalStack Webpack example repository to get started with Lambda hot reloading. ```bash cd /tmp git clone https://github.com/localstack-samples/localstack-pro-samples.git cd lambda-hot-reloading/lambda-typescript-webpack ``` -------------------------------- ### Create Sample Web Resources Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/azure/services/resource-graph.mdx Create an App Service plan and a Web App within the specified resource group. These resources will be used for demonstrating Resource Graph queries. ```bash az appservice plan create \ --name asp-doc81 \ --resource-group rg-resourcegraph-demo \ --location westeurope \ --sku F1 az webapp create \ --name ls-app-doc81 \ --resource-group rg-resourcegraph-demo \ --plan asp-doc81 \ --runtime "PYTHON:3.11" ``` -------------------------------- ### Clone DMS Kinesis RDS MariaDB Sample Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/dms.mdx Clone the sample repository to get started with a DMS setup showcasing MariaDB source and Kinesis target. ```bash git clone https://github.com/localstack-samples/sample-dms-kinesis-rds-mariadb.git ``` -------------------------------- ### CircleCI Setup for Snowflake Emulator Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/snowflake/integrations/continuous-integration.mdx Set up CircleCI to install LocalStack, pull the Snowflake emulator image, start the emulator, and wait for its startup. This configuration uses a machine executor with an Ubuntu image. ```yaml version: 2.1 orbs: python: circleci/python@2.0.3 jobs: example-job: machine: image: ubuntu-2004:2022.04.1 steps: - checkout - run: name: Start LocalStack command: | pip3 install localstack docker pull localstack/snowflake localstack start --stack snowflake -d echo "Waiting for LocalStack startup..." localstack wait -t 30 echo "Startup complete" workflows: version: 2 build: jobs: - example-job ``` -------------------------------- ### Start LocalStack and Deploy Infrastructure Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/terraform-shipment-app-guide.mdx Start LocalStack in the background and use the provided Makefile to deploy all infrastructure components. ```bash localstack auth set-token localstack start -d make deploy ``` -------------------------------- ### LocalStack CLI Start Command Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/developer-tools/running-localstack/localstack-cli.md Start LocalStack using the 'start' command. Supports various options for Docker, detached mode, environment variables, and more. ```bash Usage: localstack start [OPTIONS] Options: --docker Start LocalStack in a docker container [default] --host Start LocalStack directly on the host (DEPRECATED) --no-banner Disable LocalStack banner -d, --detached Start LocalStack in the background --network TEXT The container network the LocalStack container should be started in. By default, the default docker bridge network is used. -e, --env TEXT Additional environment variables that are passed to the LocalStack container -p, --publish TEXT Additional port mappings that are passed to the LocalStack container -v, --volume TEXT Additional volume mounts that are passed to the LocalStack container --host-dns Expose the LocalStack DNS server to the host using port bindings. -s, --stack TEXT Use a specific stack with optional version. Examples: [localstack:4.5, snowflake] -h, --help Show this message and exit. ``` -------------------------------- ### LocalStack Container Setup in GitLab CI Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/continuous-integration/gitlab-ci.md Set up LocalStack as a Docker container within a GitLab CI job. This approach installs necessary tools and starts LocalStack directly in the job's environment. ```yaml image: docker:latest stages: - job job: stage: job variables: ... DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566" ... services: - name: docker:dind alias: docker command: ["--tls=false"] before_script: - apk update - apk add gcc musl-dev linux-headers py3-pip python3 python3-dev - python3 -m pip install localstack awscli script: - docker pull localstack/localstack:latest - dind_ip="$(getent hosts docker | cut -d' ' -f1)" - echo "${dind_ip} localhost.localstack.cloud " >> /etc/hosts - DOCKER_HOST="tcp://${dind_ip}:2375" localstack start -d ``` -------------------------------- ### Initialize a new Gradle project Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/app-frameworks/spring-cloud-function.mdx Use this command to set up a new project structure with Gradle. Ensure Gradle is installed on your system. ```bash gradle init ``` -------------------------------- ### Install LocalStack with Default Configuration Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/enterprise/kubernetes/deploy-helm-chart.md Install the LocalStack Helm chart with its default configuration values. ```bash helm install localstack localstack/localstack ``` -------------------------------- ### GitHub Actions Setup for Snowflake Emulator Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/snowflake/integrations/continuous-integration.mdx Configure GitHub Actions to pull the Snowflake emulator image, install LocalStack, start the emulator, and wait for it to become available. Ensure the LOCALSTACK_AUTH_TOKEN secret is set in your repository. ```yaml name: LocalStack Test on: [ push, pull_request ] jobs: localstack-action-test: name: 'Test LocalStack GitHub Action' runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Start Snowflake emulator run: docker pull localstack/snowflake:latest pip install localstack localstack start --stack snowflake -d echo "Waiting for LocalStack startup..." localstack wait -t 15 echo "Startup complete" env: LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }} ``` -------------------------------- ### Start React Frontend Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/terraform-shipment-app-guide.mdx Navigate to the frontend directory and start the React development server. Access the UI at http://localhost:3000. ```bash cd shipment-list-frontend npm start ``` -------------------------------- ### Install Serverless-LocalStack Plugin Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/connecting/infrastructure-as-code/serverless-framework.md Command to install the `serverless-localstack` plugin as a development dependency. ```bash npm install -D serverless-localstack ``` -------------------------------- ### Run Sample Application Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/sagemaker.mdx Execute the main Python script to start the SageMaker inference sample application after setting up LocalStack. ```bash python3 main.py ``` -------------------------------- ### Travis CI Job Configuration with LocalStack Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/continuous-integration/travis-ci.md Example Travis CI configuration to install LocalStack CLI, pull the Docker image, start LocalStack in detached mode, wait for it to be ready, and then run tests using awslocal. ```yaml language: python services: - docker python: - "3.8" before_install: # Install the LocalStack CLI and awslocal - python -m pip install localstack awscli-local[ver1] # Make sure to pull the latest version of the image - docker pull localstack/localstack # Start LocalStack in the background - localstack start -d # Wait 30 seconds for the LocalStack container to become ready before timing out - echo "Waiting for LocalStack startup..." - localstack wait -t 30 - echo "Startup complete" script: # Test LocalStack by creating a new S3 bucket (and verify that it has been created by listing all buckets) - awslocal s3 mb s3://test - awslocal s3 ls - echo "Execute your tests here :)" ``` -------------------------------- ### Start LocalStack with Specific Config Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/developer-tools/running-localstack/lstk.mdx Specify a custom configuration file to use when starting LocalStack. ```bash lstk --config /path/to/config.toml start ``` -------------------------------- ### GitLab CI Setup for Snowflake Emulator Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/snowflake/integrations/continuous-integration.mdx Configure GitLab CI to use a Docker-in-Docker service, install necessary packages and LocalStack, pull the Snowflake emulator image, start the emulator, and wait for it to be ready. It also configures the Docker host and adds a localhost entry for the emulator. ```yaml image: docker:20.10.16 stages: - test test: stage: test variables: DOCKER_HOST: tcp://docker:2375 DOCKER_TLS_CERTDIR: "" LOCALSTACK_AUTH_TOKEN: $LOCALSTACK_AUTH_TOKEN services: - name: docker:20.10.16-dind alias: docker command: ["--tls=false"] before_script: - apk update - apk add gcc musl-dev linux-headers py3-pip python3 python3-dev - python3 -m pip install localstack script: - docker pull localstack/snowflake:latest - dind_ip="$(getent hosts docker | cut -d' ' -f1)" - echo "${dind_ip} localhost.localstack.cloud " >> /etc/hosts - DOCKER_HOST="tcp://${dind_ip}:2375" localstack start --stack snowflake -d - localstack wait -t 15 ``` -------------------------------- ### Provider Status Output Example Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/connecting/infrastructure-as-code/crossplane.md Example output showing the status of installed Crossplane AWS providers. ```text NAME INSTALLED HEALTHY PACKAGE AGE upbound-provider-family-aws True True xpkg.upbound.io/upbound/provider-family-aws:v0.40.0 2m provider-aws-s3 True True xpkg.upbound.io/upbound/provider-aws-s3:v0.40.0 2m provider-aws-sqs True True xpkg.upbound.io/upbound/provider-aws-sqs:v0.40.0 2m ``` -------------------------------- ### Starting LocalStack and Running Application Container (Docker) Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/networking/accessing-endpoint-url.mdx This Docker command sequence demonstrates creating a custom network, starting LocalStack, inspecting its IP, and then running your application container with the correct DNS settings. ```bash # start localstack docker network create ls docker run --rm -it --network ls --name localstack-main localstack/localstack[-pro] # get the ip address of the LocalStack container docker inspect localstack-main | \ jq -r '.[0].NetworkSettings.Networks | to_entries | .[].value.IPAddress' # prints 172.27.0.2 # run your application container docker run --rm -it --dns 172.27.0.2 --network ls ``` -------------------------------- ### Start AppConfig Deployment Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/appconfig.mdx Initiates a deployment of a configuration version to a target environment using a specified deployment strategy. Ensure all IDs and versions are correct. ```bash awslocal appconfig start-deployment \ --application-id 400c285 \ --environment-id 3695ea3 \ --deployment-strategy-id f2f2225 \ --configuration-profile-id 7d748f9 \ --configuration-version 1 \ --description "My application deployment" ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/rds-database-initialization.mdx Installs the necessary Node.js dependencies for the project. This command should be run after cloning the repository. ```bash npm install ``` ```bash make install ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/serverless-quiz-app.mdx Clone the sample repository for the serverless quiz app and navigate into the project directory. ```bash git clone https://github.com/localstack-samples/sample-serverless-quiz-app.git cd sample-serverless-quiz-app ``` -------------------------------- ### Start Transaction and Get Current Transaction ID Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/snowflake/features/transaction-management.md Starts a new named transaction and then retrieves its ID using CURRENT_TRANSACTION(). ```sql START TRANSACTION NAME mytxn2; SELECT CURRENT_TRANSACTION() AS txn; ``` -------------------------------- ### Install QEMU/KVM on Debian/Ubuntu Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/ec2.mdx Installs necessary packages for QEMU/KVM on Debian or Ubuntu-based systems. Ensure you have sudo privileges. ```bash sudo apt install -y qemu-kvm libvirt-daemon-system ``` -------------------------------- ### Initialize Project and Install Dependencies Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/elb-load-balancing.mdx Initializes a Node.js project and installs necessary Serverless plugins for LocalStack integration and deployment bucket management. ```bash npm init -y npm install -D serverless serverless-localstack serverless-deployment-bucket ``` -------------------------------- ### Install Testcontainers LocalStack Module (Go) Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/testing/testcontainers.mdx Install the Testcontainers LocalStack module for Go using the go get command. ```go go get github.com/testcontainers/testcontainers-go/modules/localstack ``` -------------------------------- ### Start LocalStack with Native Runner Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/continuous-integration/codebuild.md This snippet shows how to start LocalStack using the native runner in CodeBuild. It installs necessary tools, pulls the latest LocalStack image, and starts the emulator in detached mode. ```yaml version: 0.2 ... phases: pre_build: commands: - pip3 install localstack awscli - docker pull public.ecr.aws/localstack/localstack:latest - localstack start -d - localstack wait -t 30 ``` -------------------------------- ### Install Specific LocalStack Operator Version Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/enterprise/kubernetes/kubernetes-operator.mdx Apply the published manifests for a specific version of the Operator controller from GitHub. Example shows installation of v0.4.0. ```bash # Example: install v0.4.0 kubectl apply -f https://github.com/localstack/localstack-operator/releases/v0.4.0/download/controller.yaml ``` -------------------------------- ### Set up SES Client and Manage Emails Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/localstack-sdks/python-sdk.md Initializes an SES client, verifies an email address, sends a raw email, retrieves message IDs, and discards all SES messages. ```python import boto3 import localstack.sdk.aws client = localstack.sdk.aws.AWSClient() # Initialize SES client ses_client = boto3.client( "ses", endpoint_url=client.configuration.host, region_name="us-east-1", aws_access_key_id="test", aws_secret_access_key="test", ) # Verify email address email = "user@example.com" ses_client.verify_email_address(EmailAddress=email) # Send a raw email raw_message_data = f"From: {email}\nTo: recipient@example.com\nSubject: test\n\nThis is the message body.\n\n" ses_client.send_raw_email(RawMessage={"Data": raw_message_data}) # Get and print SES message IDs messages = client.get_ses_messages() for msg in messages: print("Message ID:", msg.id) # Discard all SES messages client.discard_ses_messages() ``` -------------------------------- ### Start LocalStack with GitHub Actions Runner Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/continuous-integration/codebuild.md This snippet demonstrates starting LocalStack within a GitHub Actions runner in CodeBuild. It pulls the image, tags it, and uses the setup-localstack action to start the emulator with AWS CLI installed. ```yaml version: 0.2 phases: pre_build: steps: - run: docker pull public.ecr.aws/localstack/localstack:latest - run: docker image tag public.ecr.aws/localstack/localstack-localstack:latest localstack/localstack:latest - name: Start LocalStack uses: LocalStack/setup-localstack@v0.2.2 with: image-tag: 'latest' install-awslocal: 'true' ``` -------------------------------- ### Install Serverless Framework Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/elb-load-balancing.mdx Installs the Serverless framework globally using npm. This is the first step to managing serverless applications. ```bash npm install -g serverless ``` -------------------------------- ### Automate Extension Installation with Environment Variable Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/extensions/managing-extensions.mdx Use the EXTENSION_AUTO_INSTALL environment variable in your docker-compose file to specify a comma-separated list of extensions to be installed automatically when LocalStack starts. ```yaml services: localstack: container_name: 'localstack-main' image: localstack/localstack-pro ports: - '127.0.0.1:4566:4566' - '127.0.0.1:4510-4559:4510-4559' environment: - LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?} - DEBUG=1 - EXTENSION_AUTO_INSTALL=localstack-extension-mailhog,localstack-extension-httpbin volumes: - './volume:/var/lib/localstack' - '/var/run/docker.sock:/var/run/docker.sock' ``` -------------------------------- ### Create and Deploy a Sample CDK App Locally Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/connecting/infrastructure-as-code/aws-cdk.md Generate a sample CDK application, bootstrap the LocalStack environment, and deploy the application. This demonstrates a typical workflow for developing CDK apps with LocalStack. ```bash # create sample app mkdir /tmp/test; cd /tmp/test cdklocal init sample-app --language=javascript # bootstrap localstack environment cdklocal bootstrap # deploy the sample app cdklocal deploy > Do you wish to deploy these changes (y/n)? y ``` -------------------------------- ### Create a Table Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/snowflake/features/data-metric-functions.md Creates a sample 'customers' table with ID, name, and email columns. This table will be used to demonstrate attaching Data Metric Functions. ```sql CREATE TABLE customers ( id NUMBER, name STRING, email STRING ); ``` -------------------------------- ### Install Amplify LocalStack Plugin Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/amplify.mdx Install the Amplify LocalStack Plugin globally and add it to your Amplify setup. This enables the Amplify CLI to target LocalStack for resource creation. ```bash npm install -g amplify-localstack amplify plugin add amplify-localstack ``` -------------------------------- ### Create Project Directory and WWW Subdirectory Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/s3-static-website-terraform.mdx Sets up the necessary directory structure for the static website project, including a subdirectory for website content. ```bash mkdir -p s3-static-website-localstack/www cd s3-static-website-localstack ``` -------------------------------- ### Start LocalStack with Default Configuration in CircleCI Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/continuous-integration/circleci.md This snippet shows how to install the LocalStack CLI, start the LocalStack Docker container in detached mode, wait for it to become available, and then run basic AWS CLI commands against it. ```yaml version: '2.1' orbs: python: circleci/python@4.0.0 jobs: localstack-test: machine: image: ubuntu-2204:current steps: - checkout - run: name: Install LocalStack CLI and awslocal command: | python3 -m pip install --user --upgrade pip python3 -m pip install --user localstack awscli-local[ver1] echo 'export PATH=$HOME/.local/bin:$PATH' >> "$BASH_ENV" - run: name: Start LocalStack command: | source "$BASH_ENV" docker pull localstack/localstack:latest localstack start -d localstack wait -t 60 - run: name: Test LocalStack command: | awslocal s3 mb s3://test-bucket awslocal s3 ls workflows: localstack-test: jobs: - localstack-test ``` -------------------------------- ### Start LocalStack Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/elb-load-balancing.mdx Launches LocalStack in the background. Replace with your actual token. ```bash LOCALSTACK_AUTH_TOKEN= localstack start -d ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/terraform-shipment-app-guide.mdx Clone the sample repository and install frontend Node.js packages. This also builds the Lambda validator JAR. ```bash git clone https://github.com/localstack-samples/sample-terraform-fullstack-serverless-shipment-app.git cd sample-terraform-fullstack-serverless-shipment-app make install ``` -------------------------------- ### Start LocalStack with Docker CLI Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/getting-started/installation.mdx Use this command to start a LocalStack container directly via the Docker CLI. It maps necessary ports, sets environment variables, and mounts the Docker socket. Ensure you have Docker installed and configured. ```bash docker run \ --rm -it \ -p 127.0.0.1:4566:4566 \ -p 127.0.0.1:4510-4559:4510-4559 \ -p 127.0.0.1:443:443 \ -e LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?} \ -v /var/run/docker.sock:/var/run/docker.sock \ localstack/localstack-pro ``` -------------------------------- ### Create S3 Bucket and Configure for Website Hosting Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/route53.mdx Creates an S3 bucket, uploads website files, configures it for static website hosting, and sets a public read access policy. ```bash DOMAIN="example.com" BUCKET_NAME="$DOMAIN" # Create the bucket awslocal s3api create-bucket --bucket "$BUCKET_NAME" # Upload your website files awslocal s3 cp index.html s3://$BUCKET_NAME/ awslocal s3 cp error.html s3://$BUCKET_NAME/ # Configure the bucket for website hosting awslocal s3 website s3://"$BUCKET_NAME"/ \ --index-document index.html \ --error-document error.html # Set bucket policy to allow public read access awslocal s3api put-bucket-policy \ --bucket $BUCKET_NAME \ --policy '{ \ "Version": "2012-10-17", \ "Statement": [{"Sid": "PublicReadGetObject", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::'$BUCKET_NAME'/*"}] \ }' ``` -------------------------------- ### Initialize Node.js Project Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/developer-tools/lambda-tools/hot-reloading.mdx Initializes a new Node.js project. This is the first step before installing dependencies. ```bash npm init -y ``` -------------------------------- ### Get Current Transaction ID Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/snowflake/features/transaction-management.md Retrieves the ID of the currently active transaction. Returns a non-null ID after a transaction has started. ```sql SELECT CURRENT_TRANSACTION() AS txn; ``` -------------------------------- ### Download Sample Application Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/sagemaker.mdx Clone the sample SageMaker inference application from GitHub using Git sparse checkout. ```bash mkdir localstack-samples && cd localstack-samples git init git remote add origin -f git@github.com:localstack/localstack-pro-samples.git git config core.sparseCheckout true echo sagemaker-inference >> .git/info/sparse-checkout git pull origin master ``` -------------------------------- ### Cloud Pod List File Example Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/developer-tools/snapshots/cloud-pods.mdx A text file where each line specifies the name of a Cloud Pod to be loaded sequentially at startup. ```text foo-pod bar-pod ``` -------------------------------- ### AWS FIS Experiment Output Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/fis.mdx Example output when starting an AWS FIS experiment, showing the experiment's ID, status, and configuration. ```json { "experiment": { "id": "efee7c02-8733-4d7c-9628-1b60bbec9759", "experimentTemplateId": "ad16589a-4a91-4aee-88df-c33446605882", "roleArn": "arn:aws:iam:123456789012:role/ExperimentRole", "state": { "status": "running" }, "targets": { "InstancesToStop": { "resourceType": "aws:ec2:instance", "resourceTags": { "foo": "bar" }, "selectionMode": "COUNT(1)" } }, "actions": { "StopInstance": { "actionId": "aws:ec2:stop-instances", "description": "stop instances", "targets": { "Instances": "InstancesToStop" } } }, "stopConditions": [ { "source": "none" } ], "creationTime": 1718268311.209798, "startTime": 1718268311.209798 } } ``` -------------------------------- ### Test Application Before Simulating Outages Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/simulating-outages.mdx Verify your application's functionality by sending a product to the API Gateway before introducing any faults. This ensures the base setup is working correctly. ```bash curl --location 'http://12345.execute-api.localhost.localstack.cloud:4566/dev/productApi' \ --header 'Content-Type: application/json' \ --data '{ "id": "prod-2004", "name": "Ultimate Gadget", "price": "49.99", "description": "The Ultimate Gadget is the perfect tool for tech enthusiasts looking for the next level in gadgetry. Compact, powerful, and loaded with features." }' ``` -------------------------------- ### Start LocalStack with Podman (Rootfull, no podman-docker) Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/config/podman.md Run LocalStack with Podman without 'podman-docker', specifying environment variables for the Docker command, host, and socket. Requires root privileges. ```bash sudo sh -c 'DEBUG=1 DOCKER_CMD=podman DOCKER_HOST=unix://run/podman/podman.sock DOCKER_SOCK=/run/podman/podman.sock localstack start --network podman' ``` -------------------------------- ### Initialize and Start Podman Machine (Windows) Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/config/podman.md Commands to initialize and start the Podman machine on Windows, preparing it for running containers. These commands are typically run from a WSL environment. ```bash podman machine init podman machine start ``` -------------------------------- ### Crossplane CRD Output Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/connecting/infrastructure-as-code/crossplane.md Example output showing Crossplane Custom Resource Definitions (CRDs) after installation. This confirms the presence of essential Crossplane API resources. ```bash compositions.apiextensions.crossplane.io 2023-09-03T11:30:36Z configurations.pkg.crossplane.io 2023-09-03T11:30:36Z ``` -------------------------------- ### Get CodeArtifact Repository Endpoint Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/codeartifact.mdx Retrieve the endpoint URL for your CodeArtifact npm repository. This URL is used to direct npm to your repository for package installation or publishing. ```bash awslocal codeartifact get-repository-endpoint --domain demo-domain --repository demo-repo --format npm --output text ``` -------------------------------- ### AppConfig Deployment Start Output Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/appconfig.mdx The output confirms the deployment has started and provides details such as the deployment state, version, and timestamps. ```json { "ApplicationId": "400c285", "EnvironmentId": "3695ea3", "DeploymentStrategyId": "f2f2225", "ConfigurationProfileId": "7d748f9", "DeploymentNumber": 1, "ConfigurationName": "my-app-config", "ConfigurationLocationUri": "hosted", "ConfigurationVersion": "1", "Description": "My application deployment", "DeploymentDurationInMinutes": 0, "GrowthFactor": 1.0, "State": "BAKING", "EventLog": [ { "EventType": "DEPLOYMENT_STARTED", "TriggeredBy": "USER", "Description": "Deployment started", "OccurredAt": "2023-08-28T11:18:43.273250Z" } ], "PercentageComplete": 0.0, "StartedAt": "2023-08-28T11:18:43.273250Z", "AppliedExtensions": [] } ``` -------------------------------- ### BitBucket Pipeline Configuration for LocalStack Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/continuous-integration/bitbucket.md This configuration sets up a BitBucket pipeline to use LocalStack. It installs necessary tools, starts a LocalStack container, and performs basic S3 operations. ```yaml image: python:3.9 definitions: services: docker: memory: 2048 pipelines: default: - step: name: Test Localstack services: - docker script: - export PYTHONPATH=$PYTHONPATH:$(pwd) - export DOCKER_SOCK=$DOCKER_HOST - export AWS_ENDPOINT_URL="http://localhost.localstack.cloud:4566" - env - echo "${BITBUCKET_DOCKER_HOST_INTERNAL} localhost.localstack.cloud " >> /etc/hosts - pip install localstack awscli-local - | curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip ./aws/install - docker run -d --rm -p 4566:4566 -p 4510-4559:4510-4559 -e DOCKER_SOCK=tcp://${BITBUCKET_DOCKER_HOST_INTERNAL}:2375 -e DOCKER_HOST=tcp://${BITBUCKET_DOCKER_HOST_INTERNAL}:2375 --name localstack-main localstack/localstack - localstack wait -t 60 - awslocal s3 mb s3://test-bucket - awslocal s3 ls ``` -------------------------------- ### LocalStack Container Configuration for Remote Pods Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/developer-tools/snapshots/cloud-pods.mdx Example Docker Compose or environment variable setup for LocalStack to access remote Cloud Pods, including necessary AWS credentials. ```yaml services: localstack: container_name: "localstack-main" image: localstack/localstack-pro ports: - "127.0.0.1:4566:4566" - "127.0.0.1:4510-4559:4510-4559" environment: - LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?} - DEBUG=1 - AWS_ACCESS_KEY_ID:... - AWS_SECRET_ACCESS_KEY:... volumes: - "./volume:/var/lib/localstack" - "./init-pods.d:/etc/localstack/init-pods.d" ``` -------------------------------- ### Start LocalStack with Terraform Init Hook Extension Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/using-terraform-with-testcontainers-and-localstack.mdx This command starts LocalStack, automatically installs the Terraform init hook extension, and mounts the Terraform configuration and Lambda JAR files into the container. The extension enables Terraform and tflocal within the container and allows init hook runners to detect Terraform files. ```bash export LOCALSTACK_AUTH_TOKEN= localstack start -e EXTENSION_AUTO_INSTALL=localstack-extension-terraform-init \ -v ./terraform/main.tf:/etc/localstack/init/ ``` -------------------------------- ### Terraform Apply Output Example Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/iam-policy-stream.mdx Example output after successfully applying Terraform configuration, showing resource creation status within LocalStack. ```shell aws_sqs_queue.queue: Creating... aws_s3_bucket.bucket: Creating... aws_s3_bucket.bucket: Creation complete after 1s [id=s3-event-notification-bucket] aws_sqs_queue.queue: Still creating... [10s elapsed] aws_sqs_queue.queue: Still creating... [20s elapsed] aws_sqs_queue.queue: Creation complete after 26s [id=http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/s3-event-notification-queue] aws_s3_bucket_notification.bucket_notification: Creating... aws_s3_bucket_notification.bucket_notification: Creation complete after 0s [id=s3-event-notification-bucket] Apply complete! Resources: 3 added, 0 changed, 0 destroyed. ``` -------------------------------- ### Kafka Console Consumer Example Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/kafka.mdx Uses the Kafka console consumer to read messages from a specified topic. Requires the bootstrap server, consumer configuration, topic name, and starting position. ```bash ./kafka-console-consumer.sh \ --bootstrap-server BootstrapBrokerStringTls \ --consumer.config client.properties \ --topic LocalMSKTopic \ --from-beginning ``` -------------------------------- ### Setup S3 Buckets and Upload Input Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/bedrock.mdx Prepare S3 buckets for input and output, and upload the batch input file. This is a prerequisite for creating an invocation job. ```bash awslocal s3 mb s3://in-bucket awslocal s3 cp batch_input.jsonl s3://in-bucket awslocal s3 mb s3://out-bucket ``` -------------------------------- ### Connect to Redis and Perform Operations Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/elasticache.mdx Connect to the ElastiCache Redis instance using the retrieved endpoint and port. This example demonstrates basic Redis operations like PING, SET, and GET. ```bash redis-cli -p 4510 ping PONG redis-cli -p 4510 set foo bar OK redis-cli -p 4510 get foo "bar" ``` -------------------------------- ### Docker Info Output Example Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/config/arm64-support.md This is an example output from the 'docker info' command, highlighting the 'Architecture' field which should show 'aarch64' for ARM64 compatibility. ```text Client: ... Server: ... Operating System: Ubuntu 20.04 OSType: linux Architecture: aarch64 ... ``` -------------------------------- ### Deploy Sample Application Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/getting-started/quickstart.mdx Deploy the sample serverless image resizer application to LocalStack using the awslocal deploy script. ```bash deployment/awslocal/deploy.sh ``` -------------------------------- ### Verify LocalStack Authentication Token in CircleCI Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/continuous-integration/circleci.md This snippet shows how to install the LocalStack CLI, start LocalStack, wait for it to be ready, and then verify that the authentication token is active and LocalStack is ready by checking the logs. ```yaml version: '2.1' orbs: python: circleci/python@4.0.0 jobs: localstack-test: machine: image: ubuntu-2204:current steps: - checkout - run: name: Install LocalStack CLI and awslocal command: | python3 -m pip install --user --upgrade pip python3 -m pip install --user localstack awscli-local[ver1] echo 'export PATH=$HOME/.local/bin:$PATH' >> "$BASH_ENV" - run: name: Start LocalStack command: | source "$BASH_ENV" docker pull localstack/localstack:latest localstack start -d localstack wait -t 60 - run: name: Verify LocalStack setup command: localstack logs | rg "activated|auth token|ready" workflows: localstack-test: jobs: - localstack-test ``` -------------------------------- ### Start Rancher Desktop Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/integrations/containers/rancher-desktop.mdx Initializes and launches Rancher Desktop. This command should be run after configuring settings. ```bash rancher-desktop --start ``` -------------------------------- ### Initialize SAM Application Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/serverlessrepo.mdx Use this command to create a sample SAM application template and generate a template.yml file. This sets up a basic Lambda function and API Gateway endpoint. ```bash samlocal init --runtime python3.9 ``` -------------------------------- ### Example Terraform Directory Structure Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/tutorials/using-terraform-with-testcontainers-and-localstack.mdx Illustrates how organizing multiple Terraform files into subfolders with a preorder traversal method ensures consistent execution. ```bash ready.d/myscript.sh ready.d/a/script_0.sh ready.d/a/aa/script_0.sh ready.d/a/aa/script_2.sh ready.d/b/script_0.sh ``` -------------------------------- ### Install Python Dependencies for MWAA Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/mwaa.mdx Create a requirements.txt file listing Python dependencies and upload it to the designated S3 bucket for your MWAA environment. This ensures your Airflow setup includes the necessary packages. ```txt boto3==1.17.54 boto==2.49.0 botocore==1.20.54 ``` ```bash awslocal s3 cp requirements.txt s3://my-mwaa-bucket/requirements.txt ``` -------------------------------- ### Serverless Framework Configuration for Cognito Authorization Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/cognito-idp.mdx Example `serverless.yml` configuration demonstrating how to integrate AWS Cognito User Pools as an authorizer for API Gateway endpoints. This setup protects the `v1/request` path. ```yaml service: test plugins: - serverless-deployment-bucket - serverless-pseudo-parameters - serverless-localstack custom: localstack: stages: [local] functions: http_request: handler: http.request events: - http: path: v1/request authorizer: arn: arn:aws:cognito-idp:us-east-1:#{AWS::AccountId}:userpool/ExampleUserPool resources: Resources: UserPool: Type: AWS::Cognito::UserPool Properties: ... ``` -------------------------------- ### S3 CORS Configuration JSON Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/services/s3.mdx Define the CORS rules for your S3 bucket in this JSON format. This example allows GET, POST, and PUT requests from http://localhost:3000 and exposes the ETag header. ```json { "CORSRules": [ { "AllowedHeaders": ["*"], "AllowedMethods": ["GET", "POST", "PUT"], "AllowedOrigins": ["http://localhost:3000"], "ExposeHeaders": ["ETag"] } ] } ``` -------------------------------- ### Configure LOCALSTACK_VOLUME_DIR and Install Extension Source: https://github.com/localstack/localstack-docs/blob/main/src/content/docs/aws/capabilities/extensions/managing-extensions.mdx Sets the `LOCALSTACK_VOLUME_DIR` environment variable to a custom volume path and then installs a local extension file. ```yaml volumes: - '/tmp/volume:/var/lib/localstack' # LOCALSTACK_VOLUME_DIR mount - '/var/run/docker.sock:/var/run/docker.sock' ``` ```bash export LOCALSTACK_VOLUME_DIR=/tmp/volume localstack extensions install file:///tmp/my_files/my-extension-1.0.0.tar.gz ```