in example/index.ts [60:90]
constructor(scope: Construct, id: string, props: TrafficDriverProps) {
super(scope, id);
if (!props.read && !props.write) {
throw new Error('At least "read" or "write" must be set');
}
this.fn = new lambda.Function(this, 'LambdaFunction', {
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')),
runtime: lambda.Runtime.NODEJS_10_X,
handler: 'index.handler',
environment: {
TABLE_NAME: props.table.tableName,
READ: props.read ? 'TRUE' : '',
WRITE: props.write ? 'TRUE': '',
},
});
if (props.write) {
props.table.grantWriteData(this.fn);
}
if (props.read) {
props.table.grantReadData(this.fn);
}
new events.Rule(this, 'Tick', {
schedule: events.Schedule.rate(Duration.minutes(1)),
targets: [ new events_targets.LambdaFunction(this.fn) ],
});
}