How to use the @aws-cdk/aws-events.Schedule.rate function in @aws-cdk/aws-events

To help you get started, we’ve selected a few @aws-cdk/aws-events examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github punchcard / punchcard / examples / lib / data-lake.ts View on Github external
// Kinesis -> Lambda
// Note: the type-safety of the `record`
lake.pipelines.dataPoints.stream
  .records()
  .forEach(stack, 'ForEachDataPoint', {}, async (record) => {
    console.log('key', record.key);
    console.log('value', record.value);
    console.log('data points', record.data_points);
    console.log('timestamp', record.timestamp);
    // console.log('this does not compile', record.doesNotExist)
  });

// send some dumy data to the dataPoints schema
Lambda.schedule(stack, 'DummyDataPoints', {
  depends: lake.pipelines.dataPoints.stream.writeAccess(),
  schedule: Schedule.rate(Duration.minutes(1)),
}, async (_, stream) => {
  await stream.putRecord({
    Data: {
      key: 'key',
      data_points: [0, 1, 2],
      timestamp: new Date(),
      value: 'some-value'
    }
  });
});
github punchcard / punchcard / examples / lib / invoke-function.ts View on Github external
count: 1,
        anyProperty: {
          this: 'property can be any type supported by the AWS.DynamoDB.DocumentClient',
        }
      },
      if: item => DynamoDB.attribute_not_exists(item.id)
    });
    newCount = 1;
  }
  return newCount;
});

// call the incrementer function from another Lambda Function
Lambda.schedule(stack, 'Caller', {
  depends: incrementer.invokeAccess(),
  schedule: Schedule.rate(Duration.minutes(1)),
}, async (_, incrementer) => {
  const newCount = await incrementer.invoke({
    id: 'id'
  });
  console.log(`new count of 'id' is ${newCount}`);
});
github punchcard / punchcard / examples / lib / dynamodb.ts View on Github external
});

// 'count' is the sortKey in this case
const sortedTable: DynamoDB.Table<'id', 'count', Item> = new DynamoDB.Table(stack, 'sorted-table', {
  partitionKey: 'id',
  sortKey: 'count',
  attributes: Item,
  tableProps: Build.of({
    billingMode: BillingMode.PAY_PER_REQUEST
  })
});

// call the incrementer function from another Lambda Function
Lambda.schedule(stack, 'Caller', {
  depends: Core.Dependency.concat(table.readWriteAccess(), sortedTable.readAccess()),
  schedule: Schedule.rate(Duration.minutes(1)),
}, async (_, [table, sortedTable]) => {
  await table.get({
    id: 'id',
  });

  await table.put({
    // the item is type-safe and well structured
    item: {
      id: 'id',
      count: 1,
      name: 'name',
      any: {
        a: 'value'
      },
      array: ['some', 'values'],
      struct: {
github punchcard / punchcard / examples / lib / hello-world.ts View on Github external
import cdk = require('@aws-cdk/core');
import { Schedule } from '@aws-cdk/aws-events';
import { Core, Lambda } from 'punchcard';

export const app = new Core.App();
const stack = app.root.map(app => new cdk.Stack(app, 'hello-world'));

Lambda.schedule(stack, 'MyFunction', {
  schedule: Schedule.rate(cdk.Duration.minutes(1))
}, async() => console.log('Hello, World!'));
github punchcard / punchcard / examples / lib / stream-processing.ts View on Github external
tableProps: Build.lazy(() => ({
    billingMode: BillingMode.PAY_PER_REQUEST
  }))
});

/**
 * Schedule a Lambda Function to send a (dummy) message to the SNS topic:
 * 
 * CloudWatch Event --(minutely)--> Lambda --(send)-> SNS Topic
 *                                         --(put)--> Dynamo Table
 **/ 
Lambda.schedule(stack, 'DummyData', {
  /**
   * Trigger the function every minute.
   */
  schedule: Schedule.rate(Duration.minutes(1)),

  /**
   * Define our runtime dependencies:
   *
   * We want to *publish* to the SNS `topic` and *write* to the DynamoDB `table`.
   */
  depends: Core.Dependency.concat(
    topic.publishAccess(),
    enrichments.writeAccess()),

  
}, async (_, [topic, table]) => {
  /**
   * Impement the Lambda Function.
   * 
   * We are passed clients for each of our dependencies: the `topic` and `table`.
github punchcard / punchcard / examples / lib / scheduled-function.ts View on Github external
partitionKey: 'id',
  sortKey: undefined,
  attributes: {
    id: string(),
    count: integer({
      minimum: 0
    })
  },
  tableProps: Build.lazy(() => ({
    billingMode: BillingMode.PAY_PER_REQUEST
  }))
});

Lambda.schedule(stack, 'Poller', {
  depends: table.readWriteAccess(),
  schedule: Schedule.rate(Duration.minutes(1)),
}, async (_, table) => {
  const item = await table.get({
    id: 'state'
  });

  if (item) {
    await table.update({
      key: {
        id: 'state'
      },
      actions: item => [
        item.count.increment(1)
      ]
    });
  } else {
    await table.put({