Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Cloudfront #21

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/cloudfront/infra/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { apiGateway, cloudFront } from "@notation/aws.iac";
import { api, router } from "@notation/aws/api-gateway";
import { getTodos } from "../runtime/todos.fn";

const todoApi = api({ name: "todo-api" });
const todoRouter = router(todoApi);

todoRouter.get("/todos2", getTodos);

const apiResource = todoApi.findResource(apiGateway.Api)!;

const cdn = todoApi.add(
new cloudFront.Distribution({
id: "my-cdn",
config: {
CallerReference: "todoApiCallerReference",
Comment: "CloudFront Distribution for Todo API",
Enabled: false,
},
dependencies: {
origin: apiResource,
},
}),
);
21 changes: 21 additions & 0 deletions examples/cloudfront/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"private": true,
"name": "cloudfront-demo",
"scripts": {
"compile": "notation compile infra/api.ts",
"dashboard": "notation dashboard",
"deploy": "notation deploy infra/api.ts",
"destroy": "notation destroy infra/api.ts",
"viz": "notation viz infra/api.ts",
"watch": "notation watch infra/api.ts"
},
"dependencies": {
"@notation/aws": "workspace:*",
"@notation/cli": "workspace:*",
"@notation/core": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.8.4"
},
"version": null
}
15 changes: 15 additions & 0 deletions examples/cloudfront/runtime/todos.fn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { LambdaConfig } from "@notation/aws/lambda.fn";
import { handle, json } from "@notation/aws/lambda.fn";
import { api } from "./utils";

const todos = await api.get<any[]>("/todos");

export const getTodos = handle.apiRequest(() => {
return json(todos);
});

export const config: LambdaConfig = {
service: "aws/lambda",
timeout: 5,
memory: 64,
};
6 changes: 6 additions & 0 deletions examples/cloudfront/runtime/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const api = {
get: async <T = any>(path: string) => {
const res = await fetch(`https://jsonplaceholder.typicode.com${path}`);
return res.json() as Promise<T>;
},
};
9 changes: 9 additions & 0 deletions examples/cloudfront/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"paths": {
"runtime/*": ["./runtime/*"],
"infra/*": ["./infra/*"]
}
}
}
15 changes: 8 additions & 7 deletions packages/aws.iac/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
"dist"
],
"dependencies": {
"@aws-sdk/client-apigatewayv2": "^3.441.0",
"@aws-sdk/client-cloudwatch-logs": "^3.441.0",
"@aws-sdk/client-eventbridge": "^3.470.0",
"@aws-sdk/client-iam": "^3.441.0",
"@aws-sdk/client-lambda": "^3.441.0",
"@aws-sdk/client-sts": "^3.441.0",
"@aws-sdk/client-apigatewayv2": "^3.511.0",
"@aws-sdk/client-cloudfront": "^3.511.0",
"@aws-sdk/client-cloudwatch-logs": "^3.511.0",
"@aws-sdk/client-eventbridge": "^3.511.0",
"@aws-sdk/client-iam": "^3.511.0",
"@aws-sdk/client-lambda": "^3.511.0",
"@aws-sdk/client-sts": "^3.511.0",
"@notation/core": "workspace:*",
"@notation/std.iac": "workspace:*",
"@types/aws-lambda": "^8.10.125",
"@types/aws-lambda": "^8.10.133",
"zod": "^3.22.4"
}
}
3 changes: 2 additions & 1 deletion packages/aws.iac/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./client";
export * as apiGateway from "./resources/api-gateway";
export * as lambda from "./resources/lambda";
export * as cloudFront from "./resources/cloudfront";
export * as eventBridge from "./resources/event-bridge";
export * as lambda from "./resources/lambda";
Loading
Loading