Skip to content

Commit 3ab8c91

Browse files
authored
Update WORKSHOP.md
1 parent ebc5f27 commit 3ab8c91

File tree

1 file changed

+95
-76
lines changed

1 file changed

+95
-76
lines changed

WORKSHOP.md

Lines changed: 95 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,127 +6,146 @@ Workshop description.
66

77
## 1. Project setup and basic build
88

9-
1. **Create project folder**
9+
### Create project folder
10+
1011
Create a new folder for your project in a sensible location, for example:
1112

1213
```shell
1314
mkdir -p ~/Documents/daemon-labs/docker-aws-lambda
1415
```
1516

16-
> [!NOTE]
17+
> [!NOTE]
1718
> You can either create this via a terminal window or your file explorer.
1819
19-
2. **Open the new folder in your code editor**
20+
### Open the new folder in your code editor
2021

2122
> [!TIP]
2223
> If you are using VSCode, we can now do everything from within the code editor.
2324
24-
4. **Create `Dockerfile`**
25-
Add the following content:
25+
### Create `Dockerfile`
2626

27-
```Dockerfile
28-
FROM public.ecr.aws/lambda/nodejs:22
29-
```
27+
Add the following content:
3028

31-
5. **Create `docker-compose.yaml`**
32-
Add the following content to define your service:
29+
```Dockerfile
30+
FROM public.ecr.aws/lambda/nodejs:22
31+
```
3332

34-
```yaml
35-
---
36-
services:
37-
lambda:
38-
build: .
39-
```
33+
### Create `docker-compose.yaml`
4034

41-
> You'll also notice that we're mounting a volume, this is to ensure any generated files are saved back to your local host folder.
35+
Add the following content to define your service:
4236

43-
6. **Initial image check**
44-
- Run the following command
37+
```yaml
38+
---
39+
services:
40+
lambda:
41+
build: .
42+
```
4543
46-
```shell
47-
docker compose build
48-
```
44+
> [!NOTE]
45+
> You'll also notice that we're mounting a volume, this is to ensure any generated files are saved back to your local host folder.
4946
50-
> If you now run `docker images`, you'll see a newly created image which should be around 226MB in size.
47+
### Initial image check
5148
52-
- Run the following command
49+
Run the following command:
5350
54-
```shell
55-
docker compose run -it --rm --entrypoint /bin/sh -v ./app:/var/task lambda
56-
```
51+
```shell
52+
docker compose build
53+
```
54+
55+
> [!NOTE]
56+
> If you now run `docker images`, you'll see a newly created image which should be around 226MB in size.
57+
58+
Run the following command:
59+
60+
```shell
61+
docker compose run -it --rm --entrypoint /bin/sh -v ./app:/var/task lambda
62+
```
5763

58-
> This command opens an interactive session with the container.
64+
> [!NOTE]
65+
> This command opens an interactive session with the container.
5966
60-
- Run the following command
67+
Run the following command:
6168

62-
```shell
63-
node --version
64-
```
69+
```shell
70+
node --version
71+
```
6572

66-
> The output should start with `v22` followed by the latest minor and patch version.
73+
> [!NOTE]
74+
> The output should start with `v22` followed by the latest minor and patch version.
6775
6876
---
6977

7078
## 2. Dependency management and TypeScript config
7179

72-
1. **Initialise project and install dev dependencies**
73-
- Run the following command
80+
### Initialise project and install dev dependencies
7481

75-
```shell
76-
npm init -y
77-
```
82+
Run the following command:
7883

79-
> Notice how the `lambda` directory is automatically created on your host machine due to the volume mount.
80-
- Run the following command
84+
```shell
85+
npm init -y
86+
```
87+
88+
> [!NOTE]
89+
> Notice how the `lambda` directory is automatically created on your host machine due to the volume mount.
90+
91+
Run the following command:
92+
93+
```shell
94+
npm add --save-dev @types/node@22 @types/aws-lambda @tsconfig/recommended typescript
95+
```
96+
97+
> [!NOTE]
98+
> Notice this automatically creates a `package-lock.json` file.
99+
> Even though dependencies have been installed, if you run `docker images` again, you'll see the image size hasn't changed because the `node_modules` were written to your local volume, not the image layer.
81100
82-
```shell
83-
npm add --save-dev @types/node@22 @types/aws-lambda @tsconfig/recommended typescript
84-
```
101+
### Exit the container
85102

86-
> Notice this automatically creates a `package-lock.json` file.
87-
> Even though dependencies have been installed, if you run `docker images` again, you'll see the image size hasn't changed because the `node_modules` were written to your local volume, not the image layer.
103+
Run the following command:
88104

89-
2. **Exit the container**
90-
- Run the following command
105+
```shell
106+
exit
107+
```
108+
109+
> [!NOTE]
110+
> We are now done with the interactive container at this stage and no longer need it.
111+
112+
### Create `tsconfig.json`
91113

92-
```shell
93-
exit
94-
```
114+
Create `tsconfig.json` and add the following content to configure the TypeScript compiler:
95115

96-
> We are now done with the interactive container at this stage and no longer need it.
116+
```json
117+
{
118+
"extends": "@tsconfig/recommended/tsconfig.json",
119+
"compilerOptions": {
120+
"outDir": "./build/dist"
121+
}
122+
}
123+
```
97124

98-
3. **Create `tsconfig.json`**
99-
Create `tsconfig.json` and add the following content to configure the TypeScript compiler:
125+
> [!NOTE]
126+
> While you could auto-generate this file, our manual configuration using a recommended preset keeps the file minimal and clean.
100127
101-
```json
102-
{
103-
"extends": "@tsconfig/recommended/tsconfig.json",
104-
"compilerOptions": {
105-
"outDir": "./build/dist"
106-
}
107-
}
108-
```
128+
### Create source file and scripts
109129

110-
> ℹ️ While you could auto-generate this file, our manual configuration using a recommended preset keeps the file minimal and clean.
130+
Create `./src/index.ts` with the following:
111131

112-
4. **Create source file and scripts**
113-
- Create `./src/index.ts` with the following:
132+
```typescript
133+
import { Handler } from "aws-lambda";
114134

115-
```typescript
116-
import { Handler } from "aws-lambda";
135+
export const handler: Handler = (event, context) => {
136+
console.log("Hello world!");
137+
};
138+
```
117139

118-
export const handler: Handler = (event, context) => {
119-
console.log("Hello world!");
120-
};
121-
```
140+
Add the following to the `scripts` section in your `package.json`:
122141

123-
- Add the following to the `scripts` section in your `package.json`:
142+
```json
143+
"build": "npm run build:tsc && npm run build:dependencies",
144+
"build:tsc": "rm -rf ./build/dist && tsc",
145+
"build:dependencies": "rm -rf ./build/dependencies && mkdir -p ./build/dependencies/nodejs && cp ./package*.json ./build/dependencies/nodejs && npm ci --omit dev --prefix ./build/dependencies/nodejs",
146+
```
124147

125-
```json
126-
"build": "npm run build:tsc && npm run build:dependencies",
127-
"build:tsc": "rm -rf ./build/dist && tsc",
128-
"build:dependencies": "rm -rf ./build/dependencies && mkdir -p ./build/dependencies/nodejs && cp ./package*.json ./build/dependencies/nodejs && npm ci --omit dev --prefix ./build/dependencies/nodejs",
129-
```
148+
---
130149

131150
Update the `Dockerfile`
132151

0 commit comments

Comments
 (0)