You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*Issue #, if available:*
*Description of changes:*
* Implement aynschronous job infrastructure using Lambda
* Add AppSync Events API for realtime notification (e.g. on job
completion)
* Update docs
By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
[日本語の解説記事はこちら](https://tmokmss.hatenablog.com/entry/20220611/1654931458)。 (Additional article about this kit in Japanese.)
5
-
6
4
This is a full stack webapp kit for starters who want to leverage the power of AWS serverless services!
7
5
8
6
Features include:
9
7
10
-
* Express API endpoint (both with and without authentication)
11
-
* React.js frontend (assets are delivered via CDN)
12
-
* E-mail authentication
8
+
* Next.js App Router on AWS Lambda
9
+
* CloudFront + Lambda function URL with response stream support
10
+
* End to end type safety from client to server
11
+
* Cognito authentication
13
12
* Asynchronous job queue
14
-
* Scheduled job runner
15
-
* Instant deployment of the entire app
16
-
17
-
**NOTE:** You can also refer to [aws-samples/trpc-nextjs-ssr-prisma-lambda](https://github.com/aws-samples/trpc-nextjs-ssr-prisma-lambda) for end-to-end type safety, server side rendering, or relational database examples.
13
+
* Instant deployment of the entire app with a single command
18
14
19
15
## Overview
20
16
Here is the architecture of this kit. We use:
21
17
22
-
*[Amazon DynamoDB](https://aws.amazon.com/dynamodb/), a serverless scalable NoSQL database
23
-
*[Amazon API Gateway HTTP API](https://aws.amazon.com/api-gateway/) +[AWS Lambda](https://aws.amazon.com/lambda/)to build serverless API endpoint ([`serverless-express`](https://github.com/vendia/serverless-express))
*[Amazon Aurora PostgreSQL Serverless v2](https://aws.amazon.com/rds/aurora/serverless/), a serverless relational database with Prisma ORM
19
+
*[Next.js App Router](https://nextjs.org/docs/app) on[AWS Lambda](https://aws.amazon.com/lambda/)for a unified frontend and backend solution
20
+
*[Amazon CloudFront](https://aws.amazon.com/cloudfront/) + Lambda Function URL with response streaming support for efficient content delivery
25
21
*[Amazon Cognito](https://aws.amazon.com/cognito/) for authentication. By default, you can sign in/up by email, but you can federate with other OIDC providers such as Google, Facebook, and more with a little modification.
26
-
*[Amazon SQS](https://aws.amazon.com/sqs/) + AWS Lambda for asynchronous job queue.
27
-
*[Amazon EventBridge](https://aws.amazon.com/eventbridge/) to run scheduled jobs.
22
+
*[AWS AppSync Events](https://docs.aws.amazon.com/appsync/latest/eventapi/event-api-welcome.html) + AWS Lambda for asynchronous job and realtime notification.
23
+
*[Amazon EventBridge](https://aws.amazon.com/eventbridge/) to run scheduled jobs.
28
24
*[Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) + S3 for access logging.
29
25
*[AWS CDK](https://aws.amazon.com/cdk/) for Infrastructure as Code. It enables you to deploy the entire application with the simplest commands.
30
26
31
-

27
+

32
28
33
29
Since it fully leverages AWS serverless services, you can use it with high cost efficiency, scalability, and almost no heavy lifting of managing servers! In terms of cost, we further discuss how much it costs in the below [#Cost](#cost) section.
34
30
35
31
### About the sample app
36
-
To show how this kit works, we include a sample web app to write and store your memos.
32
+
To show how this kit works, we include a sample web app to manage your todo list.
37
33
With this sample, you can easily understand how each component works with other ones, and what the overall experience will be like.
*[AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) and a configured IAM profile
53
+
* A public domain name configured as a Hosted Zone in Amazon Route53
54
+
55
+
Before deployment, you need to update the domain name in [`bin/cdk.ts`](cdk/bin/cdk.ts) to use your own domain that is configured as a Hosted Zone in Route53:
56
+
57
+
```typescript
58
+
const props:EnvironmentProps= {
59
+
// ...
60
+
domainName: 'your-domain.example.com', // Replace with your domain name
61
+
};
62
+
```
57
63
58
64
Then run the following commands:
59
65
@@ -64,53 +70,45 @@ npx cdk bootstrap
64
70
npx cdk deploy
65
71
```
66
72
67
-
Initial deployment usually takes about 10 minutes. You can also use `npx cdk deploy` command to deploy when you modified your CDK templates in the future.
73
+
Initial deployment usually takes about 20 minutes. You can also use `npx cdk deploy` command to deploy when you modified your CDK templates in the future.
68
74
69
75
After a successful deployment, you will get a CLI output like the below:
Opening the URL in `FrontendDomainName` output, you can now try the sample app on your browser.
86
91
87
92
## Add your own features
88
-
To implement your own features, you may want to add frontend pages, backend API endpoints, or async jobs. The frontend is an ordinary React.js application, so you can follow the conventional ways to add pages to it. As for backend, there are step-by-step guides to add features in [backend/README.md](backend/README.md), so please follow the guide.
93
+
To implement your own features, you may want to add frontend pages, API routes, or async jobs. The project uses Next.js App Router, which provides a unified approach for both frontend and backend development. You can follow the conventional Next.js patterns to add pages and API routes. For more details, please refer to the [`webapp/README.md`](./webapp/README.md) guide.
89
94
90
95
If you want to add another authentication method such as Google or Facebook federation, you can follow this document: [Add social sign-in to a user pool](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-configuring-federation-with-social-idp.html).
91
96
92
97
## Local development
93
-
To develop frontend or backend locally, please refer to each `README.md` in the subdirectories:
98
+
To develop the webapp locally, please refer to the [`webapp/README.md`](./webapp/README.md).
94
99
95
-
*[Frontend](./frontend/README.md)
96
-
*[Backend](./backend/README.md)
97
-
98
-
Instead of running the backend API on your local environment, you can use `cdk watch` feature for development by just running the following command:
100
+
Before running webapp locally, you have to populate .env.local by the following steps:
99
101
100
102
```sh
101
-
cd cdk
102
-
npx cdk watch
103
+
cp .env.local.example .env.local
104
+
# edit .env.local using the stack outputs shown after cdk deploy
103
105
```
104
106
105
-
`cdk watch` allows you to instantly deploy your backend as soon as you change the code and "tail" logs from your Lambda functions, enabling rapid iteration cycles. See [this blog for more details](https://aws.amazon.com/blogs/developer/increasing-development-speed-with-cdk-watch/).
106
-
107
-
Using `cdk watch`, you will access the deployed AWS resources from your local frontend. You have to configure environment variables in [frontend/.env](./frontend/.env) file to properly access these resources. Please refer to [Frontend README](./frontend/README.md) for more details.
108
-
109
107
## Cost
110
-
API Gateway, Lambda, SQS, CloudWatch, CloudFront, and S3 offer free tier plans, which allows you to use those services almost freely for small businesses.
108
+
Lambda, SQS, CloudWatch, CloudFront, and S3 offer free tier plans, which allows you to use those services almost freely for small businesses.
111
109
Up to one million requests per month, most of the costs related to those services are free. See [this page for more details](https://aws.amazon.com/free/).
112
110
113
-
DynamoDB is billed basically by how many read and write counts processed. See [this page for the current prices](https://aws.amazon.com/dynamodb/pricing/on-demand/). DynamoDB provisioned capacity mode also offers free tier plans, so if you want to pay the minimal cost, you can switch the billing mode (see [database.ts](cdk/lib/constructs/database.ts)).
111
+
Aurora PostgreSQL Serverless v2 is billed based on compute and storage usage. The database automatically scales up and down based on workload, and you only pay for the resources you use. See [this page for the current prices](https://aws.amazon.com/rds/aurora/pricing/). Aurora Serverless v2 can scale down to almost zero during periods of inactivity, helping to minimize costs (see [database.ts](cdk/lib/constructs/database.ts) for configuration details).
114
112
115
113
Other costs will be derived from data transfer and Elastic Container Repository (used for Docker Lambda). Although it usually does not cost much compared to other services, you may want to continuously monitor the billing metrics. Please refer to [the document to set CloudWatch alarm for AWS charges](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html).
0 commit comments