Punchcard
Punchcard is a TypeScript framework for building cloud applications atop the AWS CDK. It unifies Infrastructure Code with Runtime Code, meaning you can both declare resources and implement logic within the context of one node.js application. AWS resources are thought of as generic, type-safe objects — DynamoDB Tables are like a Map<K, V>
; SNS Topics, SQS Queues, and Kinesis Streams feel like an Array<T>
; and a Lambda Function is akin to a Function<A, B>
– like the standard library of a programming language.
Resources
- https://github.com/sam-goodwin/punchcard
- Punchcard Developer Guide - learn how to use Punchcard.
- Punchcard: Imagining the future of cloud programming - blog series exploring the philosophy behind this project.
Hello, World!
Running code in AWS is almost as simple as running it locally!
const app = new Core.App();
const stack = app.stack('hello, world!');
const topic: SNS.Topic<StringShape> = new SNS.Topic(this, 'Topic', {
shape: string
});
Lambda.schedule(this, 'SendNotification', {
rate: Schedule.rate(Duration.minutes(1)),
depends: topic,
handle: async(event, topic) => {
await topic.publish('Hello, World!');
}
});
const queue = topic.toSQSQueue(this, 'Queue');
queue.messages().forEach(this, 'ForEachMessge', {},
async(message) => {
console.log(`message '${message}' has length ${message.length}`);
}
);
Example Stacks
- Stream Processing - respond to SNS notifications with a Lambda Function; subscribe notifications to a SQS Queue and process them with a Lambda Function; process and forward data from a SQS Queue to a Kinesis Stream; sink records from the Stream to S3 and catalog it in a Glue Table.
- Invoke a Function from another Function - call a Function from another Function
- Real-Time Data Lake - collects data with Kinesis and persists to S3, exposed as a Glue Table in a Glue Database.
- Scheduled Lambda Function - runs a Lambda Function every minute and stores data in a DynamoDB Table.
- Pet Store API Gateway - implementation of the Pet Store API Gateway canonical example.
License
This library is licensed under the Apache 2.0 License.