|
1 | | -export AWS_ACCESS_KEY_ID ?= test |
| 1 | +SHELL := /bin/bash |
| 2 | + |
| 3 | +-include .env-gdc-local |
| 4 | + |
| 5 | +CDIR = cd cdk |
| 6 | + |
| 7 | +export AWS_ACCESS_KEY_ID ?= test |
2 | 8 | export AWS_SECRET_ACCESS_KEY ?= test |
3 | | -export AWS_DEFAULT_REGION = us-east-1 |
4 | | - |
5 | | -usage: ## Show this help |
6 | | - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' |
7 | | - |
8 | | -install: ## Install dependencies |
9 | | - npm install |
10 | | - which serverless || npm install -g serverless |
11 | | - which localstack || pip install localstack |
12 | | - |
13 | | -deploy: ## Deploy the app |
14 | | - @make install; \ |
15 | | - echo "Deploying Serverless app to local environment"; \ |
16 | | - SLS_DEBUG=1 serverless deploy --stage local |
17 | | - |
18 | | -send-request: ## Send a test request to the deployed application |
19 | | - @which jq || (echo "jq was not found. Please install it (https://jqlang.github.io/jq/download/) and try again." && exit 1) |
20 | | - @echo Looking up API ID from deployed API Gateway REST APIs ...; \ |
21 | | - apiId=$$(awslocal apigateway get-rest-apis --output json | jq -r '.items[] | select(.name="local-localstack-demo") | .id'); \ |
22 | | - echo Sending request to API Gateway REST APIs ID "$$apiId" ...; \ |
23 | | - requestID=$$(curl -s -d '{}' http://$$apiId.execute-api.localhost.localstack.cloud:4566/local/requests | jq -r .requestID); \ |
24 | | - echo "Received request ID '$$requestID'"; \ |
25 | | - for i in 1 2 3 4 5 6 7 8 9 10; do echo "Polling for processing result to appear in s3://archive-bucket/..."; awslocal s3 ls s3://archive-bucket/ | grep $$requestID && exit; sleep 3; done |
26 | | - |
27 | | -lint: ## Run code linter |
28 | | - @npm run lint |
29 | | - @flake8 demo |
30 | | - |
31 | | -.PHONY: usage install deploy send-request lint |
| 9 | +export AWS_DEFAULT_REGION ?= us-east-1 |
| 10 | +export AWS_ENDPOINT_URL ?= http://localhost.localstack.cloud:4566 |
| 11 | + |
| 12 | +usage: ## Show this help in table format |
| 13 | + @echo "| Target | Description |" |
| 14 | + @echo "|------------------------|-------------------------------------------------------------------|" |
| 15 | + @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/:.*##\s*/##/g' | awk -F'##' '{ printf "| %-22s | %-65s |\n", $$1, $$2 }' |
| 16 | + |
| 17 | +check: ## Check if all required prerequisites are installed |
| 18 | + @command -v docker > /dev/null 2>&1 || { echo "Docker is not installed. Please install Docker and try again."; exit 1; } |
| 19 | + @command -v node > /dev/null 2>&1 || { echo "Node.js is not installed. Please install Node.js and try again."; exit 1; } |
| 20 | + @command -v aws > /dev/null 2>&1 || { echo "AWS CLI is not installed. Please install AWS CLI and try again."; exit 1; } |
| 21 | + @command -v awslocal > /dev/null 2>&1 || { echo "awslocal is not installed. Run: pip install awscli-local"; exit 1; } |
| 22 | + @command -v localstack > /dev/null 2>&1 || { echo "LocalStack CLI is not installed. Run: pip install localstack"; exit 1; } |
| 23 | + @command -v jq > /dev/null 2>&1 || { echo "jq is not installed. See https://jqlang.github.io/jq/download/"; exit 1; } |
| 24 | + @test -n "$(LOCALSTACK_AUTH_TOKEN)" || { echo "LOCALSTACK_AUTH_TOKEN is not set. Find your token at https://app.localstack.cloud/workspace/auth-token"; exit 1; } |
| 25 | + @echo "All required prerequisites are available." |
| 26 | + |
| 27 | +install: ## Install CDK and Lambda dependencies |
| 28 | + @$(CDIR); if [ ! -d "node_modules" ]; then \ |
| 29 | + echo "Installing CDK dependencies..."; \ |
| 30 | + npm install; \ |
| 31 | + else \ |
| 32 | + echo "CDK dependencies already installed."; \ |
| 33 | + fi |
| 34 | + |
| 35 | +bundle-ruby: ## Bundle Ruby 3.3 Lambda gems (requires Docker) |
| 36 | + docker run --rm \ |
| 37 | + -v "$(shell pwd)/demo/lambdas/ruby:/var/task" \ |
| 38 | + -w /var/task \ |
| 39 | + ruby:3.3 \ |
| 40 | + sh -c "bundle config set --local path vendor/bundle && bundle install" |
| 41 | + |
| 42 | +bundle-node: ## Install Node.js Lambda production dependencies |
| 43 | + cd demo/lambdas/nodejs && npm install --omit=dev |
| 44 | + |
| 45 | +build: ## Build the CDK TypeScript app |
| 46 | + $(CDIR) && npm run build |
| 47 | + |
| 48 | +bootstrap: ## Bootstrap CDK for LocalStack |
| 49 | + $(CDIR) && npm run build && npx cdklocal bootstrap |
| 50 | + |
| 51 | +deploy: ## Build, deploy CDK stack to LocalStack, and upload frontend |
| 52 | + $(MAKE) bundle-ruby bundle-node |
| 53 | + $(MAKE) bootstrap |
| 54 | + $(CDIR) && npx cdklocal deploy LocalstackDemoStack --require-approval never |
| 55 | + @echo "Uploading frontend to s3://archive-bucket/ ..." |
| 56 | + awslocal s3 sync demo/web/ s3://archive-bucket/ |
| 57 | + @echo "" |
| 58 | + @echo "Done! Open http://localhost:4566/archive-bucket/index.html in your browser." |
| 59 | + |
| 60 | +destroy: ## Destroy the deployed CDK stack on LocalStack |
| 61 | + $(CDIR) && npx cdklocal destroy LocalstackDemoStack |
| 62 | + |
| 63 | +send-request: ## Send a test request and poll S3 for the result |
| 64 | + @command -v jq > /dev/null 2>&1 || { echo "jq is not installed. See https://jqlang.github.io/jq/download/"; exit 1; } |
| 65 | + @echo "Looking up REST API ID..." |
| 66 | + @apiId=$$(awslocal apigateway get-rest-apis --output json | jq -r '.items[] | select(.name=="localstack-demo") | .id'); \ |
| 67 | + echo "Sending request to API ID '$$apiId' ..."; \ |
| 68 | + reqID=$$(curl -s -d '{}' "http://localhost:4566/_aws/execute-api/$$apiId/local/requests" | jq -r .requestID); \ |
| 69 | + echo "Received request ID '$$reqID'"; \ |
| 70 | + for i in 1 2 3 4 5 6 7 8 9 10; do \ |
| 71 | + echo "Polling s3://archive-bucket/ for result ..."; \ |
| 72 | + awslocal s3 ls s3://archive-bucket/ | grep "$$reqID" && exit 0; \ |
| 73 | + sleep 3; \ |
| 74 | + done; \ |
| 75 | + echo "Timed out waiting for result." |
| 76 | + |
| 77 | +start: ## Start LocalStack in detached mode |
| 78 | + @echo "Starting LocalStack..." |
| 79 | + @test -n "$(LOCALSTACK_AUTH_TOKEN)" || { echo "LOCALSTACK_AUTH_TOKEN is not set. Find your token at https://app.localstack.cloud/workspace/auth-token"; exit 1; } |
| 80 | + @LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) localstack start -d |
| 81 | + @echo "LocalStack started successfully." |
| 82 | + |
| 83 | +stop: ## Stop LocalStack |
| 84 | + @echo "Stopping LocalStack..." |
| 85 | + @localstack stop |
| 86 | + @echo "LocalStack stopped successfully." |
| 87 | + |
| 88 | +ready: ## Wait until the LocalStack container is ready |
| 89 | + @echo "Waiting on the LocalStack container..." |
| 90 | + @localstack wait -t 30 && echo "LocalStack is ready to use!" || { echo "Gave up waiting on LocalStack, exiting."; exit 1; } |
| 91 | + |
| 92 | +logs: ## Save LocalStack logs to logs.txt |
| 93 | + @localstack logs > logs.txt |
| 94 | + |
| 95 | +PKG_SUB_DIRS := $(dir $(shell find . -type d -name node_modules -prune -o -type d -name "vendor" -prune -o -type f -name package.json -print)) |
| 96 | + |
| 97 | +update-deps: ## Update npm dependencies in all sub-projects |
| 98 | + for i in $(PKG_SUB_DIRS); do \ |
| 99 | + pushd $$i && ncu -u && npm install && popd; \ |
| 100 | + done |
| 101 | + |
| 102 | +.PHONY: usage check install bundle-ruby bundle-node build bootstrap deploy deploy-aws \ |
| 103 | + destroy destroy-aws send-request start stop ready logs update-deps |
0 commit comments