Skip to content

Commit 211b0c7

Browse files
committed
Add cloudfront example
1 parent ab195ea commit 211b0c7

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

examples/cloudfront/infra/api.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { apiGateway, cloudFront } from "@notation/aws.iac";
2+
import { api, router } from "@notation/aws/api-gateway";
3+
import { getTodos } from "../runtime/todos.fn";
4+
5+
const todoApi = api({ name: "todo-api" });
6+
const todoRouter = router(todoApi);
7+
8+
todoRouter.get("/todos2", getTodos);
9+
10+
const apiResource = todoApi.findResource(apiGateway.Api)!;
11+
12+
const cdn = todoApi.add(
13+
new cloudFront.Distribution({
14+
id: "my-cdn",
15+
config: {
16+
CallerReference: "todoApiCallerReference",
17+
Comment: "CloudFront Distribution for Todo API",
18+
Enabled: false,
19+
},
20+
dependencies: {
21+
origin: apiResource,
22+
},
23+
}),
24+
);

examples/cloudfront/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"private": true,
3+
"name": "cloudfront-demo",
4+
"scripts": {
5+
"compile": "notation compile infra/api.ts",
6+
"dashboard": "notation dashboard",
7+
"deploy": "notation deploy infra/api.ts",
8+
"destroy": "notation destroy infra/api.ts",
9+
"viz": "notation viz infra/api.ts",
10+
"watch": "notation watch infra/api.ts"
11+
},
12+
"dependencies": {
13+
"@notation/aws": "workspace:*",
14+
"@notation/cli": "workspace:*",
15+
"@notation/core": "workspace:*"
16+
},
17+
"devDependencies": {
18+
"@types/node": "^20.8.4"
19+
},
20+
"version": null
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { LambdaConfig } from "@notation/aws/lambda.fn";
2+
import { handle, json } from "@notation/aws/lambda.fn";
3+
import { api } from "./utils";
4+
5+
const todos = await api.get<any[]>("/todos");
6+
7+
export const getTodos = handle.apiRequest(() => {
8+
return json(todos);
9+
});
10+
11+
export const config: LambdaConfig = {
12+
service: "aws/lambda",
13+
timeout: 5,
14+
memory: 64,
15+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const api = {
2+
get: async <T = any>(path: string) => {
3+
const res = await fetch(`https://jsonplaceholder.typicode.com${path}`);
4+
return res.json() as Promise<T>;
5+
},
6+
};

examples/cloudfront/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "tsconfig/base.json",
3+
"compilerOptions": {
4+
"paths": {
5+
"runtime/*": ["./runtime/*"],
6+
"infra/*": ["./infra/*"]
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)