From e2888da65fbf48819d2f4e47fa893565feb0cd20 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Mon, 8 Jun 2026 13:54:41 +1200 Subject: [PATCH 1/3] Migrate samples to lstk, away from awslocal and tflocal Standardize all samples on the lstk CLI for starting LocalStack and running Terraform, replacing the awslocal/tflocal wrappers. Modernizing the examples along the way was necessary to get them deploying and passing again: fix API Gateway deployment ordering, use $default stages for HTTP APIs, add missing stages/permissions, and bump deprecated runtimes and service versions. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/makefile.yml | 9 +- .gitignore | 1 + Makefile | 11 +- README.md | 7 +- acm-route53/Makefile | 49 +- acm-route53/README.md | 12 +- apigateway-dynamodb/Makefile | 49 +- apigateway-dynamodb/README.md | 4 +- apigateway-dynamodb/main.tf | 9 +- apigateway-dynamodb/run.sh | 4 +- apigateway-http-proxy-authorizer/Makefile | 49 +- apigateway-http-proxy-authorizer/README.md | 4 +- apigateway-http-proxy-authorizer/main.tf | 26 +- apigateway-http-proxy-authorizer/run.sh | 2 +- apigateway-kinesis-integration/Makefile | 49 +- apigateway-kinesis-integration/README.md | 4 +- apigateway-kinesis-integration/main.tf | 29 +- apigateway-kinesis-integration/run.sh | 4 +- .../Makefile | 49 +- .../README.md | 4 +- apigateway-kinesis-lambda-integration/main.tf | 19 +- apigateway-kinesis-lambda-integration/run.sh | 2 +- apigateway-lambda-cors/Makefile | 49 +- apigateway-lambda-cors/README.md | 4 +- apigateway-lambda-cors/main.tf | 11 +- apigateway-lambda-cors/run.sh | 2 +- apigateway-rest-cors/Makefile | 49 +- apigateway-rest-cors/README.md | 4 +- apigateway-rest-cors/main.tf | 4 + apigateway-rest-cors/run.sh | 4 +- apigateway-sns-deploy/Makefile | 49 +- apigateway-sns-deploy/README.md | 4 +- apigateway-sns-deploy/main.tf | 25 +- apigateway-sns-deploy/run.sh | 2 +- apigateway-stage-cluster/Makefile | 49 +- apigateway-stage-cluster/README.md | 4 +- apigateway-stage-cluster/run.sh | 4 +- apigateway-stage-variables/Makefile | 49 +- apigateway-stage-variables/README.md | 4 +- apigateway-stage-variables/main.tf | 9 +- apigateway-stage-variables/run.sh | 2 +- .../Makefile | 49 +- .../README.md | 4 +- apigateway-step-functions-integration/main.tf | 6 +- apigateway-step-functions-integration/run.sh | 23 +- .../Makefile | 49 +- .../README.md | 4 +- apigatewayv2-http-kinesis-integration/run.sh | 2 +- .../Makefile | 49 +- .../README.md | 4 +- .../run.sh | 2 +- .../Makefile | 49 +- .../README.md | 4 +- apigatewayv2-lambda-proxy-integration/main.tf | 8 +- apigatewayv2-lambda-proxy-integration/run.sh | 34 +- apigatewayv2-lambda-proxy/Makefile | 49 +- apigatewayv2-lambda-proxy/README.md | 4 +- apigatewayv2-lambda-proxy/main.tf | 14 + apigatewayv2-lambda-proxy/run.sh | 2 +- .../Makefile | 49 +- .../README.md | 4 +- .../main.tf | 2 +- .../run.sh | 4 +- .../Makefile | 49 +- .../README.md | 4 +- .../lambda-auth.js | 2 +- .../lambda-auth.zip | Bin 647 -> 603 bytes .../main.tf | 22 + .../run.sh | 19 +- .../Makefile | 49 +- .../README.md | 4 +- .../run.sh | 4 +- apigatewayv2-ws-http-proxy/Makefile | 46 +- apigatewayv2-ws-http-proxy/README.md | 4 +- apigatewayv2-ws-http/Makefile | 46 +- apigatewayv2-ws-http/README.md | 4 +- apigatewayv2-ws-http/run.sh | 2 +- apigatewayv2-ws-kinesis-integration/Makefile | 46 +- apigatewayv2-ws-kinesis-integration/README.md | 4 +- apigatewayv2-ws-kinesis-integration/main.tf | 2 +- apigatewayv2-ws-kinesis-integration/run.sh | 4 +- apigatewayv2-ws-request-authorizer/Makefile | 46 +- apigatewayv2-ws-request-authorizer/README.md | 10 +- apigatewayv2-ws-sample/Makefile | 46 +- apigatewayv2-ws-sample/README.md | 4 +- apigatewayv2-ws-sample/main.tf | 4 - apigatewayv2-ws-sample/run.sh | 2 +- apigatewayv2-ws-sns/Makefile | 46 +- apigatewayv2-ws-sns/README.md | 4 +- apigatewayv2-ws-sns/main.tf | 2 +- apigatewayv2-ws-sqs/Makefile | 46 +- apigatewayv2-ws-sqs/README.md | 4 +- apigatewayv2-ws-sqs/main.tf | 4 +- apigatewayv2-ws-sqs/run.sh | 4 +- apigatewayv2-ws-sub-protocol/Makefile | 46 +- apigatewayv2-ws-sub-protocol/README.md | 4 +- cognito-group-example/Makefile | 46 +- cognito-group-example/README.md | 4 +- common.mk | 65 + demo-deploy/Makefile | 46 +- demo-deploy/README.md | 4 +- full-log | 6224 +++++++++++++++++ lambda-kinesis-firehose-es/Makefile | 49 +- lambda-kinesis-firehose-es/README.md | 6 +- lambda-kinesis-firehose-es/run.sh | 4 +- managed-streaming-kafka-cluster/Makefile | 56 +- managed-streaming-kafka-cluster/README.md | 4 +- managed-streaming-kafka-cluster/main.tf | 2 +- s3-sqs-notifications/Makefile | 49 +- s3-sqs-notifications/README.md | 4 +- s3-sqs-notifications/run.sh | 4 +- s3-static-website/Makefile | 43 +- s3-static-website/README.md | 5 +- s3-static-website/deploy.ps1 | 146 +- .../apigateway-appsync-integration/main.tf | 4 +- .../apigateway-aws-transfer/main.tf | 6 +- .../apigateway-lambda-proxy/main.tf | 9 +- .../apigateway-openapi-3.0-import/main.tf | 6 +- .../main.tf | 2 +- sample-archive/apigateway-s3-deploy/main.tf | 2 +- .../apigateway-sqs-integration/main.tf | 2 +- .../main.tf | 4 +- websocket-deploy/Makefile | 46 +- websocket-deploy/README.md | 4 +- websocket-deploy/main.tf | 8 - 125 files changed, 6716 insertions(+), 1860 deletions(-) create mode 100644 common.mk create mode 100644 full-log diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index 9da077e..e4734db 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -35,15 +35,12 @@ jobs: terraform_version: 1.8.4 terraform_wrapper: false - - name: Install LocalStack - run: pip install localstack awscli-local[ver1] terraform-local - - - name: Pull the latest docker image - run: docker pull localstack/localstack-pro + - name: Install lstk + run: npm install -g @localstack/lstk - name: Execute tests env: - LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} + LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }} DEBUG: 1 timeout-minutes: 100 run: make test-ci-all diff --git a/.gitignore b/.gitignore index 61deb51..ecc6932 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ __pycache__ .idea logs.txt +cluster_info.json diff --git a/Makefile b/Makefile index dec7278..0713f9f 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +LSTK := lstk --non-interactive + lint: @echo "==> Linting terraform code" @terraform fmt -diff=true -recursive -write=true @@ -12,13 +14,10 @@ lint: ## Run code linter for all projects MAKE_TARGET='lint' make for-each-dir start: ## Start LocalStack infrastructure - localstack start -d - -ready: ## Check if the LocalStack container is up and running. - localstack wait -t 20 && echo "LocalStack is ready to use!" + $(LSTK) start stop: ## Stop LocalStack infrastructure - localstack stop + $(LSTK) stop for-each-dir: ./make-for-each.sh $$MAKE_TARGET $$CMD @@ -26,4 +25,4 @@ for-each-dir: test-ci-all: MAKE_TARGET='test-ci' make for-each-dir -.PHONY: usage install lint start ready stop for-each-dir test-ci-all +.PHONY: usage install lint start stop for-each-dir test-ci-all diff --git a/README.md b/README.md index 8aabb7c..94c8dd2 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,7 @@ Each example in the repository is prefixed with the AWS service being used. For ## Prerequisites - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) — provides `lstk aws` and `lstk terraform` wrappers - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -22,10 +21,10 @@ Set it before running any sample: export LOCALSTACK_AUTH_TOKEN= ``` -Alternatively, use the LocalStack CLI to persist the token: +Alternatively, use the `lstk` CLI to log in and store your credentials in the system keyring: ```bash -localstack auth set-token +lstk login ``` You can find your auth token in the [LocalStack Web Application](https://app.localstack.cloud/workspace/auth-token). diff --git a/acm-route53/Makefile b/acm-route53/Makefile index 869e3d1..3335d9a 100644 --- a/acm-route53/Makefile +++ b/acm-route53/Makefile @@ -1,48 +1,3 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) +TEST_CMD = @$(LSTK) aws acm list-certificates | jq '.CertificateSummaryList[] | select(.CertificateArn != null and .DomainName != null)' >/dev/null && echo "Certificates found with CertificateArn and DomainName" || (echo "No certificates found with CertificateArn and DomainName" && exit 1) -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - @awslocal acm list-certificates | jq '.CertificateSummaryList[] | select(.CertificateArn != null and .DomainName != null)' >/dev/null && echo "Certificates found with CertificateArn and DomainName" || (echo "No certificates found with CertificateArn and DomainName" && exit 1) - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/acm-route53/README.md b/acm-route53/README.md index aea8448..66efd0e 100644 --- a/acm-route53/README.md +++ b/acm-route53/README.md @@ -6,8 +6,7 @@ This example shows how to generate an ACM certificate for a domain via Terraform - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -16,7 +15,6 @@ This example shows how to generate an ACM certificate for a domain via Terraform ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ## Run @@ -24,9 +22,9 @@ make ready To run this example you need to execute: ```bash -tflocal init -tflocal plan -tflocal apply --auto-approve +lstk tf init +lstk tf plan +lstk tf apply --auto-approve ``` ## Testing @@ -34,7 +32,7 @@ tflocal apply --auto-approve Run the following command to test the example: ```bash -awslocal acm list-certificates +lstk aws acm list-certificates ``` You will see the following output: diff --git a/apigateway-dynamodb/Makefile b/apigateway-dynamodb/Makefile index 97eb076..23f8a8f 100644 --- a/apigateway-dynamodb/Makefile +++ b/apigateway-dynamodb/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-dynamodb/README.md b/apigateway-dynamodb/README.md index 289ef19..fb9eff4 100644 --- a/apigateway-dynamodb/README.md +++ b/apigateway-dynamodb/README.md @@ -9,8 +9,7 @@ Localstack sample using Apigateway with DynamoDB backend - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ Localstack sample using Apigateway with DynamoDB backend ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigateway-dynamodb/main.tf b/apigateway-dynamodb/main.tf index 6bd9d71..f651326 100644 --- a/apigateway-dynamodb/main.tf +++ b/apigateway-dynamodb/main.tf @@ -66,7 +66,10 @@ resource "aws_dynamodb_table" "MyDynamoDBTable" { global_secondary_index { name = "PetType-index" - hash_key = "PetType" + key_schema { + attribute_name = "PetType" + key_type = "HASH" + } write_capacity = 5 read_capacity = 5 projection_type = "INCLUDE" @@ -103,7 +106,7 @@ resource "aws_api_gateway_rest_api" "MyApiGatewayRestApi" { "type" : "aws", "credentials" : "${aws_iam_role.APIGWRole.arn}", "httpMethod" : "POST", - "uri" : "arn:aws:apigateway:${data.aws_region.current.name}:dynamodb:action/PutItem", + "uri" : "arn:aws:apigateway:${data.aws_region.current.region}:dynamodb:action/PutItem", "responses" : { "default" : { "statusCode" : "200", @@ -141,7 +144,7 @@ resource "aws_api_gateway_rest_api" "MyApiGatewayRestApi" { "type" : "aws", "credentials" : "${aws_iam_role.APIGWRole.arn}", "httpMethod" : "POST", - "uri" : "arn:aws:apigateway:${data.aws_region.current.name}:dynamodb:action/Query", + "uri" : "arn:aws:apigateway:${data.aws_region.current.region}:dynamodb:action/Query", "responses" : { "default" : { "statusCode" : "200", diff --git a/apigateway-dynamodb/run.sh b/apigateway-dynamodb/run.sh index 879b1f0..ec8420b 100755 --- a/apigateway-dynamodb/run.sh +++ b/apigateway-dynamodb/run.sh @@ -2,11 +2,11 @@ set -x -apikey=$(tflocal output -json | jq -r .apigw_key.value) +apikey=$(lstk tf output -json | jq -r .apigw_key.value) sleep 5 -restapi=$(aws apigateway --endpoint-url=http://localhost:4566 get-rest-apis | jq -r .items[0].id) +restapi=$(lstk aws apigateway get-rest-apis | jq -r .items[0].id) curl $restapi.execute-api.localhost.localstack.cloud:4566/v1/pets -H "x-api-key: ${apikey}" -H 'Content-Type: application/json' --request POST --data-raw '{ "PetType": "dog", "PetName": "tito", "PetPrice": 250 }' response=$(curl -H "x-api-key: ${apikey}" --request GET $restapi.execute-api.localhost.localstack.cloud:4566/v1/pets/dog) diff --git a/apigateway-http-proxy-authorizer/Makefile b/apigateway-http-proxy-authorizer/Makefile index 97eb076..23f8a8f 100644 --- a/apigateway-http-proxy-authorizer/Makefile +++ b/apigateway-http-proxy-authorizer/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-http-proxy-authorizer/README.md b/apigateway-http-proxy-authorizer/README.md index df0a069..c582529 100644 --- a/apigateway-http-proxy-authorizer/README.md +++ b/apigateway-http-proxy-authorizer/README.md @@ -6,8 +6,7 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -16,7 +15,6 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ## Run Sample diff --git a/apigateway-http-proxy-authorizer/main.tf b/apigateway-http-proxy-authorizer/main.tf index b6b06ee..e5f97b5 100644 --- a/apigateway-http-proxy-authorizer/main.tf +++ b/apigateway-http-proxy-authorizer/main.tf @@ -48,7 +48,7 @@ resource "aws_api_gateway_integration" "integration" { http_method = aws_api_gateway_method.method_get.http_method type = "HTTP_PROXY" - integration_http_method = "POST" + integration_http_method = "GET" uri = "http://httpbin.org/anything/{proxy}" } @@ -97,3 +97,27 @@ resource "aws_iam_role" "role" { } POLICY } + +resource "aws_api_gateway_deployment" "deployment" { + rest_api_id = aws_api_gateway_rest_api.rest.id + + triggers = { + redeployment = sha1(jsonencode([ + aws_api_gateway_resource.proxy.id, + aws_api_gateway_method.method_get.id, + aws_api_gateway_method.method_post.id, + aws_api_gateway_integration.integration.id, + aws_api_gateway_integration.integration_post.id, + ])) + } + + lifecycle { + create_before_destroy = true + } +} + +resource "aws_api_gateway_stage" "local" { + rest_api_id = aws_api_gateway_rest_api.rest.id + deployment_id = aws_api_gateway_deployment.deployment.id + stage_name = "local" +} diff --git a/apigateway-http-proxy-authorizer/run.sh b/apigateway-http-proxy-authorizer/run.sh index ebd6a80..e722fbe 100755 --- a/apigateway-http-proxy-authorizer/run.sh +++ b/apigateway-http-proxy-authorizer/run.sh @@ -3,7 +3,7 @@ set -x # Get the API Gateway ID -restapi=$(aws apigateway --endpoint-url=http://localhost:4566 get-rest-apis | jq -r .items[0].id) +restapi=$(lstk aws apigateway get-rest-apis | jq -r .items[0].id) # Make the curl request and capture the response response=$(curl -s http://$restapi.execute-api.localhost.localstack.cloud:4566/local/proxy) diff --git a/apigateway-kinesis-integration/Makefile b/apigateway-kinesis-integration/Makefile index 97eb076..23f8a8f 100644 --- a/apigateway-kinesis-integration/Makefile +++ b/apigateway-kinesis-integration/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-kinesis-integration/README.md b/apigateway-kinesis-integration/README.md index 93d622e..fffd077 100644 --- a/apigateway-kinesis-integration/README.md +++ b/apigateway-kinesis-integration/README.md @@ -9,8 +9,7 @@ This project contains an example of an API Gateway with Kinesis Integration. - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This project contains an example of an API Gateway with Kinesis Integration. ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigateway-kinesis-integration/main.tf b/apigateway-kinesis-integration/main.tf index afbb070..8abbe8a 100644 --- a/apigateway-kinesis-integration/main.tf +++ b/apigateway-kinesis-integration/main.tf @@ -73,7 +73,7 @@ resource "aws_iam_policy" "put-record-policy" { { "Effect": "Allow", "Action": "kinesis:PutRecord", - "Resource": "arn:aws:kinesis:${data.aws_region.current.name}:${data.aws_caller_identity.current + "Resource": "arn:aws:kinesis:${data.aws_region.current.region}:${data.aws_caller_identity.current .account_id}:stream/${aws_kinesis_stream.stream.name}" } ] @@ -93,7 +93,7 @@ resource "aws_api_gateway_integration" "integration" { integration_http_method = "POST" type = "AWS" credentials = aws_iam_role.apigw-role.arn - uri = "arn:aws:apigateway:${data.aws_region.current.name}:kinesis:action/PutRecord" + uri = "arn:aws:apigateway:${data.aws_region.current.region}:kinesis:action/PutRecord" passthrough_behavior = "NEVER" @@ -187,8 +187,17 @@ resource "aws_api_gateway_integration_response" "integration_error_response" { resource "aws_api_gateway_deployment" "deployment" { rest_api_id = aws_api_gateway_rest_api.rest.id - stage_name = "dev" - depends_on = [aws_api_gateway_integration.integration] + depends_on = [ + aws_api_gateway_integration.integration, + aws_api_gateway_integration_response.integration_success_response, + aws_api_gateway_integration_response.integration_error_response, + ] +} + +resource "aws_api_gateway_stage" "stage" { + rest_api_id = aws_api_gateway_rest_api.rest.id + deployment_id = aws_api_gateway_deployment.deployment.id + stage_name = "dev" } @@ -211,10 +220,9 @@ resource "aws_kinesis_stream" "stream" { } resource "aws_iam_role" "role" { - name = random_pet.random.id - path = "/" - managed_policy_arns = ["arn:aws:iam::aws:policy/AmazonKinesisFullAccess"] - assume_role_policy = < logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-kinesis-lambda-integration/README.md b/apigateway-kinesis-lambda-integration/README.md index f3f1d06..b3fc97f 100644 --- a/apigateway-kinesis-lambda-integration/README.md +++ b/apigateway-kinesis-lambda-integration/README.md @@ -9,8 +9,7 @@ This project contains an example of an API Gateway with Kinesis Integration usin - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This project contains an example of an API Gateway with Kinesis Integration usin ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigateway-kinesis-lambda-integration/main.tf b/apigateway-kinesis-lambda-integration/main.tf index 521fe0b..e1e08e2 100644 --- a/apigateway-kinesis-lambda-integration/main.tf +++ b/apigateway-kinesis-lambda-integration/main.tf @@ -48,7 +48,7 @@ resource "aws_lambda_permission" "apigw_lambda" { principal = "apigateway.amazonaws.com" # More: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html - source_arn = "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.rest.id}/*/${aws_api_gateway_method.method.http_method}${aws_api_gateway_resource.root.path}" + source_arn = "arn:aws:execute-api:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.rest.id}/*/${aws_api_gateway_method.method.http_method}${aws_api_gateway_resource.root.path}" } # @@ -152,8 +152,21 @@ resource "aws_api_gateway_integration_response" "integration_error_response" { resource "aws_api_gateway_deployment" "deployment" { rest_api_id = aws_api_gateway_rest_api.rest.id - stage_name = "dev" - depends_on = [aws_api_gateway_integration.integration] + depends_on = [ + aws_api_gateway_integration.integration, + aws_api_gateway_integration_response.integration_success_response, + aws_api_gateway_integration_response.integration_error_response, + ] + + lifecycle { + create_before_destroy = true + } +} + +resource "aws_api_gateway_stage" "stage" { + rest_api_id = aws_api_gateway_rest_api.rest.id + deployment_id = aws_api_gateway_deployment.deployment.id + stage_name = "dev" } # diff --git a/apigateway-kinesis-lambda-integration/run.sh b/apigateway-kinesis-lambda-integration/run.sh index 88aeae0..7beabae 100755 --- a/apigateway-kinesis-lambda-integration/run.sh +++ b/apigateway-kinesis-lambda-integration/run.sh @@ -3,7 +3,7 @@ set -x # Get the API Gateway ID -restapi=$(aws apigateway --endpoint-url=http://localhost:4566 get-rest-apis | jq -r .items[0].id) +restapi=$(lstk aws apigateway get-rest-apis | jq -r .items[0].id) # Make the curl request and capture the response response=$(curl -s -X POST "$restapi.execute-api.localhost.localstack.cloud:4566/dev/api?who=god") diff --git a/apigateway-lambda-cors/Makefile b/apigateway-lambda-cors/Makefile index 97eb076..23f8a8f 100644 --- a/apigateway-lambda-cors/Makefile +++ b/apigateway-lambda-cors/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-lambda-cors/README.md b/apigateway-lambda-cors/README.md index 5cdccd0..d9e7293 100644 --- a/apigateway-lambda-cors/README.md +++ b/apigateway-lambda-cors/README.md @@ -9,8 +9,7 @@ This sample shows how to create a lambda function and expose it through an API G - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This sample shows how to create a lambda function and expose it through an API G ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigateway-lambda-cors/main.tf b/apigateway-lambda-cors/main.tf index c7d101f..6ec3677 100644 --- a/apigateway-lambda-cors/main.tf +++ b/apigateway-lambda-cors/main.tf @@ -28,12 +28,11 @@ resource "aws_api_gateway_integration" "integration" { http_method = aws_api_gateway_method.method.http_method integration_http_method = "POST" type = "AWS_PROXY" - uri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/${aws_lambda_function.lambda.arn}/invocations" + uri = "arn:aws:apigateway:${data.aws_region.current.region}:lambda:path/2015-03-31/functions/${aws_lambda_function.lambda.arn}/invocations" } resource "aws_api_gateway_deployment" "deployment" { rest_api_id = aws_api_gateway_rest_api.api.id - stage_name = "dev" triggers = { # NOTE: The configuration below will satisfy ordering considerations, @@ -55,6 +54,12 @@ resource "aws_api_gateway_deployment" "deployment" { } } +resource "aws_api_gateway_stage" "stage" { + rest_api_id = aws_api_gateway_rest_api.api.id + deployment_id = aws_api_gateway_deployment.deployment.id + stage_name = "dev" +} + resource "aws_lambda_permission" "apigw_lambda" { statement_id = "AllowExecutionFromAPIGateway" action = "lambda:InvokeFunction" @@ -101,5 +106,5 @@ resource "aws_lambda_function" "lambda" { } output "api_url" { - value = aws_api_gateway_deployment.deployment.invoke_url + value = aws_api_gateway_stage.stage.invoke_url } diff --git a/apigateway-lambda-cors/run.sh b/apigateway-lambda-cors/run.sh index f1a8331..fe35a2a 100755 --- a/apigateway-lambda-cors/run.sh +++ b/apigateway-lambda-cors/run.sh @@ -3,7 +3,7 @@ set -x # Get the API Gateway ID -restapi=$(aws apigateway --endpoint-url=http://localhost:4566 get-rest-apis | jq -r .items[0].id) +restapi=$(lstk aws apigateway get-rest-apis | jq -r .items[0].id) # Make the curl request and capture the response response=$(curl -s -X POST "$restapi.execute-api.localhost.localstack.cloud:4566/dev/cors" -d "bye") diff --git a/apigateway-rest-cors/Makefile b/apigateway-rest-cors/Makefile index 97eb076..23f8a8f 100644 --- a/apigateway-rest-cors/Makefile +++ b/apigateway-rest-cors/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-rest-cors/README.md b/apigateway-rest-cors/README.md index 2b2c063..fffb5d8 100644 --- a/apigateway-rest-cors/README.md +++ b/apigateway-rest-cors/README.md @@ -9,8 +9,7 @@ This project contains an API Gateway sample using MOCK integration to configure - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This project contains an API Gateway sample using MOCK integration to configure ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigateway-rest-cors/main.tf b/apigateway-rest-cors/main.tf index 97509fb..40e0066 100644 --- a/apigateway-rest-cors/main.tf +++ b/apigateway-rest-cors/main.tf @@ -75,6 +75,10 @@ resource "aws_api_gateway_integration_response" "options_integration_response" { "method.response.header.Access-Control-Allow-Origin" = "'*'" } + response_templates = { + "application/json" = jsonencode({ statusCode = 200 }) + } + depends_on = [ aws_api_gateway_method.options_method, aws_api_gateway_method_response.options_200, diff --git a/apigateway-rest-cors/run.sh b/apigateway-rest-cors/run.sh index 098bfb7..32660b0 100755 --- a/apigateway-rest-cors/run.sh +++ b/apigateway-rest-cors/run.sh @@ -1,10 +1,10 @@ #!/usr/bin/env sh # Get the API Gateway ID -restapi=$(aws --endpoint-url=http://localhost:4566 apigateway get-rest-apis | jq -r .items[0].id) +restapi=$(lstk aws apigateway get-rest-apis | jq -r .items[0].id) # Make the curl request and capture the response -response=$(curl -s -X OPTIONS "http://localhost:4566/restapis/$restapi/local/_user_request_/test" -H "Access-Control-Request-Headers: Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token") +response=$(curl -s -X OPTIONS "http://localhost:4566/restapis/$restapi/dev/_user_request_/test" -H "Access-Control-Request-Headers: Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token") # Output the response for debugging purposes echo "API Response: $response" diff --git a/apigateway-sns-deploy/Makefile b/apigateway-sns-deploy/Makefile index 97eb076..23f8a8f 100644 --- a/apigateway-sns-deploy/Makefile +++ b/apigateway-sns-deploy/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-sns-deploy/README.md b/apigateway-sns-deploy/README.md index e66ed1b..d170f8b 100644 --- a/apigateway-sns-deploy/README.md +++ b/apigateway-sns-deploy/README.md @@ -6,8 +6,7 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -16,7 +15,6 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ## Run Sample diff --git a/apigateway-sns-deploy/main.tf b/apigateway-sns-deploy/main.tf index 20e499d..ada8449 100644 --- a/apigateway-sns-deploy/main.tf +++ b/apigateway-sns-deploy/main.tf @@ -24,7 +24,7 @@ resource "aws_api_gateway_integration" "integration" { integration_http_method = "POST" type = "AWS" credentials = aws_iam_role.sns_publish.arn - uri = "arn:aws:apigateway:${data.aws_region.current.name}:sns:path//" + uri = "arn:aws:apigateway:${data.aws_region.current.region}:sns:path//" request_parameters = { "integration.request.header.Content-Type" = "'application/x-www-form-urlencoded'" @@ -96,3 +96,26 @@ data "aws_iam_policy_document" "sns_publish" { ] } } + +resource "aws_api_gateway_deployment" "deployment" { + rest_api_id = aws_api_gateway_rest_api.rest.id + + triggers = { + redeployment = sha1(jsonencode([ + aws_api_gateway_resource.ingest.id, + aws_api_gateway_method.method.id, + aws_api_gateway_integration.integration.id, + aws_api_gateway_integration_response.integration_response.id, + ])) + } + + lifecycle { + create_before_destroy = true + } +} + +resource "aws_api_gateway_stage" "local" { + rest_api_id = aws_api_gateway_rest_api.rest.id + deployment_id = aws_api_gateway_deployment.deployment.id + stage_name = "local" +} diff --git a/apigateway-sns-deploy/run.sh b/apigateway-sns-deploy/run.sh index 6b5efd2..828ebe9 100755 --- a/apigateway-sns-deploy/run.sh +++ b/apigateway-sns-deploy/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # Get the API Gateway ID -restapi=$(aws apigateway --endpoint-url=http://localhost:4566 get-rest-apis | jq -r .items[0].id) +restapi=$(lstk aws apigateway get-rest-apis | jq -r .items[0].id) # Make the curl request and capture the response response=$(curl -s -X POST "$restapi.execute-api.localhost.localstack.cloud:4566/local/ingest" -H 'Content-Type: application/json' -d '{ diff --git a/apigateway-stage-cluster/Makefile b/apigateway-stage-cluster/Makefile index 97eb076..23f8a8f 100644 --- a/apigateway-stage-cluster/Makefile +++ b/apigateway-stage-cluster/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-stage-cluster/README.md b/apigateway-stage-cluster/README.md index e1916be..54f49b1 100644 --- a/apigateway-stage-cluster/README.md +++ b/apigateway-stage-cluster/README.md @@ -6,8 +6,7 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -16,7 +15,6 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ## Run Sample diff --git a/apigateway-stage-cluster/run.sh b/apigateway-stage-cluster/run.sh index 1add7c0..c6ead3b 100755 --- a/apigateway-stage-cluster/run.sh +++ b/apigateway-stage-cluster/run.sh @@ -1,10 +1,10 @@ #!/usr/bin/env sh # Get the API Gateway ID -restapi=$(aws --endpoint-url=http://localhost:4566 apigateway get-rest-apis | jq -r .items[0].id) +restapi=$(lstk aws apigateway get-rest-apis | jq -r .items[0].id) # Make the curl request and capture the response -response=$(curl -s -X POST "$restapi.execute-api.localhost.localstack.cloud:4566/local/test" -H 'content-type: application/json') +response=$(curl -s -X POST "$restapi.execute-api.localhost.localstack.cloud:4566/dev/test" -H 'content-type: application/json') # Output the response for debugging purposes echo "API Response: $response" diff --git a/apigateway-stage-variables/Makefile b/apigateway-stage-variables/Makefile index 97eb076..23f8a8f 100644 --- a/apigateway-stage-variables/Makefile +++ b/apigateway-stage-variables/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-stage-variables/README.md b/apigateway-stage-variables/README.md index 0edf69e..a9fc3ab 100644 --- a/apigateway-stage-variables/README.md +++ b/apigateway-stage-variables/README.md @@ -11,8 +11,7 @@ Refer to the [AWS documentation](https://docs.aws.amazon.com/apigateway/latest/d - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -21,7 +20,6 @@ Refer to the [AWS documentation](https://docs.aws.amazon.com/apigateway/latest/d ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigateway-stage-variables/main.tf b/apigateway-stage-variables/main.tf index ec4a1a4..ed4368b 100644 --- a/apigateway-stage-variables/main.tf +++ b/apigateway-stage-variables/main.tf @@ -31,7 +31,7 @@ resource "aws_api_gateway_integration" "integration" { http_method = aws_api_gateway_method.method.http_method integration_http_method = "POST" # Must be POST for invoking Lambda function - uri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:$${stageVariables.lambdaFunction}/invocations" + uri = "arn:aws:apigateway:${data.aws_region.current.region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:function:$${stageVariables.lambdaFunction}/invocations" request_templates = { "application/json" = < logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigateway-step-functions-integration/README.md b/apigateway-step-functions-integration/README.md index 676942a..9379079 100644 --- a/apigateway-step-functions-integration/README.md +++ b/apigateway-step-functions-integration/README.md @@ -9,8 +9,7 @@ This project contains a sample of how to use a StateMachine as a target for an A - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This project contains a sample of how to use a StateMachine as a target for an A ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigateway-step-functions-integration/main.tf b/apigateway-step-functions-integration/main.tf index 0e0432d..619810d 100644 --- a/apigateway-step-functions-integration/main.tf +++ b/apigateway-step-functions-integration/main.tf @@ -48,7 +48,7 @@ resource "aws_api_gateway_integration" "integration" { credentials = aws_iam_role.apigateway.arn http_method = aws_api_gateway_method.method.http_method type = "AWS" - uri = "arn:aws:apigateway:${data.aws_region.current.name}:states:action/StartExecution" + uri = "arn:aws:apigateway:${data.aws_region.current.region}:states:action/StartExecution" integration_http_method = "POST" request_templates = { @@ -116,7 +116,7 @@ resource "aws_api_gateway_deployment" "deployment" { create_before_destroy = true } - depends_on = [aws_api_gateway_rest_api.api, aws_api_gateway_method.method, aws_api_gateway_integration.integration] + depends_on = [aws_api_gateway_rest_api.api, aws_api_gateway_method.method, aws_api_gateway_integration.integration, aws_api_gateway_integration_response.response_200] } data "aws_iam_policy_document" "sfn_assume" { @@ -189,7 +189,7 @@ resource "aws_lambda_function" "lambda" { source_code_hash = filebase64sha256("lambda.zip") - runtime = "nodejs14.x" + runtime = "nodejs18.x" } resource "aws_iam_role" "lambda_role" { diff --git a/apigateway-step-functions-integration/run.sh b/apigateway-step-functions-integration/run.sh index bdbb5d6..c174dd4 100755 --- a/apigateway-step-functions-integration/run.sh +++ b/apigateway-step-functions-integration/run.sh @@ -1,10 +1,10 @@ #!/usr/bin/env sh # Get the API Gateway ID -restapi=$(aws --endpoint-url=http://localhost:4566 apigateway get-rest-apis | jq -r .items[0].id) +restapi=$(lstk aws apigateway get-rest-apis | jq -r .items[0].id) # Make the curl request and capture the response -response=$(curl -s -X POST "$restapi.execute-api.localhost.localstack.cloud:4566/local/test" -H 'content-type: application/json' -d '{ "input": "{}", "name": "MyExecution"}') +response=$(curl -s -X POST "$restapi.execute-api.localhost.localstack.cloud:4566/dev/test" -H 'content-type: application/json' -d '{ "input": "{}", "name": "MyExecution"}') # Output the response for debugging purposes echo "API Response: $response" @@ -13,24 +13,27 @@ echo "API Response: $response" execution_arn=$(echo "$response" | jq -r .executionArn) # Check if the execution ARN was extracted successfully -if [ -z "$execution_arn" ]; then +if [ -z "$execution_arn" ] || [ "$execution_arn" = "null" ]; then echo "Smoke test failed: Execution ARN not found in the response." exit 1 fi -# Wait for 5 seconds before checking the status -sleep 5 - -# Describe the execution and capture the response -execution_response=$(awslocal stepfunctions describe-execution --execution-arn "$execution_arn") +# Poll the execution status until it leaves the RUNNING state (up to ~30s) +status="RUNNING" +for _ in $(seq 1 15); do + execution_response=$(lstk aws stepfunctions describe-execution --execution-arn "$execution_arn") + status=$(echo "$execution_response" | jq -r .status) + [ "$status" = "RUNNING" ] || break + sleep 2 +done # Output the execution response for debugging purposes echo "Execution Response: $execution_response" # Smoke test to validate the status -if echo "$execution_response" | jq -e '.status == "SUCCEEDED"' > /dev/null; then +if [ "$status" = "SUCCEEDED" ]; then echo "Smoke test passed: The execution status is 'SUCCEEDED'." else - echo "Smoke test failed: The execution status is not 'SUCCEEDED'." + echo "Smoke test failed: The execution status is '$status'." exit 1 fi diff --git a/apigatewayv2-http-kinesis-integration/Makefile b/apigatewayv2-http-kinesis-integration/Makefile index 97eb076..23f8a8f 100644 --- a/apigatewayv2-http-kinesis-integration/Makefile +++ b/apigatewayv2-http-kinesis-integration/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-http-kinesis-integration/README.md b/apigatewayv2-http-kinesis-integration/README.md index 83e78c1..925c3fe 100644 --- a/apigatewayv2-http-kinesis-integration/README.md +++ b/apigatewayv2-http-kinesis-integration/README.md @@ -9,8 +9,7 @@ This template creates an HTTP API that forwards the request body to a Kinesis st - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This template creates an HTTP API that forwards the request body to a Kinesis st ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigatewayv2-http-kinesis-integration/run.sh b/apigatewayv2-http-kinesis-integration/run.sh index 69b2987..a149ea2 100755 --- a/apigatewayv2-http-kinesis-integration/run.sh +++ b/apigatewayv2-http-kinesis-integration/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # Get the API Gateway ID -httpapi=$(aws --endpoint-url=http://localhost:4566 apigatewayv2 get-apis | jq -r .Items[0].ApiId) +httpapi=$(lstk aws apigatewayv2 get-apis | jq -r .Items[0].ApiId) # Make the curl request and capture the response response=$(curl -s -X POST "$httpapi.execute-api.localhost.localstack.cloud:4566/" \ diff --git a/apigatewayv2-lambda-proxy-handling-binary/Makefile b/apigatewayv2-lambda-proxy-handling-binary/Makefile index 97eb076..23f8a8f 100644 --- a/apigatewayv2-lambda-proxy-handling-binary/Makefile +++ b/apigatewayv2-lambda-proxy-handling-binary/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-lambda-proxy-handling-binary/README.md b/apigatewayv2-lambda-proxy-handling-binary/README.md index 0575a2a..6e75154 100644 --- a/apigatewayv2-lambda-proxy-handling-binary/README.md +++ b/apigatewayv2-lambda-proxy-handling-binary/README.md @@ -6,8 +6,7 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -16,7 +15,6 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ## Run Sample diff --git a/apigatewayv2-lambda-proxy-handling-binary/run.sh b/apigatewayv2-lambda-proxy-handling-binary/run.sh index d966bc0..81dadb5 100755 --- a/apigatewayv2-lambda-proxy-handling-binary/run.sh +++ b/apigatewayv2-lambda-proxy-handling-binary/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # Get the API Gateway ID -api_id=$(aws apigatewayv2 --endpoint-url=http://localhost:4566 get-apis | jq -r .Items[0].ApiId) +api_id=$(lstk aws apigatewayv2 get-apis | jq -r .Items[0].ApiId) # Make the curl request and save the output to output.jpg curl -s -X POST -H 'content-type: image/jpeg' --data-binary @./nyan-cat.jpg http://$api_id.execute-api.localhost.localstack.cloud:4566/example/test/foo/bar --output output.jpg diff --git a/apigatewayv2-lambda-proxy-integration/Makefile b/apigatewayv2-lambda-proxy-integration/Makefile index 97eb076..23f8a8f 100644 --- a/apigatewayv2-lambda-proxy-integration/Makefile +++ b/apigatewayv2-lambda-proxy-integration/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-lambda-proxy-integration/README.md b/apigatewayv2-lambda-proxy-integration/README.md index 18cc141..b2a5f69 100644 --- a/apigatewayv2-lambda-proxy-integration/README.md +++ b/apigatewayv2-lambda-proxy-integration/README.md @@ -9,8 +9,7 @@ A simple example of an API Gateway V2 with Lambda Proxy Integration. - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ A simple example of an API Gateway V2 with Lambda Proxy Integration. ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigatewayv2-lambda-proxy-integration/main.tf b/apigatewayv2-lambda-proxy-integration/main.tf index e093f8e..7e79f91 100644 --- a/apigatewayv2-lambda-proxy-integration/main.tf +++ b/apigatewayv2-lambda-proxy-integration/main.tf @@ -70,7 +70,7 @@ resource "aws_lambda_permission" "default" { function_name = aws_lambda_function.package.function_name principal = "apigateway.amazonaws.com" - source_arn = "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.api.id}/$default/$default" + source_arn = "arn:aws:execute-api:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.api.id}/$default/$default" } resource "aws_lambda_permission" "package" { @@ -79,7 +79,7 @@ resource "aws_lambda_permission" "package" { function_name = aws_lambda_function.package.function_name principal = "apigateway.amazonaws.com" - source_arn = "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.api.id}/*/*" + source_arn = "arn:aws:execute-api:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.api.id}/*/*" } resource "aws_lambda_permission" "package_payload" { @@ -88,7 +88,7 @@ resource "aws_lambda_permission" "package_payload" { function_name = aws_lambda_function.package_payload.function_name principal = "apigateway.amazonaws.com" - source_arn = "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.api.id}/*/*" + source_arn = "arn:aws:execute-api:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.api.id}/*/*" } resource "aws_lambda_function" "package_payload" { @@ -158,7 +158,7 @@ resource "aws_cloudwatch_log_group" "access_logs" { resource "aws_apigatewayv2_stage" "stage" { api_id = aws_apigatewayv2_api.api.id - name = "dev" + name = "$default" auto_deploy = true diff --git a/apigatewayv2-lambda-proxy-integration/run.sh b/apigatewayv2-lambda-proxy-integration/run.sh index dc07c56..ab35b48 100755 --- a/apigatewayv2-lambda-proxy-integration/run.sh +++ b/apigatewayv2-lambda-proxy-integration/run.sh @@ -1,29 +1,31 @@ #!/usr/bin/env sh # Get the API Gateway ID -http_api=$(aws --endpoint-url=http://localhost:4566 apigatewayv2 get-apis | jq -r .Items[0].ApiId) +http_api=$(lstk aws apigatewayv2 get-apis | jq -r .Items[0].ApiId) -# Make the curl requests and capture the responses -response1=$(curl -s -X POST "$http_api.execute-api.localhost.localstack.cloud:4566/package/123/payloads") -response2=$(curl -s -X POST "$http_api.execute-api.localhost.localstack.cloud:4566/package") -response3=$(curl -s -X POST "$http_api.execute-api.localhost.localstack.cloud:4566/") +# Make the curl requests and capture the HTTP status codes. +# The Lambda returns a proxy response of {"statusCode": 200, ...} with no body, +# so we assert on the HTTP status code rather than the (empty) response body. +status1=$(curl -s -o /dev/null -w '%{http_code}' -X POST "$http_api.execute-api.localhost.localstack.cloud:4566/package/123/payloads") +status2=$(curl -s -o /dev/null -w '%{http_code}' -X POST "$http_api.execute-api.localhost.localstack.cloud:4566/package") +status3=$(curl -s -o /dev/null -w '%{http_code}' -X POST "$http_api.execute-api.localhost.localstack.cloud:4566/") -# Output the responses for debugging purposes -echo "Response 1: $response1" -echo "Response 2: $response2" -echo "Response 3: $response3" +# Output the statuses for debugging purposes +echo "Status 1: $status1" +echo "Status 2: $status2" +echo "Status 3: $status3" # Smoke test to validate the outputs check_status_code() { - response=$1 - if echo "$response" | jq -e '.statusCode == 200' > /dev/null; then - echo "Smoke test passed: The response contains 'statusCode: 200'." + status=$1 + if [ "$status" = "200" ]; then + echo "Smoke test passed: The response status code is 200." else - echo "Smoke test failed: The response does not contain 'statusCode: 200'." + echo "Smoke test failed: The response status code is '$status', not 200." exit 1 fi } -check_status_code "$response1" -check_status_code "$response2" -check_status_code "$response3" +check_status_code "$status1" +check_status_code "$status2" +check_status_code "$status3" diff --git a/apigatewayv2-lambda-proxy/Makefile b/apigatewayv2-lambda-proxy/Makefile index 97eb076..23f8a8f 100644 --- a/apigatewayv2-lambda-proxy/Makefile +++ b/apigatewayv2-lambda-proxy/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-lambda-proxy/README.md b/apigatewayv2-lambda-proxy/README.md index 395fa40..6f20da7 100644 --- a/apigatewayv2-lambda-proxy/README.md +++ b/apigatewayv2-lambda-proxy/README.md @@ -8,8 +8,7 @@ This example creates a HTTP proxy endpoint with a Lambda Proxy integration. - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -18,7 +17,6 @@ This example creates a HTTP proxy endpoint with a Lambda Proxy integration. ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ## Run Sample diff --git a/apigatewayv2-lambda-proxy/main.tf b/apigatewayv2-lambda-proxy/main.tf index 8db2c50..0f83fa0 100644 --- a/apigatewayv2-lambda-proxy/main.tf +++ b/apigatewayv2-lambda-proxy/main.tf @@ -21,6 +21,20 @@ resource "aws_apigatewayv2_route" "example" { target = "integrations/${aws_apigatewayv2_integration.example.id}" } +resource "aws_apigatewayv2_stage" "example" { + api_id = aws_apigatewayv2_api.example.id + name = "$default" + auto_deploy = true +} + +resource "aws_lambda_permission" "apigw" { + statement_id = "AllowExecutionFromAPIGateway" + action = "lambda:InvokeFunction" + function_name = aws_lambda_function.lambda.function_name + principal = "apigateway.amazonaws.com" + source_arn = "${aws_apigatewayv2_api.example.execution_arn}/*/*" +} + resource "aws_lambda_function" "lambda" { filename = "lambda.zip" function_name = "mylambda" diff --git a/apigatewayv2-lambda-proxy/run.sh b/apigatewayv2-lambda-proxy/run.sh index 01c0f5b..da6259c 100755 --- a/apigatewayv2-lambda-proxy/run.sh +++ b/apigatewayv2-lambda-proxy/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # Get the API Gateway ID -httpapi=$(aws --endpoint-url=http://localhost:4566 apigatewayv2 get-apis | jq -r .Items[0].ApiId) +httpapi=$(lstk aws apigatewayv2 get-apis | jq -r .Items[0].ApiId) # Make the curl request and capture the response response=$(curl -s -X POST "$httpapi.execute-api.localhost.localstack.cloud:4566/example/test" \ diff --git a/apigatewayv2-lambda-request-authorizer-1.0/Makefile b/apigatewayv2-lambda-request-authorizer-1.0/Makefile index 97eb076..23f8a8f 100644 --- a/apigatewayv2-lambda-request-authorizer-1.0/Makefile +++ b/apigatewayv2-lambda-request-authorizer-1.0/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-lambda-request-authorizer-1.0/README.md b/apigatewayv2-lambda-request-authorizer-1.0/README.md index 1272eb6..f1c9090 100644 --- a/apigatewayv2-lambda-request-authorizer-1.0/README.md +++ b/apigatewayv2-lambda-request-authorizer-1.0/README.md @@ -9,8 +9,7 @@ This project contains a sample Lambda function that can be used as a request aut - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This project contains a sample Lambda function that can be used as a request aut ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigatewayv2-lambda-request-authorizer-1.0/main.tf b/apigatewayv2-lambda-request-authorizer-1.0/main.tf index de1b7f1..2e0d43c 100644 --- a/apigatewayv2-lambda-request-authorizer-1.0/main.tf +++ b/apigatewayv2-lambda-request-authorizer-1.0/main.tf @@ -96,7 +96,7 @@ resource "aws_lambda_permission" "apigw_to_lambda" { resource "aws_apigatewayv2_stage" "testing" { api_id = aws_apigatewayv2_api.apigw.id - name = "testing" + name = "$default" auto_deploy = true access_log_settings { diff --git a/apigatewayv2-lambda-request-authorizer-1.0/run.sh b/apigatewayv2-lambda-request-authorizer-1.0/run.sh index 6365142..c1c234b 100755 --- a/apigatewayv2-lambda-request-authorizer-1.0/run.sh +++ b/apigatewayv2-lambda-request-authorizer-1.0/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # Get the API Gateway ID -httpapi=$(aws --endpoint-url=http://localhost:4566 apigatewayv2 get-apis | jq -r .Items[0].ApiId) +httpapi=$(lstk aws apigatewayv2 get-apis | jq -r .Items[0].ApiId) # Make the curl request and capture the response response=$(curl -s -X POST "$httpapi.execute-api.localhost.localstack.cloud:4566/example/test" -H 'Authorization: secretToken') @@ -10,7 +10,7 @@ response=$(curl -s -X POST "$httpapi.execute-api.localhost.localstack.cloud:4566 echo "API Response: $response" # Smoke test to validate the output -if echo "$response" | grep -q "\"message\":\"Hello from Lambda!\""; then +if echo "$response" | grep -q "Hello from Lambda!"; then echo "Smoke test passed: The response contains 'Hello from Lambda!'." else echo "Smoke test failed: The response does not contain 'Hello from Lambda!'." diff --git a/apigatewayv2-lambda-request-authorizer-2.0/Makefile b/apigatewayv2-lambda-request-authorizer-2.0/Makefile index 97eb076..23f8a8f 100644 --- a/apigatewayv2-lambda-request-authorizer-2.0/Makefile +++ b/apigatewayv2-lambda-request-authorizer-2.0/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-lambda-request-authorizer-2.0/README.md b/apigatewayv2-lambda-request-authorizer-2.0/README.md index 0e8b949..faf2fee 100644 --- a/apigatewayv2-lambda-request-authorizer-2.0/README.md +++ b/apigatewayv2-lambda-request-authorizer-2.0/README.md @@ -6,8 +6,7 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -16,7 +15,6 @@ This sample demonstrates Terraform-based AWS service emulation with LocalStack. ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ## Run Sample diff --git a/apigatewayv2-lambda-request-authorizer-2.0/lambda-auth.js b/apigatewayv2-lambda-request-authorizer-2.0/lambda-auth.js index c004f7a..5b0e1f3 100644 --- a/apigatewayv2-lambda-request-authorizer-2.0/lambda-auth.js +++ b/apigatewayv2-lambda-request-authorizer-2.0/lambda-auth.js @@ -1,6 +1,6 @@ exports.handler = async(event) => { console.log(event) - if (event.headers.Authorization == "secretToken") { + if ((event.headers.Authorization || event.headers.authorization) == "secretToken") { console.log("allowed"); return { "principalId": "abcdef", // The principal user identification associated with the token sent by the client. diff --git a/apigatewayv2-lambda-request-authorizer-2.0/lambda-auth.zip b/apigatewayv2-lambda-request-authorizer-2.0/lambda-auth.zip index ef3fa8cae8e0a2d77f452971f213d53b6ec3dfd5..317795dce9da3c00b870cc6fcdab3b032a2e38eb 100644 GIT binary patch literal 603 zcmWIWW@Zs#U|`^2xRrV$#%F^`*j+{jhR3W7417S*oW$IultkUc(vl3ltm3!9w)wXW z1m@n2FMJ@vJWY5fFV~I&M#h%{CE3k-j%>56Tyrvm9<(Q$eyo2VI3;K2xmgPx#9vmt zzq^}XuJF3V>$`iN?Fz|AWWBRBD&~RM*7=8C8Qbii?bCAcoW>mO&o`8xOc9M)a(Rzi z+@jLYNaxXD7LqtLDAxs-?WgvHA_5Li=OvPxRcE3f9d)I z%|pk74hZsJ%Y82Bbxe&(9& zemUH-|MIMkBgLekfA{{XhfXsV)GkyhzngK{^6}i{GB+Rb3HtZycbt2a?vr^TZ%OxJ z&mgbVi=|4JBR)_5*r zU)*`>VK#qrSmeKYaph+pWA7};yZ^>Z^}(1vdjD%U7Ucu>QBfzWKKecx;#NZ@Q4l_-M;HGm#S$7};()Z@eA$Cg{t8 z6D4bXC-T%T`PlX6d*HOW7T)V^MQ$8j_Cs#IN7s?q7C5%lfizPZCP~=lDb8(Y#}W`7WQn5^}ngZ=fk&m5}ByzSDxlNRkYRLVKwJDqQ*z_-a=Di3Fz ze54hh@-uW={N|ezKODZCTYKlQ;e-iJKkS6cHJXn1m={$p-#+EMN8^m`p{+_>8^TyQx+=*D{1>_5aCsW /dev/null; then - echo "Smoke test passed: The response contains 'statusCode: 200'." +if [ "$status" = "200" ]; then + echo "Smoke test passed: The response status code is 200." else - echo "Smoke test failed: The response does not contain 'statusCode: 200'." + echo "Smoke test failed: The response status code is '$status', not 200." exit 1 fi diff --git a/apigatewayv2-step-functions-integration/Makefile b/apigatewayv2-step-functions-integration/Makefile index 97eb076..23f8a8f 100644 --- a/apigatewayv2-step-functions-integration/Makefile +++ b/apigatewayv2-step-functions-integration/Makefile @@ -1,48 +1 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -test: - ./run.sh - -run: start install init deploy test - -test-ci: - make start install init deploy test; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-step-functions-integration/README.md b/apigatewayv2-step-functions-integration/README.md index aea7efb..d846117 100644 --- a/apigatewayv2-step-functions-integration/README.md +++ b/apigatewayv2-step-functions-integration/README.md @@ -9,8 +9,7 @@ This project contains a sample of how to use a StateMachine as a target for an A - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This project contains a sample of how to use a StateMachine as a target for an A ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigatewayv2-step-functions-integration/run.sh b/apigatewayv2-step-functions-integration/run.sh index a6d3138..a4031ee 100755 --- a/apigatewayv2-step-functions-integration/run.sh +++ b/apigatewayv2-step-functions-integration/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # Get the API Gateway ID -httpapi=$(aws --endpoint-url=http://localhost:4566 apigatewayv2 get-apis | jq -r .Items[0].ApiId) +httpapi=$(lstk aws apigatewayv2 get-apis | jq -r .Items[0].ApiId) # Make the curl request and capture the response response=$(curl -s "$httpapi.execute-api.localhost.localstack.cloud:4566/test" -H 'content-type: application/json' -d '{ "IsHelloWorldExample": "Yes" }') @@ -22,7 +22,7 @@ fi sleep 10 # Describe the execution and capture the response -execution_response=$(awslocal stepfunctions describe-execution --execution-arn "$execution_arn") +execution_response=$(lstk aws stepfunctions describe-execution --execution-arn "$execution_arn") # Output the execution response for debugging purposes echo "Execution Response: $execution_response" diff --git a/apigatewayv2-ws-http-proxy/Makefile b/apigatewayv2-ws-http-proxy/Makefile index 21030a4..fa3fda8 100644 --- a/apigatewayv2-ws-http-proxy/Makefile +++ b/apigatewayv2-ws-http-proxy/Makefile @@ -1,45 +1,3 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) +DEPLOY_STEPS := start install init deploy -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -run: start install init deploy - -test-ci: - make start install init deploy; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-ws-http-proxy/README.md b/apigatewayv2-ws-http-proxy/README.md index dfb9664..9e5a89b 100644 --- a/apigatewayv2-ws-http-proxy/README.md +++ b/apigatewayv2-ws-http-proxy/README.md @@ -9,8 +9,7 @@ This template creates a WebSocket API that forwards the request body to an HTTP - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This template creates a WebSocket API that forwards the request body to an HTTP ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigatewayv2-ws-http/Makefile b/apigatewayv2-ws-http/Makefile index 21030a4..fa3fda8 100644 --- a/apigatewayv2-ws-http/Makefile +++ b/apigatewayv2-ws-http/Makefile @@ -1,45 +1,3 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) +DEPLOY_STEPS := start install init deploy -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -run: start install init deploy - -test-ci: - make start install init deploy; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-ws-http/README.md b/apigatewayv2-ws-http/README.md index 82c2ef4..9104f13 100644 --- a/apigatewayv2-ws-http/README.md +++ b/apigatewayv2-ws-http/README.md @@ -9,8 +9,7 @@ This template creates a WebSocket API that forwards the request body to an HTTP - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This template creates a WebSocket API that forwards the request body to an HTTP ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigatewayv2-ws-http/run.sh b/apigatewayv2-ws-http/run.sh index 3f88ea5..1d6bedd 100755 --- a/apigatewayv2-ws-http/run.sh +++ b/apigatewayv2-ws-http/run.sh @@ -1,5 +1,5 @@ #!/usr/bin/env sh -tflocal init; tflocal apply -auto-approve +lstk tf init; lstk tf apply -auto-approve wscat -c localhost:4510 diff --git a/apigatewayv2-ws-kinesis-integration/Makefile b/apigatewayv2-ws-kinesis-integration/Makefile index 21030a4..fa3fda8 100644 --- a/apigatewayv2-ws-kinesis-integration/Makefile +++ b/apigatewayv2-ws-kinesis-integration/Makefile @@ -1,45 +1,3 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -SHELL := /bin/bash -PYTHON_BIN ?= $(shell which python3 || which python) +DEPLOY_STEPS := start install init deploy -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -start: - @test -n "${LOCALSTACK_AUTH_TOKEN}" || (echo "LOCALSTACK_AUTH_TOKEN is not set" && exit 1); - DEBUG=1 LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d - -stop: - localstack stop - -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -install: ## Install dependencies - @which localstack || pip install localstack - @which awslocal || pip install awscli-local - @which terraform || (echo 'Terraform was not found';) - @which tflocal || pip install terraform-local - -init: - tflocal init - -deploy: - tflocal apply --auto-approve - -run: start install init deploy - -test-ci: - make start install init deploy; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -clean: - rm -rf .terraform - -.PHONY: start ready install init deploy test logs run test-ci clean +include ../common.mk diff --git a/apigatewayv2-ws-kinesis-integration/README.md b/apigatewayv2-ws-kinesis-integration/README.md index f8bcbef..ca2d0ab 100644 --- a/apigatewayv2-ws-kinesis-integration/README.md +++ b/apigatewayv2-ws-kinesis-integration/README.md @@ -9,8 +9,7 @@ This template creates a WebSocket API that forwards the request body to a Kinesi - A valid [LocalStack for AWS license](https://localstack.cloud/pricing). Your license provides a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/). - [Docker](https://docs.docker.com/get-docker/) -- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) -- [`awslocal` CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) +- [`lstk` CLI](https://docs.localstack.cloud/aws/tooling/lstk/) - [Terraform](https://developer.hashicorp.com/terraform/downloads) - `make` and `jq` @@ -19,7 +18,6 @@ This template creates a WebSocket API that forwards the request body to a Kinesi ```bash export LOCALSTACK_AUTH_TOKEN= make start -make ready ``` ### Run diff --git a/apigatewayv2-ws-kinesis-integration/main.tf b/apigatewayv2-ws-kinesis-integration/main.tf index d0ce8c0..053cfc8 100644 --- a/apigatewayv2-ws-kinesis-integration/main.tf +++ b/apigatewayv2-ws-kinesis-integration/main.tf @@ -56,7 +56,7 @@ resource "aws_apigatewayv2_integration" "integration" { api_id = aws_apigatewayv2_api.websocket.id integration_type = "AWS" integration_method = "POST" - integration_uri = "arn:aws:apigateway:${data.aws_region.current.name}:kinesis:action/PutRecord" + integration_uri = "arn:aws:apigateway:${data.aws_region.current.region}:kinesis:action/PutRecord" credentials_arn = aws_iam_role.execution_role.arn request_templates = { "default" = <