File tree Expand file tree Collapse file tree 5 files changed +75
-0
lines changed
Expand file tree Collapse file tree 5 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 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+ ) ;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 1+ {
2+ "extends" : " tsconfig/base.json" ,
3+ "compilerOptions" : {
4+ "paths" : {
5+ "runtime/*" : [" ./runtime/*" ],
6+ "infra/*" : [" ./infra/*" ]
7+ }
8+ }
9+ }
You can’t perform that action at this time.
0 commit comments