From 16509a6a12f825b0ba66e7a3f540783413374be9 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 20 May 2025 00:06:12 +0500 Subject: [PATCH 01/11] Update makefile targets and update dockerfile --- tasks.py | 1 + {{copier__project_name}}/Makefile | 39 +++++++++++++------ ...type == \"image\" %}Dockerfile{% endif %}" | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/tasks.py b/tasks.py index 9025a0b..5697e09 100644 --- a/tasks.py +++ b/tasks.py @@ -56,6 +56,7 @@ def log_next_steps(): + "\n3. Run 'make setup' to run dynamodb locally and create the database" + "\n4. Then run 'make build' to build the lambda function" + "\n5. Then run 'make deploy' to deploy the lambda function" + + "\n6. To remove the local setup, run 'make down'" + "\nRefer to README.md for more details." + TERMINATOR ) diff --git a/{{copier__project_name}}/Makefile b/{{copier__project_name}}/Makefile index 4e5a403..740e3f0 100644 --- a/{{copier__project_name}}/Makefile +++ b/{{copier__project_name}}/Makefile @@ -8,6 +8,8 @@ BUILD_DIR ?= .aws-sam/build {% if copier__dynamo_db %} DYNAMO_ENDPOINT ?= http://localhost:8000 TABLE_NAME ?= RequestsTable-{{copier__stack_name}} +CONTAINER_NAME ?= {{copier__stack_name}}-dynamodb-local +NETWORK_NAME ?= {{copier__stack_name}}-network {% endif %} # Default target @@ -29,26 +31,25 @@ deploy-sandbox: {% if copier__package_type != "image" %}--resolve-image-repos{% endif %} local: - sam local start-api {% if copier__dynamo_db %}--env-vars env_example.json --docker-network lambda-local{% endif %} + sam local start-api {% if copier__dynamo_db %}--env-vars env_example.json --docker-network $(NETWORK_NAME){% endif %} invoke: - sam local invoke HelloWorldFunction --event events/event.json{% if copier__dynamo_db %} --env-vars env_example.json --docker-network lambda-local{% endif %} + sam local invoke HelloWorldFunction --event events/event.json{% if copier__dynamo_db %} --env-vars env_example.json --docker-network $(NETWORK_NAME){% endif %} {% if copier__dynamo_db %} dynamo-up: - @if [ -z "$$(docker network ls --filter name=^lambda-local$$ -q)" ]; then \ - echo "Creating Docker network 'lambda-local'..."; \ - docker network create lambda-local; \ + @if [ -z "$$(docker network ls --filter name=^$(NETWORK_NAME)$$ -q)" ]; then \ + echo "Creating Docker network '$(NETWORK_NAME)'..."; \ + docker network create $(NETWORK_NAME); \ else \ - echo "Docker network 'lambda-local' already exists."; \ + echo "Docker network '$(NETWORK_NAME)' already exists."; \ fi; \ - if [ -f .dynamodb-container-id ] && [ -n "$$(docker ps -q -f id=$$(cat .dynamodb-container-id 2>/dev/null))" ]; then \ - echo "DynamoDB local container is already running with ID: $$(cat .dynamodb-container-id)"; \ + if [ -n "$$(docker ps -q -f name=^/$(CONTAINER_NAME)$$)" ]; then \ + echo "DynamoDB local container '$(CONTAINER_NAME)' is already running."; \ else \ echo "Starting DynamoDB local container..."; \ - rm -f .dynamodb-container-id 2>/dev/null || true; \ - docker run -d --rm --network lambda-local -p 8000:8000 --name {{copier__stack_name}}-dynamodb-local amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb > .dynamodb-container-id; \ - echo "DynamoDB local container started with ID: $$(cat .dynamodb-container-id)"; \ + docker run -d --rm --network $(NETWORK_NAME) -p 8000:8000 --name $(CONTAINER_NAME) amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb; \ + echo "DynamoDB local container '$(CONTAINER_NAME)' started."; \ fi wait-for-dynamodb: @@ -93,6 +94,22 @@ setup: test: AWS_SAM_STACK_NAME=$(STACK_NAME) PYTHONPATH=. uv run --with pytest,boto3,requests,pytest-mock pytest -v --disable-warnings --tb=short tests +down: + @if [ -n "$$(docker ps -q -f name=^/$(CONTAINER_NAME)$$)" ]; then \ + echo "Stopping DynamoDB local container..."; \ + docker stop $(CONTAINER_NAME); \ + echo "DynamoDB local container '$(CONTAINER_NAME)' stopped."; \ + else \ + echo "DynamoDB local container '$(CONTAINER_NAME)' is not running."; \ + fi; \ + if [ -n "$$(docker network ls --filter name=^$(NETWORK_NAME)$$ -q)" ]; then \ + echo "Removing Docker network '$(NETWORK_NAME)'..."; \ + docker network rm $(NETWORK_NAME); \ + echo "Docker network '$(NETWORK_NAME)' removed."; \ + else \ + echo "Docker network '$(NETWORK_NAME)' does not exist."; \ + fi + delete-sandbox: sam delete --stack-name $(STACK_NAME)-sandbox diff --git "a/{{copier__project_name}}/src/{% if copier__package_type == \"image\" %}Dockerfile{% endif %}" "b/{{copier__project_name}}/src/{% if copier__package_type == \"image\" %}Dockerfile{% endif %}" index bdc8951..f638675 100644 --- "a/{{copier__project_name}}/src/{% if copier__package_type == \"image\" %}Dockerfile{% endif %}" +++ "b/{{copier__project_name}}/src/{% if copier__package_type == \"image\" %}Dockerfile{% endif %}" @@ -1,4 +1,4 @@ -FROM public.ecr.aws/lambda/python:{{copier__runtime}}-{{copier__architectures}} +FROM public.ecr.aws/lambda/python:{{copier__runtime}}-slim COPY app.py ${LAMBDA_TASK_ROOT} # Command can be overwritten by providing a different command in the template directly. From d939cfa47b88fbe13c2440e3fe889297b270c305 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 20 May 2025 00:09:51 +0500 Subject: [PATCH 02/11] Update docs --- {{copier__project_name}}/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/{{copier__project_name}}/README.md b/{{copier__project_name}}/README.md index 3ff6130..d6bfe99 100644 --- a/{{copier__project_name}}/README.md +++ b/{{copier__project_name}}/README.md @@ -110,6 +110,12 @@ make test ## Cleanup +To delete the local setup (i.e container and local network) run the following command: + +```bash +make down +``` + To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following: ```bash From 3e140fb78828bb2eddb770ca486be890be7e9c82 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 20 May 2025 18:41:53 +0500 Subject: [PATCH 03/11] Update dockerfile base image --- ...f copier__package_type == \"image\" %}Dockerfile{% endif %}" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/{{copier__project_name}}/src/{% if copier__package_type == \"image\" %}Dockerfile{% endif %}" "b/{{copier__project_name}}/src/{% if copier__package_type == \"image\" %}Dockerfile{% endif %}" index f638675..bdc8951 100644 --- "a/{{copier__project_name}}/src/{% if copier__package_type == \"image\" %}Dockerfile{% endif %}" +++ "b/{{copier__project_name}}/src/{% if copier__package_type == \"image\" %}Dockerfile{% endif %}" @@ -1,4 +1,4 @@ -FROM public.ecr.aws/lambda/python:{{copier__runtime}}-slim +FROM public.ecr.aws/lambda/python:{{copier__runtime}}-{{copier__architectures}} COPY app.py ${LAMBDA_TASK_ROOT} # Command can be overwritten by providing a different command in the template directly. From edbee07499a73310fcbb78adb65c9acac0c8ca30 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 20 May 2025 20:23:10 +0500 Subject: [PATCH 04/11] Add validation for existing docker container runnning --- {{copier__project_name}}/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/{{copier__project_name}}/Makefile b/{{copier__project_name}}/Makefile index 740e3f0..dde5693 100644 --- a/{{copier__project_name}}/Makefile +++ b/{{copier__project_name}}/Makefile @@ -1,4 +1,4 @@ -.PHONY: build deploy local clean test setup{% if copier__dynamo_db %} dynamo-up dynamo-down create-table{% endif %} +.PHONY: build deploy local clean test setup{% if copier__dynamo_db %} dynamo-up dynamo-down wait-for-dynamodb create-table{% endif %} # Configuration STACK_NAME ?= {{ copier__stack_name }} @@ -47,6 +47,10 @@ dynamo-up: if [ -n "$$(docker ps -q -f name=^/$(CONTAINER_NAME)$$)" ]; then \ echo "DynamoDB local container '$(CONTAINER_NAME)' is already running."; \ else \ + if docker ps --format '{{.Ports}}' | grep ':8000->'; then \ + echo "Error: Port 8000 is already in use by another container. Cannot start DynamoDB local container."; \ + exit 1; \ + fi; \ echo "Starting DynamoDB local container..."; \ docker run -d --rm --network $(NETWORK_NAME) -p 8000:8000 --name $(CONTAINER_NAME) amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb; \ echo "DynamoDB local container '$(CONTAINER_NAME)' started."; \ From bc14c41b928482aeda623135778365314c7aaa22 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 20 May 2025 20:35:38 +0500 Subject: [PATCH 05/11] Remove extra step from Next Steps --- tasks.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tasks.py b/tasks.py index 5697e09..32885f4 100644 --- a/tasks.py +++ b/tasks.py @@ -52,11 +52,10 @@ def log_next_steps(): HINT + "Next steps:" + "\n1. Run 'cd {{ copier__project_name }}' to enter the project directory" - + "\n2. Update the .envrc file with your AWS credentials" - + "\n3. Run 'make setup' to run dynamodb locally and create the database" - + "\n4. Then run 'make build' to build the lambda function" - + "\n5. Then run 'make deploy' to deploy the lambda function" - + "\n6. To remove the local setup, run 'make down'" + + "\n2. Run 'make setup' to run dynamodb locally and create the database" + + "\n3. Then run 'make build' to build the lambda function" + + "\n4. Then run 'make deploy' to deploy the lambda function" + + "\n5. To remove the local setup, run 'make down'" + "\nRefer to README.md for more details." + TERMINATOR ) From 501df319739b20e885d79db064390bbed0c98733 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 20 May 2025 21:18:00 +0500 Subject: [PATCH 06/11] Escape copier branckets --- {{copier__project_name}}/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{copier__project_name}}/Makefile b/{{copier__project_name}}/Makefile index dde5693..1ae1472 100644 --- a/{{copier__project_name}}/Makefile +++ b/{{copier__project_name}}/Makefile @@ -47,7 +47,7 @@ dynamo-up: if [ -n "$$(docker ps -q -f name=^/$(CONTAINER_NAME)$$)" ]; then \ echo "DynamoDB local container '$(CONTAINER_NAME)' is already running."; \ else \ - if docker ps --format '{{.Ports}}' | grep ':8000->'; then \ + if docker ps --format "{% raw %}{{.Ports}}{% endraw %}" | grep ':8000->'; then \ echo "Error: Port 8000 is already in use by another container. Cannot start DynamoDB local container."; \ exit 1; \ fi; \ From 430e0070f9156c61d2fe88f5382bb704cf151cf4 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 20 May 2025 22:50:29 +0500 Subject: [PATCH 07/11] Update build command and fix requirements path --- copier.yml | 4 ++-- {{copier__project_name}}/Makefile | 4 ++-- {{copier__project_name}}/template.yaml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/copier.yml b/copier.yml index 9369caa..fa53e42 100644 --- a/copier.yml +++ b/copier.yml @@ -73,8 +73,8 @@ copier__auth: copier__dynamo_db: type: bool - help: "Do you want to enable DynamoDB for your project? (y/n) [default: No]" - default: false + help: "Do you want to enable DynamoDB for your project? (y/n) [default: Yes]" + default: true copier__aws_region: type: str diff --git a/{{copier__project_name}}/Makefile b/{{copier__project_name}}/Makefile index 1ae1472..189a74f 100644 --- a/{{copier__project_name}}/Makefile +++ b/{{copier__project_name}}/Makefile @@ -16,7 +16,7 @@ NETWORK_NAME ?= {{copier__stack_name}}-network all: build build: - sam build {% if copier__package_type != "image" %}--use-container{% endif %} > /dev/null 2>&1 + sam build > /dev/null 2>&1 validate: sam validate --lint @@ -93,7 +93,7 @@ create-table: setup: dynamo-up wait-for-dynamodb create-table{% else %} setup: - pip install -r requirements.txt{% endif %} + pip install -r src/requirements.txt{% endif %} test: AWS_SAM_STACK_NAME=$(STACK_NAME) PYTHONPATH=. uv run --with pytest,boto3,requests,pytest-mock pytest -v --disable-warnings --tb=short tests diff --git a/{{copier__project_name}}/template.yaml b/{{copier__project_name}}/template.yaml index d2f4960..d9d0b4a 100644 --- a/{{copier__project_name}}/template.yaml +++ b/{{copier__project_name}}/template.yaml @@ -60,7 +60,7 @@ Resources: Runtime: python{{ copier__runtime }} {% endif %} Architectures: - - {{copier__architectures}} + - "{{copier__architectures}}" {% if copier__dynamo_db %} Environment: Variables: From f4189fcb7bf9c2b922318bb0674b2ffb2cf7a388 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 20 May 2025 23:19:46 +0500 Subject: [PATCH 08/11] Remove .envrc file --- {{copier__project_name}}/.envrc | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 {{copier__project_name}}/.envrc diff --git a/{{copier__project_name}}/.envrc b/{{copier__project_name}}/.envrc deleted file mode 100644 index 5b607f6..0000000 --- a/{{copier__project_name}}/.envrc +++ /dev/null @@ -1,3 +0,0 @@ -export AWS_ACCESS_KEY_ID=dummyAccessKeyId -export AWS_SECRET_ACCESS_KEY=dummySecretAccessKey -export AWS_REGION={{copier__aws_region}} From 310b1872c410aa4f6173bb475f21e19705b289d9 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Mon, 2 Jun 2025 20:26:15 +0500 Subject: [PATCH 09/11] Update makefile targets to use network-name for docker containers --- tasks.py | 5 +- {{copier__project_name}}/Makefile | 116 ++++++++++++++++++------------ 2 files changed, 75 insertions(+), 46 deletions(-) diff --git a/tasks.py b/tasks.py index 32885f4..f4929aa 100644 --- a/tasks.py +++ b/tasks.py @@ -54,8 +54,9 @@ def log_next_steps(): + "\n1. Run 'cd {{ copier__project_name }}' to enter the project directory" + "\n2. Run 'make setup' to run dynamodb locally and create the database" + "\n3. Then run 'make build' to build the lambda function" - + "\n4. Then run 'make deploy' to deploy the lambda function" - + "\n5. To remove the local setup, run 'make down'" + + "\n4. To run lambda function locally, run 'make local' to invoke the lambda function" + + "\n5. To deploy, run 'make deploy' to deploy the lambda function" + + "\n6. To remove the local setup, run 'make down'" + "\nRefer to README.md for more details." + TERMINATOR ) diff --git a/{{copier__project_name}}/Makefile b/{{copier__project_name}}/Makefile index 189a74f..32c621e 100644 --- a/{{copier__project_name}}/Makefile +++ b/{{copier__project_name}}/Makefile @@ -12,32 +12,31 @@ CONTAINER_NAME ?= {{copier__stack_name}}-dynamodb-local NETWORK_NAME ?= {{copier__stack_name}}-network {% endif %} -# Default target -all: build +## Build & Deploy -build: - sam build > /dev/null 2>&1 +build: ## Build the AWS SAM project + @sam build > /dev/null 2>build_error.log && echo "Build succeeded!" || (cat build_error.log && exit 1) + @rm -f build_error.log -validate: +validate: ## Validate the SAM template with linting sam validate --lint -deploy: - sam deploy --guided --profile {{copier__aws_profile}} +deploy: ## Deploy the stack using interactive guided mode + sam deploy --guided --profile {{copier__aws_profile}} \ + {% if copier__package_type == "image" %}--resolve-image-repos{% endif %} -deploy-sandbox: - sam deploy --stack-name $(STACK_NAME)-sandbox \ - --capabilities CAPABILITY_IAM \ - --parameter-overrides StageName=sandbox \ - {% if copier__package_type != "image" %}--resolve-image-repos{% endif %} +## Local Development -local: +local: ## Start the local API using SAM sam local start-api {% if copier__dynamo_db %}--env-vars env_example.json --docker-network $(NETWORK_NAME){% endif %} -invoke: +invoke: ## Invoke a Lambda function locally using an event payload sam local invoke HelloWorldFunction --event events/event.json{% if copier__dynamo_db %} --env-vars env_example.json --docker-network $(NETWORK_NAME){% endif %} {% if copier__dynamo_db %} -dynamo-up: +## DynamoDB (Local) Setup + +dynamo-up: ## Start a local DynamoDB instance in a Docker container @if [ -z "$$(docker network ls --filter name=^$(NETWORK_NAME)$$ -q)" ]; then \ echo "Creating Docker network '$(NETWORK_NAME)'..."; \ docker network create $(NETWORK_NAME); \ @@ -47,19 +46,15 @@ dynamo-up: if [ -n "$$(docker ps -q -f name=^/$(CONTAINER_NAME)$$)" ]; then \ echo "DynamoDB local container '$(CONTAINER_NAME)' is already running."; \ else \ - if docker ps --format "{% raw %}{{.Ports}}{% endraw %}" | grep ':8000->'; then \ - echo "Error: Port 8000 is already in use by another container. Cannot start DynamoDB local container."; \ - exit 1; \ - fi; \ - echo "Starting DynamoDB local container..."; \ - docker run -d --rm --network $(NETWORK_NAME) -p 8000:8000 --name $(CONTAINER_NAME) amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb; \ + echo "Starting DynamoDB local container without exposing port 8000 on host..."; \ + docker run -d --rm --network $(NETWORK_NAME) --name $(CONTAINER_NAME) amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb; \ echo "DynamoDB local container '$(CONTAINER_NAME)' started."; \ fi -wait-for-dynamodb: - @echo "Waiting for DynamoDB Local to be ready..." +wait-for-dynamodb: ## Wait until DynamoDB Local is ready inside the container + @echo "Waiting for DynamoDB Local to be ready (inside container)..." @attempts=0; \ - until curl -s http://localhost:8000 >/dev/null; do \ + until docker exec $(CONTAINER_NAME) curl -s http://localhost:8000 >/dev/null 2>&1; do \ if [ $$attempts -ge 10 ]; then \ echo "DynamoDB Local did not become ready in time"; \ exit 1; \ @@ -70,9 +65,13 @@ wait-for-dynamodb: done; \ echo "DynamoDB Local is ready." -create-table: - @# Store the AWS command output in a variable - $(eval AWS_OUTPUT := $(shell aws dynamodb create-table \ +create-table: ## Create the DynamoDB table in the local container + @echo "Creating DynamoDB table '$(TABLE_NAME)' in container '$(CONTAINER_NAME)'..." + @docker run --rm --network $(NETWORK_NAME) \ + -e AWS_ACCESS_KEY_ID=dummy \ + -e AWS_SECRET_ACCESS_KEY=dummy \ + amazon/aws-cli \ + dynamodb create-table \ --table-name $(TABLE_NAME) \ --attribute-definitions \ AttributeName=ip_address,AttributeType=S \ @@ -81,24 +80,44 @@ create-table: AttributeName=ip_address,KeyType=HASH \ AttributeName=timestamp,KeyType=RANGE \ --billing-mode PAY_PER_REQUEST \ - --endpoint-url $(DYNAMO_ENDPOINT))) + --endpoint-url http://$(CONTAINER_NAME):8000 \ + --region $(REGION) + +list-records: ## List all records in the DynamoDB table + @echo "Listing records from DynamoDB table '$(TABLE_NAME)'..." + @docker run --rm --network $(NETWORK_NAME) \ + -e AWS_ACCESS_KEY_ID=dummy \ + -e AWS_SECRET_ACCESS_KEY=dummy \ + amazon/aws-cli \ + dynamodb scan \ + --table-name $(TABLE_NAME) \ + --endpoint-url http://$(CONTAINER_NAME):8000 \ + --region $(REGION) + +count-records: ## Count the number of records in the DynamoDB table + @echo "Counting records in DynamoDB table '$(TABLE_NAME)'..." + @docker run --rm --network $(NETWORK_NAME) \ + -e AWS_ACCESS_KEY_ID=dummy \ + -e AWS_SECRET_ACCESS_KEY=dummy \ + amazon/aws-cli \ + dynamodb scan \ + --table-name $(TABLE_NAME) \ + --select "COUNT" \ + --endpoint-url http://$(CONTAINER_NAME):8000 \ + --region $(REGION) - @# Check if jq exists and use it if available - @if command -v jq > /dev/null 2>&1; then \ - echo '$(AWS_OUTPUT)' | jq; \ - else \ - echo '$(AWS_OUTPUT)'; \ - echo "\033[33mNote: Install jq for colorized JSON output\033[0m"; \ - fi +setup: dynamo-up wait-for-dynamodb create-table ## Set up local DynamoDB environment{% else %} +setup: ## Install Python dependencies + pip3 install -r src/requirements.txt{% endif %} -setup: dynamo-up wait-for-dynamodb create-table{% else %} -setup: - pip install -r src/requirements.txt{% endif %} +## Testing -test: +test: ## Run Python unit tests using uv and pytest AWS_SAM_STACK_NAME=$(STACK_NAME) PYTHONPATH=. uv run --with pytest,boto3,requests,pytest-mock pytest -v --disable-warnings --tb=short tests -down: +## Cleanup + +down: ## Stop and remove local DynamoDB container and network @if [ -n "$$(docker ps -q -f name=^/$(CONTAINER_NAME)$$)" ]; then \ echo "Stopping DynamoDB local container..."; \ docker stop $(CONTAINER_NAME); \ @@ -114,8 +133,17 @@ down: echo "Docker network '$(NETWORK_NAME)' does not exist."; \ fi -delete-sandbox: - sam delete --stack-name $(STACK_NAME)-sandbox - -delete: +delete: ## Delete the deployed SAM stack sam delete --stack-name $(STACK_NAME) + +## Help + +help: ## Show the list of all the commands and their help text + @awk 'BEGIN { FS = ":.*##"; target="";printf "\nUsage:\n make \033[36m\033[33m\n\nTargets:\033[0m\n" } \ + /^[a-zA-Z_-]+:.*?##/ { if(target=="")print ""; target=$$1; printf " \033[36m%-10s\033[0m %s\n\n", $$1, $$2 } \ + /^([a-zA-Z_-]+):/ {if(target=="")print "";match($$0, "(.*):"); target=substr($$0,RSTART,RLENGTH) } \ + /^\t## (.*)/ { match($$0, "[^\t#:\\\\]+"); txt=substr($$0,RSTART,RLENGTH);printf " \033[36m%-10s\033[0m", target; printf " %s\n", txt ; target=""} \ + /^## .*/ {match($$0, "## (.+)$$"); txt=substr($$0,4,RLENGTH);printf "\n\033[33m%s\033[0m\n", txt ; target=""} \ + ' $(MAKEFILE_LIST) + +.DEFAULT_GOAL := help From 93f42cc0ce22b2c3224a0cffd068d6930a588a95 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Mon, 2 Jun 2025 21:09:46 +0500 Subject: [PATCH 10/11] Update Makefile target help text --- {{copier__project_name}}/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{copier__project_name}}/Makefile b/{{copier__project_name}}/Makefile index 32c621e..ec0dfb1 100644 --- a/{{copier__project_name}}/Makefile +++ b/{{copier__project_name}}/Makefile @@ -46,7 +46,7 @@ dynamo-up: ## Start a local DynamoDB instance in a Docker container if [ -n "$$(docker ps -q -f name=^/$(CONTAINER_NAME)$$)" ]; then \ echo "DynamoDB local container '$(CONTAINER_NAME)' is already running."; \ else \ - echo "Starting DynamoDB local container without exposing port 8000 on host..."; \ + echo "Starting DynamoDB local container..."; \ docker run -d --rm --network $(NETWORK_NAME) --name $(CONTAINER_NAME) amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb; \ echo "DynamoDB local container '$(CONTAINER_NAME)' started."; \ fi From ff71f71288646ae227589eb88bfe817e1beea4e4 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Date: Tue, 3 Jun 2025 16:25:48 +0500 Subject: [PATCH 11/11] Add AWS_profile variable in makefile --- tasks.py | 2 +- {{copier__project_name}}/Makefile | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index f4929aa..2e52bd7 100644 --- a/tasks.py +++ b/tasks.py @@ -20,7 +20,7 @@ def run_setup(): print("Error: AWS SAM CLI is not installed. Please install it and try again.") exit(1) - print("Running AWS SAM build and validate...") + print("Running AWS SAM validate and build...") subprocess.run(shlex.split("make validate")) subprocess.run(shlex.split("make build")) print("AWS Lambda template build and setup complete.") diff --git a/{{copier__project_name}}/Makefile b/{{copier__project_name}}/Makefile index ec0dfb1..3d4d068 100644 --- a/{{copier__project_name}}/Makefile +++ b/{{copier__project_name}}/Makefile @@ -5,6 +5,7 @@ STACK_NAME ?= {{ copier__stack_name }} REGION ?= {{copier__aws_region}} TEMPLATE_FILE ?= template.yaml BUILD_DIR ?= .aws-sam/build +AWS_PROFILE ?= {{copier__aws_profile}} {% if copier__dynamo_db %} DYNAMO_ENDPOINT ?= http://localhost:8000 TABLE_NAME ?= RequestsTable-{{copier__stack_name}} @@ -22,7 +23,7 @@ validate: ## Validate the SAM template with linting sam validate --lint deploy: ## Deploy the stack using interactive guided mode - sam deploy --guided --profile {{copier__aws_profile}} \ + sam deploy --guided --profile $(AWS_PROFILE) \ {% if copier__package_type == "image" %}--resolve-image-repos{% endif %} ## Local Development