@guardian/cdk 49.2.0 → 49.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,18 @@
1
- import { Function } from "aws-cdk-lib/aws-lambda";
2
1
  import type { FunctionProps } from "aws-cdk-lib/aws-lambda";
2
+ import { Alias, Function } from "aws-cdk-lib/aws-lambda";
3
3
  import { GuDistributable } from "../../types";
4
4
  import type { GuLambdaErrorPercentageMonitoringProps, GuLambdaThrottlingMonitoringProps } from "../cloudwatch";
5
5
  import type { GuStack } from "../core";
6
6
  import { AppIdentity } from "../core";
7
7
  export interface GuFunctionProps extends GuDistributable, Omit<FunctionProps, "code">, AppIdentity {
8
+ /**
9
+ * Create a new Lambda version and alias. This is only necessary if you want to use features which rely
10
+ * on versioning (e.g. SnapStart or Provisioned Concurrency).
11
+ *
12
+ * If you enable versioning you must ensure that your Lambda function whenever a new build is deployed via
13
+ * CloudFormation. The simplest way to do this is to include the build number in the `fileName` prop.
14
+ */
15
+ enableVersioning?: boolean;
8
16
  /**
9
17
  * Alarm if error percentage exceeds a threshold.
10
18
  */
@@ -42,6 +50,7 @@ export interface GuFunctionProps extends GuDistributable, Omit<FunctionProps, "c
42
50
  export declare class GuLambdaFunction extends Function {
43
51
  readonly app: string;
44
52
  readonly fileName: string;
53
+ readonly alias?: Alias;
45
54
  constructor(scope: GuStack, id: string, props: GuFunctionProps);
46
55
  }
47
56
  //# sourceMappingURL=lambda.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lambda.d.ts","sourceRoot":"","sources":["../../../src/constructs/lambda/lambda.ts"],"names":[],"mappings":"AAEA,OAAO,EAAQ,QAAQ,EAAiB,MAAM,wBAAwB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAW,MAAM,wBAAwB,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,sCAAsC,EAAE,iCAA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IACH,oBAAoB,CAAC,EAAE,iCAAiC,CAAC;CAC1D;AAeD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;gBAElB,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe;CA6D/D"}
@@ -65,6 +65,11 @@ class GuLambdaFunction extends aws_lambda_1.Function {
65
65
  });
66
66
  this.app = app;
67
67
  this.fileName = fileName;
68
+ if (props.enableVersioning) {
69
+ this.alias = new aws_lambda_1.Alias(scope, `${id}-AliasForLambda`, {
70
+ aliasName: scope.stage, version: this.currentVersion
71
+ });
72
+ }
68
73
  if (props.errorPercentageMonitoring) {
69
74
  new cloudwatch_1.GuLambdaErrorPercentageAlarm(scope, `${id}-ErrorPercentageAlarmForLambda`, {
70
75
  ...props.errorPercentageMonitoring,
@@ -1 +1 @@
1
- {"version":3,"file":"lambda.js","sourceRoot":"","sources":["../../../src/constructs/lambda/lambda.ts"],"names":[],"mappings":";;;AAAA,6CAAuC;AAEvC,uDAAuE;AAEvE,+CAA4C;AAC5C,uCAA8C;AAC9C,8CAAsF;AAGtF,kCAAqE;AACrE,gCAAoE;AAkBpE,SAAS,iBAAiB,CAAC,OAAgB,EAAE,UAAmB;IAC9D,IAAI,UAAU,EAAE;QACd,OAAO,UAAU,CAAC;KACnB;SAAM;QACL,QAAQ,OAAO,CAAC,MAAM,EAAE;YACtB,KAAK,0BAAa,CAAC,IAAI;gBACrB,OAAO,IAAI,CAAC;YACd;gBACE,OAAO,GAAG,CAAC;SACd;KACF;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,gBAAiB,SAAQ,qBAAQ;IAI5C,YAAY,KAAc,EAAE,EAAU,EAAE,KAAsB;QAC5D,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gBACnE,GAAG,KAAK,CAAC,oBAAoB;gBAC7B,MAAM,EAAE,IAAI;aACb,CAAC,CAAC;SACJ;QAED,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAElC,MAAM,oBAAoB,GAAsB;YAC9C,IAAI,0BAAoB,CAAC,KAAK,EAAE,KAAK,CAAC;YACtC,IAAI,0BAAoB,CAAC,KAAK,EAAE,KAAK,CAAC;SACvC,CAAC;QAEF,oBAAoB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;QAEnE,kBAAW,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF;AA3DD,4CA2DC","sourcesContent":["import { Duration } from \"aws-cdk-lib\";\nimport type { PolicyStatement } from \"aws-cdk-lib/aws-iam\";\nimport { Code, Function, RuntimeFamily } from \"aws-cdk-lib/aws-lambda\";\nimport type { FunctionProps, Runtime } from \"aws-cdk-lib/aws-lambda\";\nimport { Bucket } from \"aws-cdk-lib/aws-s3\";\nimport { GuDistributable } from \"../../types\";\nimport { GuLambdaErrorPercentageAlarm, GuLambdaThrottlingAlarm } from \"../cloudwatch\";\nimport type { GuLambdaErrorPercentageMonitoringProps, GuLambdaThrottlingMonitoringProps } from \"../cloudwatch\";\nimport type { GuStack } from \"../core\";\nimport { AppIdentity, GuDistributionBucketParameter } from \"../core\";\nimport { ReadParametersByName, ReadParametersByPath } from \"../iam\";\n\nexport interface GuFunctionProps extends GuDistributable, Omit<FunctionProps, \"code\">, AppIdentity {\n /**\n * Alarm if error percentage exceeds a threshold.\n */\n errorPercentageMonitoring?: GuLambdaErrorPercentageMonitoringProps;\n\n /**\n * Alarm if throttling occurs. Note, it is also worth considering a\n * concurrency limit (the `reservedConcurrentExecutions` prop) if you are\n * concerned about throttling.\n *\n * @see https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html\n */\n throttlingMonitoring?: GuLambdaThrottlingMonitoringProps;\n}\n\nfunction defaultMemorySize(runtime: Runtime, memorySize?: number): number {\n if (memorySize) {\n return memorySize;\n } else {\n switch (runtime.family) {\n case RuntimeFamily.JAVA:\n return 1024;\n default:\n return 512;\n }\n }\n}\n\n/**\n * Construct which creates a Lambda function.\n *\n * This Lambda relies on the code artifact residing in a standard location in S3. For more details on the bucket used,\n * see [[`GuDistributionBucketParameter`]]. By default, the path used will be `<stack>/<stage>/<app</<fileName>`.\n *\n * The default memory size of this Lambda will vary depending on the runtime chosen.\n * For Java runtimes (i.e. resource hungry Scala Lambdas!), 1024MB will be used. For all other runtimes,\n * the memory size defaults to 512MB. This can be overridden via the `memorySize` prop.\n *\n * By default, the timeout for this Lambda is 30 seconds. This can be overridden via the `timeout` prop.\n *\n * By default the Lambda is granted permission to read from the SSM parameter store subtree specific to this Lambda\n * (i.e. it can read all keys under `/<stage>/<stack>/<app>/`). If you need to add additional permissions, you can use\n * [`addToRolePolicy`](https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-lambda.FunctionBase.html#addwbrtowbrrolewbrpolicystatement).\n *\n * The Lambda has `STACK`, `STAGE` and `APP` environment variables which can be used to determine its identity.\n *\n * Note that this construct creates a Lambda without an event source. Depending on your use-case, you may wish to\n * consider using a pattern which instantiates a Lambda with an event source e.g. [[`GuScheduledLambda`]].\n */\nexport class GuLambdaFunction extends Function {\n public readonly app: string;\n public readonly fileName: string;\n\n constructor(scope: GuStack, id: string, props: GuFunctionProps) {\n const { app, fileName, runtime, memorySize, timeout } = props;\n\n const defaultEnvironmentVariables = {\n STACK: scope.stack,\n STAGE: scope.stage,\n APP: app,\n };\n\n const bucket = Bucket.fromBucketName(\n scope,\n `${id}-bucket`,\n GuDistributionBucketParameter.getInstance(scope).valueAsString\n );\n const objectKey = GuDistributable.getObjectKey(scope, { app }, { fileName });\n const code = Code.fromBucket(bucket, objectKey);\n super(scope, id, {\n ...props,\n environment: {\n ...props.environment,\n ...defaultEnvironmentVariables,\n },\n memorySize: defaultMemorySize(runtime, memorySize),\n timeout: timeout ?? Duration.seconds(30),\n code,\n });\n\n this.app = app;\n this.fileName = fileName;\n\n if (props.errorPercentageMonitoring) {\n new GuLambdaErrorPercentageAlarm(scope, `${id}-ErrorPercentageAlarmForLambda`, {\n ...props.errorPercentageMonitoring,\n lambda: this,\n });\n }\n\n if (props.throttlingMonitoring) {\n new GuLambdaThrottlingAlarm(scope, `${id}-ThrottlingAlarmForLambda`, {\n ...props.throttlingMonitoring,\n lambda: this,\n });\n }\n\n bucket.grantRead(this, objectKey);\n\n const ssmParamReadPolicies: PolicyStatement[] = [\n new ReadParametersByPath(scope, props),\n new ReadParametersByName(scope, props),\n ];\n\n ssmParamReadPolicies.map((policy) => this.addToRolePolicy(policy));\n\n AppIdentity.taggedConstruct(props, this);\n }\n}\n"]}
1
+ {"version":3,"file":"lambda.js","sourceRoot":"","sources":["../../../src/constructs/lambda/lambda.ts"],"names":[],"mappings":";;;AAAA,6CAAqC;AAGrC,uDAA4E;AAC5E,+CAA0C;AAC1C,uCAA4C;AAE5C,8CAAoF;AAEpF,kCAAmE;AACnE,gCAAkE;AA2BlE,SAAS,iBAAiB,CAAC,OAAgB,EAAE,UAAmB;IAC9D,IAAI,UAAU,EAAE;QACd,OAAO,UAAU,CAAC;KACnB;SAAM;QACL,QAAQ,OAAO,CAAC,MAAM,EAAE;YACtB,KAAK,0BAAa,CAAC,IAAI;gBACrB,OAAO,IAAI,CAAC;YACd;gBACE,OAAO,GAAG,CAAC;SACd;KACF;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,gBAAiB,SAAQ,qBAAQ;IAK5C,YAAY,KAAc,EAAE,EAAU,EAAE,KAAsB;QAC5D,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;QAE9D,MAAM,2BAA2B,GAAG;YAClC,KAAK,E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AAK,CAAC,oBAAoB,EAAE;YAC9B,IAAI,oCAAuB,CAAC,KAAK,EAAE,GAAG,EAAE,2BAA2B,EAAE;gBACnE,GAAG,KAAK,CAAC,oBAAoB;gBAC7B,MAAM,EAAE,IAAI;aACb,CAAC,CAAC;SACJ;QAED,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAElC,MAAM,oBAAoB,GAAsB;YAC9C,IAAI,0BAAoB,CAAC,KAAK,EAAE,KAAK,CAAC;YACtC,IAAI,0BAAoB,CAAC,KAAK,EAAE,KAAK,CAAC;SACvC,CAAC;QAEF,oBAAoB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;QAEnE,kBAAW,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF;AAlED,4CAkEC","sourcesContent":["import {Duration} from \"aws-cdk-lib\";\nimport type {PolicyStatement} from \"aws-cdk-lib/aws-iam\";\nimport type {FunctionProps, Runtime} from \"aws-cdk-lib/aws-lambda\";\nimport {Alias, Code, Function, RuntimeFamily} from \"aws-cdk-lib/aws-lambda\";\nimport {Bucket} from \"aws-cdk-lib/aws-s3\";\nimport {GuDistributable} from \"../../types\";\nimport type {GuLambdaErrorPercentageMonitoringProps, GuLambdaThrottlingMonitoringProps} from \"../cloudwatch\";\nimport {GuLambdaErrorPercentageAlarm, GuLambdaThrottlingAlarm} from \"../cloudwatch\";\nimport type {GuStack} from \"../core\";\nimport {AppIdentity, GuDistributionBucketParameter} from \"../core\";\nimport {ReadParametersByName, ReadParametersByPath} from \"../iam\";\n\nexport interface GuFunctionProps extends GuDistributable, Omit<FunctionProps, \"code\">, AppIdentity {\n /**\n * Create a new Lambda version and alias. This is only necessary if you want to use features which rely\n * on versioning (e.g. SnapStart or Provisioned Concurrency).\n *\n * If you enable versioning you must ensure that your Lambda function whenever a new build is deployed via\n * CloudFormation. The simplest way to do this is to include the build number in the `fileName` prop.\n */\n enableVersioning?: boolean;\n\n /**\n * Alarm if error percentage exceeds a threshold.\n */\n errorPercentageMonitoring?: GuLambdaErrorPercentageMonitoringProps;\n\n /**\n * Alarm if throttling occurs. Note, it is also worth considering a\n * concurrency limit (the `reservedConcurrentExecutions` prop) if you are\n * concerned about throttling.\n *\n * @see https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html\n */\n throttlingMonitoring?: GuLambdaThrottlingMonitoringProps;\n}\n\nfunction defaultMemorySize(runtime: Runtime, memorySize?: number): number {\n if (memorySize) {\n return memorySize;\n } else {\n switch (runtime.family) {\n case RuntimeFamily.JAVA:\n return 1024;\n default:\n return 512;\n }\n }\n}\n\n/**\n * Construct which creates a Lambda function.\n *\n * This Lambda relies on the code artifact residing in a standard location in S3. For more details on the bucket used,\n * see [[`GuDistributionBucketParameter`]]. By default, the path used will be `<stack>/<stage>/<app</<fileName>`.\n *\n * The default memory size of this Lambda will vary depending on the runtime chosen.\n * For Java runtimes (i.e. resource hungry Scala Lambdas!), 1024MB will be used. For all other runtimes,\n * the memory size defaults to 512MB. This can be overridden via the `memorySize` prop.\n *\n * By default, the timeout for this Lambda is 30 seconds. This can be overridden via the `timeout` prop.\n *\n * By default the Lambda is granted permission to read from the SSM parameter store subtree specific to this Lambda\n * (i.e. it can read all keys under `/<stage>/<stack>/<app>/`). If you need to add additional permissions, you can use\n * [`addToRolePolicy`](https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-lambda.FunctionBase.html#addwbrtowbrrolewbrpolicystatement).\n *\n * The Lambda has `STACK`, `STAGE` and `APP` environment variables which can be used to determine its identity.\n *\n * Note that this construct creates a Lambda without an event source. Depending on your use-case, you may wish to\n * consider using a pattern which instantiates a Lambda with an event source e.g. [[`GuScheduledLambda`]].\n */\nexport class GuLambdaFunction extends Function {\n public readonly app: string;\n public readonly fileName: string;\n public readonly alias?: Alias;\n\n constructor(scope: GuStack, id: string, props: GuFunctionProps) {\n const { app, fileName, runtime, memorySize, timeout } = props;\n\n const defaultEnvironmentVariables = {\n STACK: scope.stack,\n STAGE: scope.stage,\n APP: app,\n };\n\n const bucket = Bucket.fromBucketName(\n scope,\n `${id}-bucket`,\n GuDistributionBucketParameter.getInstance(scope).valueAsString\n );\n const objectKey = GuDistributable.getObjectKey(scope, { app }, { fileName });\n const code = Code.fromBucket(bucket, objectKey);\n super(scope, id, {\n ...props,\n environment: {\n ...props.environment,\n ...defaultEnvironmentVariables,\n },\n memorySize: defaultMemorySize(runtime, memorySize),\n timeout: timeout ?? Duration.seconds(30),\n code,\n });\n\n this.app = app;\n this.fileName = fileName;\n\n if (props.enableVersioning) {\n this.alias = new Alias(scope, `${id}-AliasForLambda`, {\n aliasName: scope.stage, version: this.currentVersion\n });\n }\n\n if (props.errorPercentageMonitoring) {\n new GuLambdaErrorPercentageAlarm(scope, `${id}-ErrorPercentageAlarmForLambda`, {\n ...props.errorPercentageMonitoring,\n lambda: this,\n });\n }\n\n if (props.throttlingMonitoring) {\n new GuLambdaThrottlingAlarm(scope, `${id}-ThrottlingAlarmForLambda`, {\n ...props.throttlingMonitoring,\n lambda: this,\n });\n }\n\n bucket.grantRead(this, objectKey);\n\n const ssmParamReadPolicies: PolicyStatement[] = [\n new ReadParametersByPath(scope, props),\n new ReadParametersByName(scope, props),\n ];\n\n ssmParamReadPolicies.map((policy) => this.addToRolePolicy(policy));\n\n AppIdentity.taggedConstruct(props, this);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"scheduled-lambda.d.ts","sourceRoot":"","sources":["../../src/patterns/scheduled-lambda.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,KAAK,EAAE,sCAAsC,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACrG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBA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,qBAAa,iBAAkB,SAAQ,gBAAgB;gBACzC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,sBAAsB;CAmBtE"}
@@ -17,7 +17,9 @@ class GuScheduledLambda extends lambda_1.GuLambdaFunction {
17
17
  };
18
18
  super(scope, id, lambdaProps);
19
19
  props.rules.forEach((rule, index) => {
20
- const target = new aws_events_targets_1.LambdaFunction(this);
20
+ // If we have an alias, ensure that all invocations are handled by the most recently published Lambda version.
21
+ // Otherwise, use the most recent unpublished version ($LATEST)
22
+ const target = this.alias ? new aws_events_targets_1.LambdaFunction(this.alias) : new aws_events_targets_1.LambdaFunction(this);
21
23
  new aws_events_1.Rule(this, `${id}-${rule.schedule.expressionString}-${index}`, {
22
24
  schedule: rule.schedule,
23
25
  targets: [target],
@@ -1 +1 @@
1
- {"version":3,"file":"scheduled-lambda.js","sourceRoot":"","sources":["../../src/patterns/scheduled-lambda.ts"],"names":[],"mappings":";;;AAAA,uDAA8C;AAE9C,uEAAgE;AAGhE,iDAAwD;AAuDxD;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,yBAAgB;IACrD,YAAY,KAAc,EAAE,EAAU,EAAE,KAA6B;QACnE,MAAM,WAAW,GAAoB;YACnC,GAAG,KAAK;YACR,yBAAyB,EAAE,KAAK,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,uBAAuB;SAClH,CAAC;QACF,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;QAE9B,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAClC,MAAM,MAAM,GAAG,IAAI,mCAAc,CAAC,IAAI,CAAC,CAAC;YACxC,IAAI,iBAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,KAAK,EAAE,EAAE;gBACjE,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,OAAO,EAAE,CAAC,MAAM,CAAC;gBACjB,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC1D,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlBD,8CAkBC","sourcesContent":["import { Rule } from \"aws-cdk-lib/aws-events\";\nimport type { Schedule } from \"aws-cdk-lib/aws-events\";\nimport { LambdaFunction } from \"aws-cdk-lib/aws-events-targets\";\nimport type { GuLambdaErrorPercentageMonitoringProps, NoMonitoring } from \"../constructs/cloudwatch\";\nimport type { GuStack } from \"../constructs/core\";\nimport { GuLambdaFunction } from \"../constructs/lambda\";\nimport type { GuFunctionProps } from \"../constructs/lambda\";\n\n/**\n * Configuration options for the [[`GuScheduledLambda`]] pattern.\n *\n * For all lambda function configuration options, see [[`GuFunctionProps`]].\n *\n * The `schedule` property determines when your lambda is invoked. For example, to invoke\n * the lambda every 5 minutes, use:\n * ```typescript\n * import { Schedule } from \"aws-cdk-lib/aws-events\";\n * import { Duration } from \"aws-cdk-lib/core\";\n *\n * const props = {\n * // Other props here\n * rules: [{ schedule: Schedule.rate(Duration.minutes(5)) }],\n * }\n * ```\n *\n * To invoke the lambda every weekday at 8am, use:\n * ```\n * import { Schedule } from \"aws-cdk-lib/aws-events\";\n *\n * const props = {\n * // Other props here\n * rules: [{ schedule: Schedule.expression(\"cron(0 8 ? * MON-FRI *)\") }],\n * }\n * ```\n *\n * It is advisable to configure an alarm based on the lambda's error percentage.\n * To do this, add the `monitoringConfiguration` property. The required properties for this are:\n *\n * ```typescript\n * monitoringConfiguration: {\n * toleratedErrorPercentage: <sensible_error_percentage_threshold>,\n * snsTopicName: \"my-topic-for-cloudwatch-alerts\",\n * }\n * ```\n * Other alarm properties (e.g. alarm name and description) will be pre-populated with sensible defaults.\n * For a full list of optional properties, see [[`GuLambdaErrorPercentageMonitoringProps`]].\n *\n * If your team do not use CloudWatch, it's possible to opt-out with the following configuration:\n * ```typescript\n * monitoringConfiguration: { noMonitoring: true }\n * ```\n */\nexport interface GuScheduledLambdaProps extends Omit<GuFunctionProps, \"errorPercentageMonitoring\"> {\n rules: Array<{\n schedule: Schedule;\n description?: string;\n }>;\n monitoringConfiguration: NoMonitoring | GuLambdaErrorPercentageMonitoringProps;\n}\n\n/**\n * Pattern which creates all of the resources needed to invoke a lambda function on a schedule.\n *\n * For all configuration options, see [[`GuScheduledLambdaProps`]].\n */\nexport class GuScheduledLambda extends GuLambdaFunction {\n constructor(scope: GuStack, id: string, props: GuScheduledLambdaProps) {\n const lambdaProps: GuFunctionProps = {\n ...props,\n errorPercentageMonitoring: props.monitoringConfiguration.noMonitoring ? undefined : props.monitoringConfiguration,\n };\n super(scope, id, lambdaProps);\n\n props.rules.forEach((rule, index) => {\n const target = new LambdaFunction(this);\n new Rule(this, `${id}-${rule.schedule.expressionString}-${index}`, {\n schedule: rule.schedule,\n targets: [target],\n ...(rule.description && { description: rule.description }),\n enabled: true,\n });\n });\n }\n}\n"]}
1
+ {"version":3,"file":"scheduled-lambda.js","sourceRoot":"","sources":["../../src/patterns/scheduled-lambda.ts"],"names":[],"mappings":";;;AAAA,uDAA8C;AAE9C,uEAAgE;AAGhE,iDAAwD;AAuDxD;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,yBAAgB;IACrD,YAAY,KAAc,EAAE,EAAU,EAAE,KAA6B;QACnE,MAAM,WAAW,GAAoB;YACnC,GAAG,KAAK;YACR,yBAAyB,EAAE,KAAK,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,uBAAuB;SAClH,CAAC;QACF,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;QAE9B,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAClC,8GAA8G;YAC9G,+DAA+D;YAC/D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,mCAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,mCAAc,CAAC,IAAI,CAAC,CAAC;YACtF,IAAI,iBAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,KAAK,EAAE,EAAE;gBACjE,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,OAAO,EAAE,CAAC,MAAM,CAAC;gBACjB,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC1D,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AApBD,8CAoBC","sourcesContent":["import { Rule } from \"aws-cdk-lib/aws-events\";\nimport type { Schedule } from \"aws-cdk-lib/aws-events\";\nimport { LambdaFunction } from \"aws-cdk-lib/aws-events-targets\";\nimport type { GuLambdaErrorPercentageMonitoringProps, NoMonitoring } from \"../constructs/cloudwatch\";\nimport type { GuStack } from \"../constructs/core\";\nimport { GuLambdaFunction } from \"../constructs/lambda\";\nimport type { GuFunctionProps } from \"../constructs/lambda\";\n\n/**\n * Configuration options for the [[`GuScheduledLambda`]] pattern.\n *\n * For all lambda function configuration options, see [[`GuFunctionProps`]].\n *\n * The `schedule` property determines when your lambda is invoked. For example, to invoke\n * the lambda every 5 minutes, use:\n * ```typescript\n * import { Schedule } from \"aws-cdk-lib/aws-events\";\n * import { Duration } from \"aws-cdk-lib/core\";\n *\n * const props = {\n * // Other props here\n * rules: [{ schedule: Schedule.rate(Duration.minutes(5)) }],\n * }\n * ```\n *\n * To invoke the lambda every weekday at 8am, use:\n * ```\n * import { Schedule } from \"aws-cdk-lib/aws-events\";\n *\n * const props = {\n * // Other props here\n * rules: [{ schedule: Schedule.expression(\"cron(0 8 ? * MON-FRI *)\") }],\n * }\n * ```\n *\n * It is advisable to configure an alarm based on the lambda's error percentage.\n * To do this, add the `monitoringConfiguration` property. The required properties for this are:\n *\n * ```typescript\n * monitoringConfiguration: {\n * toleratedErrorPercentage: <sensible_error_percentage_threshold>,\n * snsTopicName: \"my-topic-for-cloudwatch-alerts\",\n * }\n * ```\n * Other alarm properties (e.g. alarm name and description) will be pre-populated with sensible defaults.\n * For a full list of optional properties, see [[`GuLambdaErrorPercentageMonitoringProps`]].\n *\n * If your team do not use CloudWatch, it's possible to opt-out with the following configuration:\n * ```typescript\n * monitoringConfiguration: { noMonitoring: true }\n * ```\n */\nexport interface GuScheduledLambdaProps extends Omit<GuFunctionProps, \"errorPercentageMonitoring\"> {\n rules: Array<{\n schedule: Schedule;\n description?: string;\n }>;\n monitoringConfiguration: NoMonitoring | GuLambdaErrorPercentageMonitoringProps;\n}\n\n/**\n * Pattern which creates all of the resources needed to invoke a lambda function on a schedule.\n *\n * For all configuration options, see [[`GuScheduledLambdaProps`]].\n */\nexport class GuScheduledLambda extends GuLambdaFunction {\n constructor(scope: GuStack, id: string, props: GuScheduledLambdaProps) {\n const lambdaProps: GuFunctionProps = {\n ...props,\n errorPercentageMonitoring: props.monitoringConfiguration.noMonitoring ? undefined : props.monitoringConfiguration,\n };\n super(scope, id, lambdaProps);\n\n props.rules.forEach((rule, index) => {\n // If we have an alias, ensure that all invocations are handled by the most recently published Lambda version.\n // Otherwise, use the most recent unpublished version ($LATEST)\n const target = this.alias ? new LambdaFunction(this.alias) : new LambdaFunction(this);\n new Rule(this, `${id}-${rule.schedule.expressionString}-${index}`, {\n schedule: rule.schedule,\n targets: [target],\n ...(rule.description && { description: rule.description }),\n enabled: true,\n });\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@guardian/cdk",
3
3
  "description": "Generic Guardian flavoured AWS CDK components",
4
- "version": "49.2.0",
4
+ "version": "49.3.0-beta.1",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "files": [
@@ -28,35 +28,35 @@
28
28
  "cli:dev": "ts-node src/bin/index.ts"
29
29
  },
30
30
  "devDependencies": {
31
- "@guardian/eslint-config-typescript": "3.0.0",
31
+ "@guardian/eslint-config-typescript": "4.0.0",
32
32
  "@types/git-url-parse": "^9.0.1",
33
33
  "@types/jest": "^29.2.5",
34
34
  "@types/js-yaml": "^4.0.5",
35
35
  "@types/lodash.camelcase": "^4.3.7",
36
36
  "@types/lodash.kebabcase": "^4.1.7",
37
37
  "@types/lodash.upperfirst": "^4.3.7",
38
- "@types/node": "18.11.18",
38
+ "@types/node": "18.13.0",
39
39
  "@types/yargs": "^17.0.19",
40
40
  "aws-cdk": "2.59.0",
41
41
  "cz-conventional-changelog": "^3.3.0",
42
- "eslint": "^8.32.0",
42
+ "eslint": "^8.33.0",
43
43
  "eslint-plugin-custom-rules": "file:tools/eslint",
44
44
  "gh-pages": "^5.0.0",
45
45
  "jest": "^29.3.1",
46
- "prettier": "^2.8.3",
46
+ "prettier": "^2.8.4",
47
47
  "semantic-release": "^19.0.5",
48
48
  "serve": "^14.2.0",
49
49
  "ts-jest": "^29.0.5",
50
50
  "ts-node": "^10.9.1",
51
51
  "typedoc": "^0.23.24",
52
- "typescript": "~4.9.4"
52
+ "typescript": "~4.9.5"
53
53
  },
54
54
  "dependencies": {
55
55
  "@oclif/core": "1.24.2",
56
56
  "aws-cdk-lib": "2.59.0",
57
- "aws-sdk": "^2.1296.0",
57
+ "aws-sdk": "^2.1306.0",
58
58
  "chalk": "^4.1.2",
59
- "codemaker": "^1.73.0",
59
+ "codemaker": "^1.74.0",
60
60
  "constructs": "10.1.215",
61
61
  "git-url-parse": "^13.1.0",
62
62
  "js-yaml": "^4.1.0",