### Start LocalStack (Async) Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/circleci This snippet demonstrates starting LocalStack in the background and then proceeding with setup and tests, including waiting for LocalStack and creating an SQS queue. ```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 in background command: | source "$BASH_ENV" docker pull localstack/localstack:latest localstack start -d - run: name: Execute setup and tests command: | source "$BASH_ENV" localstack wait -t 60 awslocal sqs create-queue --queue-name test-queue awslocal sqs list-queues workflows: localstack-test: jobs: - localstack-test ``` -------------------------------- ### Install Dependencies, Deploy Resources, and Run Tasks Source: https://docs.localstack.cloud/aws/services/dms Execute make commands to install project dependencies, deploy the CDK stack with DMS resources, 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 ``` -------------------------------- ### AppConfig Deployment Start Response Source: https://docs.localstack.cloud/aws/services/appconfig Example JSON response after starting an AppConfig deployment. ```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": [] } ``` -------------------------------- ### Clone Sample Repository Source: https://docs.localstack.cloud/aws/tutorials/rds-database-initialization Clone the sample repository to get started with the project. ```bash git clone https://github.com/localstack-samples/sample-cdk-rds-database-initialization.git cd sample-cdk-rds-database-initialization ``` -------------------------------- ### Setup Python Virtual Environment (Windows) Source: https://docs.localstack.cloud/aws/getting-started/quickstart Creates a Python virtual environment and installs development dependencies from requirements-dev.txt. ```bash python -m venv .venv .venv\Scripts\activate pip install -r requirements-dev.txt ``` -------------------------------- ### Start LocalStack Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/github-actions Basic setup for LocalStack in a GitHub Actions workflow. ```yaml - name: Start LocalStack uses: LocalStack/setup-localstack@v0.2.2 with: image-tag: 'latest' install-awslocal: 'true' ``` -------------------------------- ### Setup Python Virtual Environment (macOS/Linux) Source: https://docs.localstack.cloud/aws/getting-started/quickstart Creates a Python virtual environment and installs development dependencies from requirements-dev.txt. ```bash python -m venv .venv source .venv/bin/activate pip install -r requirements-dev.txt ``` -------------------------------- ### Query All Initialization Stages Source: https://docs.localstack.cloud/aws/capabilities/config/initialization-hooks Use this command to get the status of all initialization stages (BOOT, START, READY, SHUTDOWN) and the executed scripts. ```bash curl -s localhost:4566/_localstack/init | jq . ``` -------------------------------- ### Start LocalStack (Default) Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/circleci This snippet shows how to install the LocalStack CLI and awslocal, then start LocalStack in detached mode and wait for it to be ready. It concludes with a basic S3 test. ```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 ``` -------------------------------- ### Install Cross-Platform Emulation Source: https://docs.localstack.cloud/aws/capabilities/config/arm64-support Installs the `binfmt` emulator to enable cross-platform emulation for Docker Lambda functions or binaries not built for your architecture. This example installs emulation for the AMD64 architecture. ```bash docker run --privileged --rm tonistiigi/binfmt --install amd64 ``` -------------------------------- ### Start AppConfig Deployment Source: https://docs.localstack.cloud/aws/services/appconfig Starts a deployment of a configuration to an environment using a specified deployment strategy. ```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" ``` -------------------------------- ### Show Ephemeral Instances CLI Help Source: https://docs.localstack.cloud/aws/capabilities/cloud-sandbox/ephemeral-instances Displays the available commands and options for the Ephemeral Instances CLI. No additional setup is required if the LocalStack CLI is installed. ```bash localstack ephemeral --help ``` -------------------------------- ### Query for a non-existent resource Source: https://docs.localstack.cloud/azure/services/resource-graph This example demonstrates querying for a resource that does not exist, resulting in an empty data set. The Resource Graph extension must be installed. ```bash az graph query \ --graph-query "Resources | where type =~ 'Microsoft.Web/sites' and name =~ 'doesnotexist'" ``` ```json { "count": 0, "data": [], "skip_token": null, "total_records": 0 } ``` -------------------------------- ### Start LocalStack CLI Source: https://docs.localstack.cloud/aws/getting-started/installation Start LocalStack in the background using the 'localstack start' command. Ensure your auth token is set up. ```bash localstack start # start localstack in background with -d flag ``` -------------------------------- ### Start LocalStack Source: https://docs.localstack.cloud/aws/connecting/infrastructure-as-code/serverless-framework Run this command to start the LocalStack environment before deploying your Serverless service. ```bash localstack start ``` -------------------------------- ### Clone DMS Sample Repository Source: https://docs.localstack.cloud/aws/services/dms Clone the sample DMS Kinesis RDS MariaDB repository from GitHub to get started with a practical example. ```bash git clone https://github.com/localstack-samples/sample-dms-kinesis-rds-mariadb.git ``` -------------------------------- ### CircleCI Setup for Snowflake Emulator Source: https://docs.localstack.cloud/snowflake/integrations/continuous-integration This snippet demonstrates how to set up a CircleCI job to install LocalStack, pull the Snowflake emulator image, and start the emulator. ```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 Podman Machine Source: https://docs.localstack.cloud/aws/capabilities/config/podman Start the Podman machine after initialization. ```bash podman machine start ``` -------------------------------- ### GitHub Actions Setup for Snowflake Emulator Source: https://docs.localstack.cloud/snowflake/integrations/continuous-integration This snippet shows how to configure a GitHub Actions workflow to pull the Snowflake emulator image, install LocalStack, and start the emulator. ```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 }} ``` -------------------------------- ### Deploy Application Preview with LocalStack Startup Action Source: https://docs.localstack.cloud/aws/tutorials/ephemeral-application-previews This step utilizes the 'LocalStack/setup-localstack/ephemeral/startup' action to deploy the application preview on an ephemeral LocalStack instance. It requires GitHub and LocalStack API keys and defines the commands to build and deploy the application, including frontend assets and CloudFront distribution. ```yaml - name: Deploy Preview uses: LocalStack/setup-localstack/ephemeral/startup@v0.2.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} localstack-api-key: ${{ secrets.LOCALSTACK_API_KEY }} preview-cmd: | npm install -g aws-cdk-local aws-cdk pip install awscli-local[ver1] make build make bootstrap make deploy make prepare-frontend-local make build-frontend make bootstrap-frontend make deploy-frontend distributionId=$(awslocal cloudfront list-distributions | jq -r '.DistributionList.Items[0].Id') echo LS_PREVIEW_URL=$AWS_ENDPOINT_URL/cloudfront/$distributionId/ >> $GITHUB_ENV ``` -------------------------------- ### Create Sample Web Resources Source: https://docs.localstack.cloud/azure/services/resource-graph Deploy an App Service plan and a Web App within the specified resource group and location. These resources will be used for Resource Graph querying. ```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" ``` -------------------------------- ### Verify LocalStack Setup with Auth Token Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/circleci This snippet shows the complete CircleCI configuration including installing LocalStack CLI, starting LocalStack with an assumed CI Auth Token, waiting for it, and verifying the setup by checking logs for activation and readiness messages. ```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 ``` -------------------------------- ### Install Project Dependencies Source: https://docs.localstack.cloud/aws/tutorials/rds-database-initialization Install the necessary Node.js dependencies for the project. The 'make install' command is an optional alternative. ```bash npm install # or if you prefer using make make install ``` -------------------------------- ### Deploy Sample Application Source: https://docs.localstack.cloud/aws/getting-started/quickstart Deploys the sample serverless image resizer application to LocalStack using the provided deployment script. ```bash deployment/awslocal/deploy.sh ``` -------------------------------- ### GitLab CI Setup for Snowflake Emulator Source: https://docs.localstack.cloud/snowflake/integrations/continuous-integration This snippet shows how to configure a GitLab CI job to install LocalStack, pull the Snowflake emulator image, and start the emulator within a Docker-in-Docker environment. ```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 ``` -------------------------------- ### Start React Frontend Source: https://docs.localstack.cloud/aws/tutorials/terraform-shipment-app-guide 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 ``` -------------------------------- ### Travis CI Configuration for LocalStack Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/travis-ci Example .travis.yaml configuration to install LocalStack CLI, pull the latest image, start LocalStack in detached mode, wait for it to become ready, and then run S3 bucket creation tests. ```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 :)" ``` -------------------------------- ### Install aws-sam-cli-local Source: https://docs.localstack.cloud/aws/connecting/infrastructure-as-code/aws-sam Install the `samlocal` wrapper script using pip. ```bash pip install aws-sam-cli-local ``` -------------------------------- ### Set Up Python Virtual Environment and Install Dependencies Source: https://docs.localstack.cloud/aws/tutorials/serverless-quiz-app Create a Python virtual environment and install the necessary development dependencies for the project. This ensures a consistent development environment. ```bash python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r tests/requirements-dev.txt ``` -------------------------------- ### Travis CI Configuration for LocalStack Pro Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/travis-ci Example Travis CI configuration for LocalStack Pro, including installing the CLI, pulling the Pro image, starting LocalStack, and waiting for readiness. Assumes LOCALSTACK_AUTH_TOKEN is set as an environment variable. ```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" ``` -------------------------------- ### Install Serverless Framework Globally Source: https://docs.localstack.cloud/aws/tutorials/elb-load-balancing Installs the Serverless framework globally using npm. This is the first step to using the framework. ```bash npm install -g serverless ``` -------------------------------- ### LocalStack Container Setup in GitLab CI Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/gitlab-ci Set up a GitLab CI job to pull and run the LocalStack Docker image, configure host entries, and start LocalStack. This snippet includes installing LocalStack and AWS CLI within the job. ```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 ``` -------------------------------- ### Start Rancher Desktop Source: https://docs.localstack.cloud/aws/integrations/containers/rancher-desktop Initialize and start the Rancher Desktop application. ```bash rancher-desktop --start ``` -------------------------------- ### Install Amplify LocalStack Plugin Source: https://docs.localstack.cloud/aws/services/amplify Install the Amplify LocalStack Plugin globally and add it to your Amplify setup. ```bash npm install -g amplify-localstack amplify plugin add amplify-localstack ``` -------------------------------- ### Docker Container List Example Source: https://docs.localstack.cloud/aws/services/eks Example output from 'docker ps' showing k3d proxy and k3s server containers running for the EKS cluster. ```text CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ... b335f7f089e4 rancher/k3d-proxy:5.0.1-rc.1 "/bin/sh -c nginx-pr…" 1 minute ago Up 1 minute 0.0.0.0:8081->80/tcp, 0.0.0.0:44959->6443/tcp k3d-cluster1-serverlb f05770ec8523 rancher/k3s:v1.21.5-k3s2 "/bin/k3s server --t…" 1 minute ago Up 1 minute ... ``` -------------------------------- ### Install Specific LocalStack Operator Version Source: https://docs.localstack.cloud/aws/enterprise/kubernetes/kubernetes-operator Installs a specific version of the LocalStack Operator controller, using v0.4.0 as an example. ```bash # Example: install v0.4.0 kubectl apply -f https://github.com/localstack/localstack-operator/releases/v0.4.0/download/controller.yaml ``` -------------------------------- ### SQS Client Setup, Message Send, and Receive Source: https://docs.localstack.cloud/aws/tooling/localstack-sdks/python-sdk Demonstrates setting up an SQS client, creating a queue, sending messages, and retrieving them using the LocalStack SDK for Python and boto3. ```python import json import boto3 import localstack.sdk.aws # Initialize LocalStack AWS client client = localstack.sdk.aws.AWSClient() # Set up SQS client using the LocalStack AWS client configuration sqs_client = boto3.client( "sqs", endpoint_url=client.configuration.host, region_name="us-east-1", aws_access_key_id="test", aws_secret_access_key="test", ) # Create an SQS queue queue_name = "test-queue" sqs_client.create_queue(QueueName=queue_name) queue_url = sqs_client.get_queue_url(QueueName=queue_name)["QueueUrl"] # Send messages to the queue for i in range(5): sqs_client.send_message( QueueUrl=queue_url, MessageBody=json.dumps( {"event": f"event-{i}", "message": f"message-{i}"} ), ) # Retrieve messages from the queue response = sqs_client.receive_message( QueueUrl=queue_url, MaxNumberOfMessages=5 ) # Print each message body messages = response.get("Messages", []) for msg in messages: print("Message Body:", msg.get("Body")) ``` ```text Message Body: {"event": "event-0", "message": "message-0"} Message Body: {"event": "event-1", "message": "message-1"} Message Body: {"event": "event-2", "message": "message-2"} Message Body: {"event": "event-3", "message": "message-3"} Message Body: {"event": "event-4", "message": "message-4"} ``` -------------------------------- ### Install Testcontainers LocalStack Module for Go Source: https://docs.localstack.cloud/aws/integrations/testing/testcontainers Install the Testcontainers LocalStack module for Go using the go get command. ```bash go get github.com/testcontainers/testcontainers-go/modules/localstack ``` -------------------------------- ### Create, Bootstrap, and Deploy Sample CDK App Source: https://docs.localstack.cloud/aws/connecting/infrastructure-as-code/aws-cdk Generates a sample CDK application, bootstraps the LocalStack environment, and deploys the application. Requires LocalStack to be running. ```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://docs.localstack.cloud/snowflake/features/data-metric-functions Creates a sample 'customers' table with 'id', 'name', and 'email' columns. This table will be used to demonstrate Data Metric Functions. ```sql CREATE TABLE customers ( id NUMBER, name STRING, email STRING ); ``` -------------------------------- ### Create S3 Bucket and Configure for Website Hosting Source: https://docs.localstack.cloud/aws/services/route53 Sets up an S3 bucket for static website hosting, including creating the bucket, uploading files, configuring website settings, and setting a public read access policy using LocalStack. ```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'/*" }] }' ``` -------------------------------- ### Complete Mock Configuration File Example Source: https://docs.localstack.cloud/aws/services/stepfunctions A comprehensive example of a LocalStack configuration file demonstrating the 'StateMachines' and 'MockedResponses' sections for testing a Lambda and SQS integration. ```json { "StateMachines":{ "LambdaSQSIntegration":{ "TestCases":{ "BaseCase":{ "LambdaState":"MockedLambdaStateSuccess", "SQSState":"MockedSQSStateSuccess" }, "LambdaRetryCase":{ "LambdaState":"MockedLambdaStateRetry", "SQSState":"MockedSQSStateSuccess" }, "HybridCase":{ "LambdaState":"MockedLambdaSuccess" } } } }, "MockedResponses":{ "MockedLambdaStateSuccess":{ "0":{ "Return":{ "StatusCode":200, "Payload":{ "greeting":"Hello John Smith, you’re now testing mocked integrations with LocalStack!" } } } }, "MockedSQSStateSuccess":{ "0":{ "Return":{ "MD5OfMessageBody":"3661896f-1287-45a3-8f89-53bd7b25a9a6", "MessageId":"7c9ef661-c455-4779-a9c2-278531e231c2" } } }, "MockedLambdaStateRetry":{ "0":{ "Throw":{ "Error":"Lambda.ServiceException", "Cause":"An internal service error occurred." } }, "1-2":{ "Throw":{ "Error":"Lambda.TooManyRequestsException", "Cause":"Invocation rate limit exceeded." } }, "3":{ "Return":{ "StatusCode":200, "Payload":{ "greeting":"Hello John Smith, you’re now testing mocked integrations with LocalStack!" } } } } } } ``` -------------------------------- ### Start LocalStack with Native Runner Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/codebuild Configures CodeBuild to pull and start a LocalStack Docker container using the native runner. Includes installing dependencies and waiting for LocalStack to be ready. ```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 ``` -------------------------------- ### List Support Cases Source: https://docs.localstack.cloud/aws/services/support Use this command to list all support cases. This example filters cases in the 'General guidance' category. ```bash awslocal support describe-cases ``` -------------------------------- ### Automate Extension Installation with EXTENSION_AUTO_INSTALL Source: https://docs.localstack.cloud/aws/tooling/extensions/managing-extensions Configure the `EXTENSION_AUTO_INSTALL` environment variable in your docker-compose file to automatically install specified extensions when the LocalStack container starts up. The value is a comma-separated list of extension directives. ```yaml 1 services: 2 localstack: 3 container_name: 'localstack-main' 4 image: localstack/localstack-pro 5 ports: 6 - '127.0.0.1:4566:4566' 7 - '127.0.0.1:4510-4559:4510-4559' 8 environment: 9 - LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?} 10 - DEBUG=1 11 - EXTENSION_AUTO_INSTALL=localstack-extension-mailhog,localstack-extension-httpbin 12 volumes: 13 - './volume:/var/lib/localstack' 14 - '/var/run/docker.sock:/var/run/docker.sock' ``` -------------------------------- ### Start Application Preview Source: https://docs.localstack.cloud/aws/capabilities/cloud-sandbox/app-preview Configures a GitHub Actions workflow to start a LocalStack Ephemeral Instance for application preview. The `preview-cmd` property specifies the deployment script. The preview is available for 30 minutes. ```yaml uses: LocalStack/setup-localstack@v0.2.3 with: github-token: ${{ secrets.GITHUB_TOKEN }} state-backend: ephemeral state-action: start # Adding this option prevents Ephemeral Instance to be stopped after the `preview-cmd` run skip-ephemeral-stop: 'true' # Optional script/command to run preview-cmd: deploy.sh env: LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} ``` -------------------------------- ### Example of a Pod startup error Source: https://docs.localstack.cloud/aws/enterprise/kubernetes/faq This log message indicates that the LocalStack container crashed shortly after starting. ```text Back-off restarting failed container localstack in pod ``` -------------------------------- ### Create a Launch Template Source: https://docs.localstack.cloud/aws/services/autoscaling Use the `CreateLaunchTemplate` API to define the configuration for instances within an Auto Scaling group. This example creates a basic launch template with a specified image ID and instance type. ```bash awslocal ec2 create-launch-template \ --launch-template-name my-template-for-auto-scaling \ --version-description version1 \ --launch-template-data '{"ImageId":"ami-ff0fea8310f3","InstanceType":"t2.micro"}' ``` ```json { "LaunchTemplate": { "LaunchTemplateId": "lt-5ccdf1a84f178ba44", "LaunchTemplateName": "my-template-for-auto-scaling", "CreateTime": "2024-07-12T07:59:08+00:00", "CreatedBy": "arn:aws:iam::000000000000:root", "DefaultVersionNumber": 1, "LatestVersionNumber": 1, "Tags": [] } } ``` -------------------------------- ### Get Glue Tables Response Source: https://docs.localstack.cloud/aws/services/glue Example JSON response when retrieving tables from the Glue data catalog. ```json { "TableList": [ { "Name": "table1", "DatabaseName": "db1" } ] } ``` -------------------------------- ### Create Project Directory and WWW Subdirectory Source: https://docs.localstack.cloud/aws/tutorials/s3-static-website-terraform Sets up the necessary directory structure for the static website project, including a 'www' subdirectory for website content. ```bash mkdir -p s3-static-website-localstack/www cd s3-static-website-localstack ``` -------------------------------- ### Initialize Project and Install Dependencies Source: https://docs.localstack.cloud/aws/tutorials/elb-load-balancing Initializes a Node.js project and installs necessary Serverless plugins for LocalStack integration and deployment bucket management as development dependencies. ```bash npm init -y npm install -D serverless serverless-localstack serverless-deployment-bucket ``` -------------------------------- ### Initialize a new Gradle Project Source: https://docs.localstack.cloud/aws/integrations/app-frameworks/spring-cloud-function Use this command to initialize a new Gradle project. This sets up the basic structure for your project. ```bash gradle init ``` -------------------------------- ### Start Workflow Execution Output Source: https://docs.localstack.cloud/aws/services/swf Example output from the StartWorkflowExecution API, containing the unique run ID for the new execution. ```json { "runId": "0602601afc71403abb934d8094c51668" } ``` -------------------------------- ### CloudWatch Get Log Events Response Source: https://docs.localstack.cloud/aws/services/cloudwatch Example JSON response from the `get-log-events` command, displaying the log messages and associated metadata. ```json { "events": [ { "timestamp": 1683009968920, "message": "START RequestId: 71712856-9f41-4d22-827c-e3883f799f25 Version: $LATEST", "ingestionTime": 1683009968979 }, { "timestamp": 1683009968932, "message": "END RequestId: 71712856-9f41-4d22-827c-e3883f799f25", "ingestionTime": 1683009968979 }, { "timestamp": 1683009968945, "message": "REPORT RequestId: 71712856-9f41-4d22-827c-e3883f799f25\tDuration: 1.27 ms\tBilled Duration: 2 ms\tMemory Size: 1024 MB\tMax Memory Used: 1024 MB\t", "ingestionTime": 1683009968979 } ], "nextForwardToken": "f/00000000000000000000000000000000000000000000000000000002", "nextBackwardToken": "b/00000000000000000000000000000000000000000000000000000000" } ``` -------------------------------- ### S3 Bucket Resource Description Source: https://docs.localstack.cloud/aws/services/cloudcontrol Example output when listing or getting an S3 bucket resource using the Cloud Control API. ```json { "ResourceDescriptions": [ { "Identifier": "my-bucket", "Properties": "{\"BucketName\":\"my-bucket\"}" } ], "TypeName": "AWS::S3::Bucket" } ``` -------------------------------- ### Install and Connect wscat Source: https://docs.localstack.cloud/aws/services/appsync Installs the `wscat` tool and connects to the AppSync WebSocket endpoint. Set the `API_ID` environment variable before connecting. ```bash npm install -g wscat export API_ID= wscat \ -s "graphql-ws" \ -c "ws://localhost:4510/graphql/$API_ID" ``` -------------------------------- ### API Gateway v2 Get APIs Response Source: https://docs.localstack.cloud/aws/services/apigateway Example response from the `awslocal apigatewayv2 get-apis` command, showing WebSocket API details. ```json { "Items": [{ "ApiEndpoint": "ws://localhost:4510", "ApiId": "129ca37e", ... }] } ``` -------------------------------- ### Start LocalStack with SFN Mock Config (CLI) Source: https://docs.localstack.cloud/aws/services/stepfunctions Use the LocalStack CLI to start the service with a mounted mock configuration file for Step Functions. ```bash LOCALSTACK_SFN_MOCK_CONFIG=/tmp/MockConfigFile.json \ localstack start --volume /path/to/MockConfigFile.json:/tmp/MockConfigFile.json ``` -------------------------------- ### Initialize LocalStack SageMaker Sample Project Source: https://docs.localstack.cloud/aws/services/sagemaker Initializes a new local directory and clones the SageMaker inference sample project from GitHub using 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 ``` -------------------------------- ### LocalStack Lambda Invocation Logs Source: https://docs.localstack.cloud/aws/tutorials/reproducible-machine-learning-cloud-pods Example output from a LocalStack Lambda invocation, showing the prediction result. This output is visible when LocalStack is started with DEBUG=1. ```text null >START RequestId: 65dc894d-25e0-168e-dea1-a3e8bfdb563b Version: $LATEST > --> prediction result: [8 8 4 9 0 8 9 8 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 9 6 7 8 9 ... ... > 9 5 4 8 8 4 9 0 8 9 8] > END RequestId: 6... ``` -------------------------------- ### Fish Shell Completion Setup Source: https://docs.localstack.cloud/aws/tooling/localstack-cli Installs LocalStack CLI completion for the fish shell by writing the completion script to the appropriate directory for fish to find. ```fish localstack completion fish > ~/.config/fish/completions/localstack.fish ``` -------------------------------- ### Run Docker Compose Up Source: https://docs.localstack.cloud/snowflake/getting-started Start the services defined in the docker-compose.yml file. ```bash docker-compose up ``` -------------------------------- ### Initialize a new SAM project Source: https://docs.localstack.cloud/aws/connecting/infrastructure-as-code/aws-sam Initialize a new SAM project using the `samlocal init` command. Select the desired template, runtime, and packaging type. ```bash samlocal init ``` -------------------------------- ### Get Cost Anomaly Monitors Source: https://docs.localstack.cloud/aws/services/ce Retrieves a list of all created cost anomaly monitors. Use this to view, manage, or verify your anomaly detection setup. ```bash awslocal ce get-anomaly-monitors ``` ```json { "AnomalyMonitors": [ { "MonitorArn": "arn:aws:ce::000000000000:anomalymonitor/22570ff3", "MonitorName": "mon5463", "MonitorType": "DIMENSIONAL" } ] } ``` -------------------------------- ### Load LocalStack State Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/circleci Installs LocalStack and AWS CLI, starts a LocalStack container, and imports a previously saved state from a zip file attached from the workspace. ```yaml jobs: localstack-load-state: machine: image: ubuntu-2204:current steps: - run: python3 -m pip install localstack awscli-local[ver1] - run: | docker pull localstack/localstack:latest localstack start -d localstack wait -t 60 # LocalStack already running - attach_workspace: at: . - run: name: Import state command: | test -f ls-state.zip && localstack state import ls-state.zip ``` -------------------------------- ### Start Azure Emulator with localstack CLI Source: https://docs.localstack.cloud/azure/getting-started Start the Azure emulator using the `localstack` CLI. Ensure your `LOCALSTACK_AUTH_TOKEN` is set. ```bash $ export LOCALSTACK_AUTH_TOKEN= $ IMAGE_NAME=localstack/localstack-azure localstack start ``` -------------------------------- ### Clone Sample Repository Source: https://docs.localstack.cloud/aws/tutorials/serverless-quiz-app Clone the sample serverless quiz application repository and navigate into the project directory. This is the first step to get the project locally. ```bash git clone https://github.com/localstack-samples/sample-serverless-quiz-app.git cd sample-serverless-quiz-app ``` -------------------------------- ### Start LocalStack with Terraform Init Hook Source: https://docs.localstack.cloud/aws/tutorials/using-terraform-with-testcontainers-and-localstack Starts LocalStack, automatically installs the Terraform init extension, and mounts a Terraform configuration file to be used as an initialization hook. This command ensures Terraform and tflocal are available within the container and enables the 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/ ``` -------------------------------- ### Configure HyperExecute Environment Source: https://docs.localstack.cloud/aws/integrations/testing/lambdatest-hyperexecute This configuration file starts LocalStack, creates necessary AWS resources, and installs dependencies. It's used to set up the testing environment for HyperExecute. ```yaml version: "0.1" runson: linux autosplit: true parallelism: 2 concurrency: 2 scenarioCommandStatusOnly: true runtime: language: python version: 3.10 pre: - pip install localstack awscli awscli-local - localstack start -d - localstack wait -t 60 - awslocal s3 mb s3://test-bucket - awslocal sqs create-queue --queue-name test-queue - awslocal sns create-topic --name test-topic ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://docs.localstack.cloud/aws/tutorials/terraform-shipment-app-guide Clone the sample application 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 ``` -------------------------------- ### Run Docker Compose for Kafka and LocalStack Source: https://docs.localstack.cloud/aws/integrations/messaging/selfmanaged-kafka-cluster Starts the Kafka cluster, ZooKeeper, LocalStack, and Kowl UI using Docker Compose. Ensure Docker is installed and running. ```bash docker-compose up -d ``` -------------------------------- ### LocalStack Pod CLI Help Overview Source: https://docs.localstack.cloud/aws/capabilities/state-management/cli-commands Displays an overview of available commands and options for the LocalStack Pod CLI. ```bash Usage: pod [OPTIONS] COMMAND [ARGS]... Manage the state of your instance via Cloud Pods. Options: --help Show this message and exit. Commands: delete Delete a Cloud Pod inspect Inspect the contents of a Cloud Pod This command shows the... 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 This command lists... ``` -------------------------------- ### User Data Script for HTTP Server Source: https://docs.localstack.cloud/aws/services/ec2 A shell script to be used as user data for an EC2 instance. It installs Python 3 and starts an HTTP server on port 8000. ```bash #!/bin/bash -xeu apt update apt install python3 -y python3 -m http.server 8000 ``` -------------------------------- ### Start LocalStack with a Specific Profile Source: https://docs.localstack.cloud/snowflake/capabilities/configuration Demonstrates how to start the LocalStack CLI with a specified configuration profile, such as 'dev.env'. ```bash localstack --profile=dev start --stack snowflake ``` -------------------------------- ### Save LocalStack State Source: https://docs.localstack.cloud/aws/integrations/continuous-integration/circleci Installs LocalStack and AWS CLI, starts a LocalStack container, and exports its current state to a zip file. This state is then persisted to the workspace and stored as an artifact. ```yaml jobs: localstack-save-state: machine: image: ubuntu-2204:current steps: - run: python3 -m pip install localstack awscli-local[ver1] - run: | docker pull localstack/localstack:latest localstack start -d localstack wait -t 60 # LocalStack already running and deployed infrastructure - run: name: Export state command: localstack state export ls-state.zip - persist_to_workspace: paths: - ls-state.zip # Store state as artifact for local debugging - store_artifact: key: ls-state paths: ls-state.zip ``` -------------------------------- ### Example with Scheduling and Metadata Source: https://docs.localstack.cloud/aws/enterprise/kubernetes/pod-configuration Configure Lambda pods to run on dedicated nodes, add tolerations, set resource limits, and attach metadata for platform tooling. This example demonstrates advanced pod configuration options. ```json { "profiles": { "lambda": { "nodeSelector": { "workload": "localstack-lambda" }, "tolerations": [ { "key": "dedicated", "operator": "Equal", "value": "localstack", "effect": "NoSchedule" } ], "resources": { "requests": { "cpu": "250m", "memory": "256Mi" }, "limits": { "cpu": "1", "memory": "1Gi" } }, "labels": { "team": "platform" }, "annotations": { "prometheus.io/scrape": "true" } } }, "services": { "lambda": { "profile": "lambda" } } } ``` -------------------------------- ### Example extensions.txt for pip requirements Source: https://docs.localstack.cloud/aws/tooling/extensions/managing-extensions Define LocalStack extensions using a pip requirements file format in extensions.txt. This allows for automatic installation of extensions upon container startup. ```text localstack-extension-mailhog git+https://github.com/localstack/localstack-extensions/#egg=localstack-extension-aws-replicator&subdirectory=aws-replicator ``` -------------------------------- ### Terraform Apply Output Example Source: https://docs.localstack.cloud/aws/tutorials/iam-policy-stream Example output after successfully applying Terraform configuration to create S3 bucket, SQS queue, and bucket notification resources within LocalStack. ```bash 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. ``` -------------------------------- ### Override Init Container Images Source: https://docs.localstack.cloud/aws/enterprise/kubernetes/configuration Override default init container images used for setup tasks before the main container starts. Useful for air-gapped environments or private registries. ```bash K8S_CURL_INIT_IMAGE=my-registry.example.com/curl-init:latest LAMBDA_K8S_INIT_IMAGE=my-registry.example.com/lambda-init:latest ``` -------------------------------- ### Install wscat Source: https://docs.localstack.cloud/aws/services/appsync Install the `wscat` command-line tool globally using npm. This tool is used for creating WebSocket connections to test the AppSync API. ```bash npm install -g wscat ``` -------------------------------- ### Start LocalStack with Terraform Init Hook Source: https://docs.localstack.cloud/aws/capabilities/config/initialization-hooks Configure LocalStack to automatically install the Terraform extension and run Terraform configurations as init hooks. Mount your main.tf file to the appropriate directory. ```yaml services: localstack: container_name: "localstack-main" image: localstack/localstack-pro ports: - "127.0.0.1:4566:4566" # LocalStack Gateway environment: # Activate LocalStack for AWS: https://docs.localstack.cloud/getting-started/auth-token/ - LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?} - EXTENSION_AUTO_INSTALL=localstack-extension-terraform-init volumes: # you could also place your main.tf in "./ready.d" and set "./ready.d:/etc/localstack/init/ready.d" - "./main.tf:/etc/localstack/init/ready.d/main.tf" - "./volume:/var/lib/localstack" - "/var/run/docker.sock:/var/run/docker.sock ``` -------------------------------- ### Initialize Podman Machine Source: https://docs.localstack.cloud/aws/capabilities/config/podman Initialize a new Podman machine for use on Windows. ```bash podman machine init ``` -------------------------------- ### Query a specific resource by type and name, projecting the ID Source: https://docs.localstack.cloud/azure/services/resource-graph This example shows how to filter resources by both type and name, and then project only the 'id' column in the results. Ensure the Resource Graph extension is installed. ```bash az graph query \ --graph-query "Resources | where type =~ 'Microsoft.Web/sites' and name =~ 'ls-app-doc81' | project id" ``` ```json { "count": 1, "data": [ { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-resourcegraph-demo/providers/Microsoft.Web/sites/ls-app-doc81", "resourceGroup": "rg-resourcegraph-demo" } ], "skip_token": null, "total_records": 1 } ``` -------------------------------- ### Local Lambda Function Debug Output Source: https://docs.localstack.cloud/aws/tutorials/aws-proxy-localstack-extension Example log output from a local Lambda function invoked by a proxied SQS message. It shows the start, debug messages, and end of the function execution. ```log 2024-03-26T07:45:16.524 DEBUG --- [db58fad602e5] l.s.l.i.version_manager : [func1-ed938bb0-e1ee-41fb-a844-db58fad602e5] START RequestId: ed938bb0-e1ee-41fb-a844-db58fad602e5 Version: $LATEST 2024-03-26T07:45:16.524 DEBUG --- [db58fad602e5] l.s.l.i.version_manager : [func1-ed938bb0-e1ee-41fb-a844-db58fad602e5] Debug output from Lambda function 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 ```