This library is built with (and relies on) the AWS CDK. If you're new to the CDK, the CDK Docs and the TypeScript CDK Workshop are good places to start.
Install punchcard
and the aws-cdk
:
npm install --save-dev aws-cdk
npm install @aws-cdk/core
npm install punchcard
Create an index.ts
file to contain your application's entrypoint:
import cdk = require('@aws-cdk/core');
import { Schedule } from '@aws-cdk/aws-events';
import { Core, Lambda } from 'punchcard';
const app = new Core.App();
// Constructs are created laziliy by mapping "into the" Build context
const stack = app.root.map(app => new cdk.Stack(app, 'MyStack'));
// you can also use the helper:
const stack = app.stack('MyStack');
Lambda.schedule(stack, 'MyFunction', {
schedule: Schedule.rate(cdk.Duration.minutes(1)),
}, async() => console.log('Hello, World!'));
This app schedules a Lambda Function to log out "Hello, World"
every minute. To deploy it to CloudFormation, compile your code and run cdk deploy
:
./node_modules/.bin/tsc
./node_modules/aws-cdk/bin/cdk deploy -a ./index.js