Skip to content

Commit 3ad51f3

Browse files
committed
improve doc; add scheduled job sample; use zod-prisma-types
1 parent 4a481d0 commit 3ad51f3

13 files changed

Lines changed: 671 additions & 66 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Features include:
99
* CloudFront + Lambda function URL with response stream support
1010
* End to end type safety from client to server
1111
* Cognito authentication
12+
* Real-time notification from server to client
1213
* Asynchronous job queue
1314
* Instant deployment of the entire app with a single command
1415

@@ -19,7 +20,7 @@ Here is the architecture of this kit. We use:
1920
* [Next.js App Router](https://nextjs.org/docs/app) on [AWS Lambda](https://aws.amazon.com/lambda/) for a unified frontend and backend solution
2021
* [Amazon CloudFront](https://aws.amazon.com/cloudfront/) + Lambda Function URL with response streaming support for efficient content delivery
2122
* [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.
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+
* [AWS AppSync Events](https://docs.aws.amazon.com/appsync/latest/eventapi/event-api-welcome.html) + AWS Lambda for asynchronous job and real-time notification.
2324
* [Amazon EventBridge](https://aws.amazon.com/eventbridge/) to run scheduled jobs.
2425
* [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) + S3 for access logging.
2526
* [AWS CDK](https://aws.amazon.com/cdk/) for Infrastructure as Code. It enables you to deploy the entire application with the simplest commands.
@@ -50,7 +51,7 @@ You need the following tools to deploy this sample:
5051
* [Node.js](https://nodejs.org/en/download/) (>= v20)
5152
* [Docker](https://docs.docker.com/get-docker/)
5253
* [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+
* A public domain name configured as a Hosted Zone in Amazon Route53 (If you do not like this requirement, please [upvote the issue #47](https://github.com/aws-samples/serverless-full-stack-webapp-starter-kit/issues/47).)
5455

5556
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:
5657

cdk/lib/constructs/async-job.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Construct } from 'constructs';
2-
import { CfnOutput, Duration } from 'aws-cdk-lib';
2+
import { CfnOutput, Duration, TimeZone } from 'aws-cdk-lib';
33
import { Architecture, DockerImageCode, DockerImageFunction, IFunction } from 'aws-cdk-lib/aws-lambda';
44
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
55
import { Database } from './database';
66
import { EventBus } from './event-bus';
77
import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
88
import { join } from 'path';
9+
import { Schedule, ScheduleExpression, ScheduleTargetInput } from 'aws-cdk-lib/aws-scheduler';
10+
import { LambdaInvoke } from 'aws-cdk-lib/aws-scheduler-targets';
911

1012
export interface AsyncJobProps {
1113
readonly database: Database;
@@ -49,5 +51,21 @@ export class AsyncJob extends Construct {
4951

5052
new CfnOutput(this, 'HandlerArn', { value: handler.functionArn });
5153
this.handler = handler;
54+
55+
// you can add scheduled jobs here.
56+
this.addSchedule(
57+
'SampleJob',
58+
ScheduleExpression.cron({ minute: '0', hour: '0', day: '1', timeZone: TimeZone.ETC_UTC }),
59+
);
60+
}
61+
62+
public addSchedule(jobType: string, schedule: ScheduleExpression, payload?: any) {
63+
return new Schedule(this, jobType, {
64+
schedule,
65+
target: new LambdaInvoke(this.handler, {
66+
input: ScheduleTargetInput.fromObject({ jobType, payload }),
67+
retryAttempts: 5,
68+
}),
69+
});
5270
}
5371
}

cdk/lib/constructs/cron-jobs.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

cdk/lib/main-stack.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { BlockPublicAccess, Bucket, BucketEncryption, ObjectOwnership } from 'aw
33
import { Construct } from 'constructs';
44
import { AsyncJob } from './constructs/async-job';
55
import { Auth } from './constructs/auth';
6-
import { CronJobs } from './constructs/cron-jobs';
76
import { Database } from './constructs/database';
87
import { Vpc } from 'aws-cdk-lib/aws-ec2';
98
import { HostedZone } from 'aws-cdk-lib/aws-route53';

0 commit comments

Comments
 (0)