Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add basic docs for scheduled lambda pattern #241

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/patterns/scheduled-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,60 @@ import type { GuStack } from "../constructs/core";
import { GuLambdaFunction } from "../constructs/lambda";
import type { GuFunctionProps } from "../constructs/lambda";

interface GuScheduledLambdaProps extends Omit<GuFunctionProps, "rules" | "apis" | "errorPercentageMonitoring"> {
/**
* Configuration options for the [[`GuScheduledLambda`]] pattern.
*
* For all lambda function configuration options, see [[`GuFunctionProps`]].
*
* The `schedule` property determines when your lambda is invoked. For example, to invoke
* the lambda every 5 minutes, use:
* ```typescript
* import { Schedule } from "@aws-cdk/aws-events";
* import { Duration } from "@aws-cdk/core";
*
* const props = {
* // Other props here
* schedule: Schedule.rate(Duration.minutes(5)),
* }
* ```
*
* To invoke the lambda every weekday at 8am, use:
* ```
* import { Schedule } from "@aws-cdk/aws-events";
*
* const props = {
* // Other props here
* schedule: Schedule.expression("cron(0 8 ? * MON-FRI *)"),
* }
* ```
*
* It is advisable to configure an alarm based on the lambda's error percentage.
* To do this, add the `monitoringConfiguration` property. The required properties for this are:
*
* ```typescript
* monitoringConfiguration: {
* toleratedErrorPercentage: <sensible_error_percentage_threshold>,
* snsTopicName: "my-topic-for-cloudwatch-alerts",
* }
* ```
* Other alarm properties (e.g. alarm name and description) will be pre-populated with sensible defaults.
* For a full list of optional properties, see [[`GuLambdaErrorPercentageMonitoringProps`]].
*
* If your team do not use CloudWatch, it's possible to opt-out with the following configuration:
* ```typescript
* monitoringConfiguration: { noMonitoring: true }
* ```
*/
export interface GuScheduledLambdaProps extends Omit<GuFunctionProps, "rules" | "apis" | "errorPercentageMonitoring"> {
schedule: Schedule;
monitoringConfiguration: NoMonitoring | GuLambdaErrorPercentageMonitoringProps;
}

/**
* Pattern which creates all of the resources needed to invoke a lambda function on a schedule.
*
* For all configuration options, see [[`GuScheduledLambdaProps`]].
*/
export class GuScheduledLambda extends GuLambdaFunction {
constructor(scope: GuStack, id: string, props: GuScheduledLambdaProps) {
const lambdaProps: GuFunctionProps = {
Expand Down