Skip to content

Commit 716d970

Browse files
whummerclaude
andcommitted
Add Lambda debug mode, hot reload, bucket rename, and VS Code config
- Rename S3 website bucket from orders-ui to app (simpler entrypoint URL) - Add .localstack/lambda_debug_mode.yaml for order-handler debug on port 19891 - Add debug-start Makefile target (LAMBDA_DEBUG_MODE_CONFIG_PATH + port mapping) - Add hot-reload / hot-reload-off Makefile targets (s3://hot-reload bucket) - Update .vscode/launch.json to debugpy remote attach config (port 19891, /var/task) - Add .vscode/extensions.json with recommended extensions - Add ms-python.python to devcontainer extensions - Move LAMBDA_DOCKER_FLAGS, LOCALSTACK_APPINSPECTOR_* into devcontainer remoteEnv Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1c3a3cc commit 716d970

8 files changed

Lines changed: 54 additions & 28 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"extensions": [
1111
"amazonwebservices.aws-toolkit-vscode",
1212
"localstack.localstack",
13-
"hashicorp.terraform"
13+
"hashicorp.terraform",
14+
"ms-python.python"
1415
]
1516
},
1617
"codespaces": {
@@ -19,5 +20,10 @@
1920
]
2021
}
2122
},
23+
"remoteEnv": {
24+
"LAMBDA_DOCKER_FLAGS": "-p 19891:19891",
25+
"LOCALSTACK_APPINSPECTOR_ENABLE": "1",
26+
"LOCALSTACK_APPINSPECTOR_DEV_ENABLE": "1"
27+
},
2228
"postStartCommand": "bash ./00-setup/setup.sh"
2329
}

.localstack/lambda_debug_mode.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
functions:
2+
order-handler:
3+
debug-port: 19891
4+
enforce-timeouts: false

.vscode/extensions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"recommendations": [
3+
"amazonwebservices.aws-toolkit-vscode",
4+
"localstack.localstack",
5+
"hashicorp.terraform",
6+
"ms-python.python"
7+
]
8+
}

.vscode/launch.json

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,19 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Debug order-handler (LocalStack)",
6-
"type": "aws-sam",
7-
"request": "direct-invoke",
8-
"invokeTarget": {
9-
"target": "code",
10-
"lambdaHandler": "handler.handler",
11-
"projectRoot": "${workspaceFolder}/01-serverless-app/lambdas/order_handler"
5+
"name": "Attach to order-handler (LocalStack debug mode)",
6+
"type": "debugpy",
7+
"request": "attach",
8+
"connect": {
9+
"host": "localhost",
10+
"port": 19891
1211
},
13-
"lambda": {
14-
"runtime": "python3.12",
15-
"payload": {
16-
"json": {
17-
"body": "{\"item\": \"debug-test\", \"quantity\": 1}"
18-
}
19-
},
20-
"environmentVariables": {
21-
"ORDERS_TABLE": "orders",
22-
"ORDERS_QUEUE_URL": "http://localhost:4566/000000000000/orders-queue",
23-
"AWS_ENDPOINT_URL": "http://localhost:4566"
12+
"pathMappings": [
13+
{
14+
"localRoot": "${workspaceFolder}/01-serverless-app/lambdas/order_handler",
15+
"remoteRoot": "/var/task"
2416
}
25-
},
26-
"sam": {
27-
"localArguments": ["--debug-port", "5890"]
28-
}
17+
]
2918
}
3019
]
3120
}

01-serverless-app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ awslocal s3 ls s3://order-receipts/
9393

9494
```bash
9595
echo "Website: $(tflocal output -raw website_url)"
96-
# Open http://localhost:4566/orders-ui/index.html in your browser
96+
# Open http://localhost:4566/app/index.html in your browser
9797
```
9898

9999
---

01-serverless-app/terraform/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ locals {
591591
}
592592

593593
resource "aws_s3_bucket" "website" {
594-
bucket = "orders-ui"
594+
bucket = "app"
595595
}
596596

597597
resource "aws_s3_bucket_public_access_block" "website" {
@@ -634,5 +634,5 @@ output "api_endpoint" {
634634
}
635635

636636
output "website_url" {
637-
value = "http://localhost:4566/orders-ui/index.html"
637+
value = "http://localhost:4566/app/index.html"
638638
}

Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@ help: ## Show this help
1010
# ── LocalStack ────────────────────────────────────────────────────────────────
1111

1212
start: ## Start LocalStack in the background
13-
LOCALSTACK_APPINSPECTOR_ENABLE=1 LOCALSTACK_APPINSPECTOR_DEV_ENABLE=1 localstack start -d
13+
LOCALSTACK_APPINSPECTOR_ENABLE=1 LOCALSTACK_APPINSPECTOR_DEV_ENABLE=1 \
14+
LAMBDA_DOCKER_FLAGS='-p 19891:19891' localstack start -d
15+
16+
debug-start: ## Start LocalStack with Lambda debug mode enabled (port 19891)
17+
LOCALSTACK_APPINSPECTOR_ENABLE=1 LOCALSTACK_APPINSPECTOR_DEV_ENABLE=1 \
18+
LAMBDA_DOCKER_FLAGS='-p 19891:19891' \
19+
LAMBDA_DEBUG_MODE_CONFIG_PATH=$(PWD)/.localstack/lambda_debug_mode.yaml localstack start -d
20+
21+
hot-reload: ## Switch order-handler to hot-reload mode (edits take effect immediately)
22+
awslocal lambda update-function-code \
23+
--function-name order-handler \
24+
--s3-bucket hot-reload \
25+
--s3-key $(PWD)/01-serverless-app/lambdas/order_handler
26+
27+
hot-reload-off: ## Restore order-handler to the packaged ZIP (disable hot reload)
28+
cd $(TERRAFORM_DIR) && tflocal apply -auto-approve -target=aws_lambda_function.order_handler
1429

1530
stop: ## Stop LocalStack
1631
localstack stop
@@ -111,6 +126,7 @@ iam-status: ## Show current IAM enforcement state and Lambda role policies
111126
publish-token: ## Upload LOCALSTACK_AUTH_TOKEN to S3 for workshop participants
112127
bash scripts/publish-workshop-token.sh
113128

114-
.PHONY: help start stop status logs setup init build deploy destroy redeploy outputs \
129+
.PHONY: help start stop status logs setup debug-start hot-reload hot-reload-off \
130+
init build deploy destroy redeploy outputs \
115131
test test-fast open-ui api-endpoint inject-fault remove-fault replay-dlq \
116132
iam-enforce iam-off iam-fix iam-status publish-token

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,8 @@ make replay-dlq # Replay messages from the DLQ
120120
make iam-enforce # Enable IAM policy enforcement
121121
make iam-fix # Grant missing dynamodb:PutItem to the Lambda role
122122
make iam-off # Disable IAM enforcement (permissive mode)
123+
make debug-start # Start LocalStack with Lambda debug mode (port 19891)
124+
make hot-reload # Switch order-handler to hot-reload mode
125+
make hot-reload-off # Restore order-handler to packaged ZIP
123126
make logs # Tail LocalStack logs
124127
```

0 commit comments

Comments
 (0)