Skip to content

Commit 2f9b04b

Browse files
authored
add(lambda_debugging/sam-typescript): Include npm build commands and fix launch.json (#3)
1 parent 8dea88c commit 2f9b04b

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

lambda-debugging-sam-typescript/.vscode/launch.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
"request": "attach",
88
"address": "127.0.0.1",
99
"port": 7050,
10-
"localRoot": "${workspaceFolder}/hello-world",
10+
// Change localRoot to ${workspaceFolder}/hello-world for AWS SAM
11+
"localRoot": "${workspaceFolder}/hello-world/dist",
1112
"remoteRoot": "/var/task/",
12-
"outFiles":[
13-
"TODO(fix-these)",
14-
".aws-sam/build/HelloWorldFunction/**",
15-
"${workspaceFolder}/**/*.(m|c|)js",
16-
"!**/node_modules/**"
17-
]
13+
"outFiles": [
14+
"${workspaceFolder}/.aws-sam/build/HelloWorldFunction/**",
15+
"${workspaceFolder}/hello-world/dist/app.js",
16+
"${workspaceFolder}/hello-world/dist/app.js.map"
17+
],
18+
"sourceMaps": true,
19+
"skipFiles": ["<node_internals>/**"]
1820
}
1921
]
2022
}

lambda-debugging-sam-typescript/Makefile

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ install: ## Install CLI dependencies
2929

3030
build: build-local ## Build the Lambda function (default local)
3131

32-
# TODO: FIX TypeScript deployment
33-
# TODO: package runtime dependencies from package.json/node_modules
34-
# TODO: run tests before build
35-
build-docker: ## Build the Lambda function zip in Docker
36-
docker run --platform $(DOCKER_PLATFORM) --rm -v "$$(pwd)/hello-world:/app" $(IMAGE) bash -c "cd /app && zip -r hello-world-javascript.zip ."
37-
38-
# TODO: FIX TypeScript deployment
39-
# TODO: package runtime dependencies from package.json/node_modules
40-
# TODO: run tests before build
32+
build-docker: ## Build the Lambda function zip in Docker
33+
docker run --rm --platform $(DOCKER_PLATFORM) \
34+
-v "$$(pwd)/hello-world:/app" $(IMAGE) \
35+
bash -c "cd /app && npm ci && npm test && npm run build"
36+
4137
build-local: ## Build the Lambda function zip locally (Node.js requires)
42-
cd hello-world && zip -r hello-world-javascript.zip .
38+
cd hello-world && \
39+
npm ci && \
40+
npm test && \
41+
npm run build
4342

4443
build-sam: ## Build the Lambda function via AWS SAM
4544
$(SAM) build --use-container
@@ -49,14 +48,13 @@ wait: ## Wait until the Lambda function becomes ready to invoke
4948

5049
deploy: deploy-aws ## Deploy the Lambda function (default AWS CLI)
5150

52-
# TODO: FIX TypeScript deployment
5351
deploy-aws: ## Deploy the Lambda function via AWS CLI
5452
$(AWS) lambda create-function \
5553
--function-name $(FUNCTION_NAME) \
5654
--runtime $(LAMBDA_RUNTIME) \
5755
--role arn:aws:iam::000000000000:role/lambda-role \
5856
--handler app.lambdaHandler \
59-
--zip-file fileb://hello-world/hello-world-javascript.zip \
57+
--zip-file fileb://hello-world/dist/hello-world-javascript.zip \
6058
--timeout 2
6159

6260
deploy-sam: ## Deploy the Lambda function via AWS SAM CLI
@@ -72,7 +70,7 @@ invoke: ## Invoke the Lambda function and show logs
7270

7371
# TODO: avoid having the built zip file in the source directory
7472
clean: ## Clean the build directory
75-
rm -rf hello-world/hello-world-javascript.zip
73+
cd hello-world && rm -rf ./dist ./node_modules ./coverage
7674

7775
start: ## Start LocalStack
7876
IMAGE_NAME=localstack/localstack-pro \

lambda-debugging-sam-typescript/hello-world/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"unit": "jest",
99
"lint": "eslint '*.ts' --quiet --fix",
1010
"compile": "tsc",
11-
"test": "npm run compile && npm run unit"
11+
"test": "npm run compile && npm run unit",
12+
"prebuild": "rm -rf dist",
13+
"build": "esbuild app.ts --bundle --sourcemap --sources-content=true --platform=node --target=es2020 --outfile=./dist/app.js",
14+
"postbuild": "cd dist && zip -r hello-world-javascript.zip ./app.js*"
1215
},
1316
"dependencies": {
1417
"esbuild": "^0.14.14"

0 commit comments

Comments
 (0)