@guardian/cdk 50.0.0 → 50.1.0

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.
@@ -17,27 +17,47 @@ export interface GuFunctionProps extends GuDistributable, Omit<FunctionProps, "c
17
17
  * @see https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html
18
18
  */
19
19
  throttlingMonitoring?: GuLambdaThrottlingMonitoringProps;
20
+ /**
21
+ * SSM parameter for the S3 bucket that contains your lambda file.
22
+ *
23
+ * Typically you should not override this but you may need to if, for example,
24
+ * you are referencing a file that is shared across many apps and/or AWS
25
+ * accounts.
26
+ *
27
+ * @defaultValue [[`GuDistributionBucketParameter`]]
28
+ */
29
+ bucketNamePath?: string;
20
30
  }
21
31
  /**
22
32
  * Construct which creates a Lambda function.
23
33
  *
24
- * This Lambda relies on the code artifact residing in a standard location in S3. For more details on the bucket used,
25
- * see [[`GuDistributionBucketParameter`]]. By default, the path used will be `<stack>/<stage>/<app</<fileName>`.
34
+ * This Lambda relies on the code artifact residing in a standard location in
35
+ * S3. For more details on the bucket used, see
36
+ * [[`GuDistributionBucketParameter`]]. By default, the path used will be
37
+ * `<stack>/<stage>/<app</<fileName>`. If required, e.g. if you are sharing
38
+ * lambda code across apps or accounts, override the source bucket using the
39
+ * `bucketNamePath` prop.
26
40
  *
27
- * The default memory size of this Lambda will vary depending on the runtime chosen.
28
- * For Java runtimes (i.e. resource hungry Scala Lambdas!), 1024MB will be used. For all other runtimes,
29
- * the memory size defaults to 512MB. This can be overridden via the `memorySize` prop.
41
+ * The default memory size of this Lambda will vary depending on the runtime
42
+ * chosen. For Java runtimes (i.e. resource hungry Scala Lambdas!), 1024MB will
43
+ * be used. For all other runtimes, the memory size defaults to 512MB. This can
44
+ * be overridden via the `memorySize` prop.
30
45
  *
31
- * By default, the timeout for this Lambda is 30 seconds. This can be overridden via the `timeout` prop.
46
+ * By default, the timeout for this Lambda is 30 seconds. This can be overridden
47
+ * via the `timeout` prop.
32
48
  *
33
- * By default the Lambda is granted permission to read from the SSM parameter store subtree specific to this Lambda
34
- * (i.e. it can read all keys under `/<stage>/<stack>/<app>/`). If you need to add additional permissions, you can use
35
- * [`addToRolePolicy`](https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-lambda.FunctionBase.html#addwbrtowbrrolewbrpolicystatement).
49
+ * By default the Lambda is granted permission to read from the SSM parameter
50
+ * store subtree specific to this Lambda (i.e. it can read all keys under
51
+ * `/<stage>/<stack>/<app>/`). If you need to add additional permissions, you
52
+ * can use
53
+ * [`addToRolePolicy`](`https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-lambda.FunctionBase.html#addwbrtowbrrolewbrpolicystatement`).
36
54
  *
37
- * The Lambda has `STACK`, `STAGE` and `APP` environment variables which can be used to determine its identity.
55
+ * The Lambda has `STACK`, `STAGE` and `APP` environment variables which can be
56
+ * used to determine its identity.
38
57
  *
39
- * Note that this construct creates a Lambda without an event source. Depending on your use-case, you may wish to
40
- * consider using a pattern which instantiates a Lambda with an event source e.g. [[`GuScheduledLambda`]].
58
+ * Note that this construct creates a Lambda without an event source. Depending
59
+ * on your use-case, you may wish to consider using a pattern which instantiates
60
+ * a Lambda with an event source e.g. [[`GuScheduledLambda`]].
41
61
  */
42
62
  export declare class GuLambdaFunction extends Function {
43
63
  readonly app: string;
@@ -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,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAC/G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,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a,gBAAiB,SAAQ,QAAQ;IAC5C,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAErB,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe;CAuD/D"}
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GuLambdaFunction = void 0;
4
+ /* eslint "@guardian/tsdoc-required/tsdoc-required": 2 -- to begin rolling this out for public APIs. */
4
5
  const aws_cdk_lib_1 = require("aws-cdk-lib");
5
6
  const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
6
7
  const aws_s3_1 = require("aws-cdk-lib/aws-s3");
8
+ const aws_ssm_1 = require("aws-cdk-lib/aws-ssm");
7
9
  const types_1 = require("../../types");
8
10
  const cloudwatch_1 = require("../cloudwatch");
9
11
  const core_1 = require("../core");
@@ -24,33 +26,46 @@ function defaultMemorySize(runtime, memorySize) {
24
26
  /**
25
27
  * Construct which creates a Lambda function.
26
28
  *
27
- * This Lambda relies on the code artifact residing in a standard location in S3. For more details on the bucket used,
28
- * see [[`GuDistributionBucketParameter`]]. By default, the path used will be `<stack>/<stage>/<app</<fileName>`.
29
+ * This Lambda relies on the code artifact residing in a standard location in
30
+ * S3. For more details on the bucket used, see
31
+ * [[`GuDistributionBucketParameter`]]. By default, the path used will be
32
+ * `<stack>/<stage>/<app</<fileName>`. If required, e.g. if you are sharing
33
+ * lambda code across apps or accounts, override the source bucket using the
34
+ * `bucketNamePath` prop.
29
35
  *
30
- * The default memory size of this Lambda will vary depending on the runtime chosen.
31
- * For Java runtimes (i.e. resource hungry Scala Lambdas!), 1024MB will be used. For all other runtimes,
32
- * the memory size defaults to 512MB. This can be overridden via the `memorySize` prop.
36
+ * The default memory size of this Lambda will vary depending on the runtime
37
+ * chosen. For Java runtimes (i.e. resource hungry Scala Lambdas!), 1024MB will
38
+ * be used. For all other runtimes, the memory size defaults to 512MB. This can
39
+ * be overridden via the `memorySize` prop.
33
40
  *
34
- * By default, the timeout for this Lambda is 30 seconds. This can be overridden via the `timeout` prop.
41
+ * By default, the timeout for this Lambda is 30 seconds. This can be overridden
42
+ * via the `timeout` prop.
35
43
  *
36
- * By default the Lambda is granted permission to read from the SSM parameter store subtree specific to this Lambda
37
- * (i.e. it can read all keys under `/<stage>/<stack>/<app>/`). If you need to add additional permissions, you can use
38
- * [`addToRolePolicy`](https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-lambda.FunctionBase.html#addwbrtowbrrolewbrpolicystatement).
44
+ * By default the Lambda is granted permission to read from the SSM parameter
45
+ * store subtree specific to this Lambda (i.e. it can read all keys under
46
+ * `/<stage>/<stack>/<app>/`). If you need to add additional permissions, you
47
+ * can use
48
+ * [`addToRolePolicy`](`https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-lambda.FunctionBase.html#addwbrtowbrrolewbrpolicystatement`).
39
49
  *
40
- * The Lambda has `STACK`, `STAGE` and `APP` environment variables which can be used to determine its identity.
50
+ * The Lambda has `STACK`, `STAGE` and `APP` environment variables which can be
51
+ * used to determine its identity.
41
52
  *
42
- * Note that this construct creates a Lambda without an event source. Depending on your use-case, you may wish to
43
- * consider using a pattern which instantiates a Lambda with an event source e.g. [[`GuScheduledLambda`]].
53
+ * Note that this construct creates a Lambda without an event source. Depending
54
+ * on your use-case, you may wish to consider using a pattern which instantiates
55
+ * a Lambda with an event source e.g. [[`GuScheduledLambda`]].
44
56
  */
45
57
  class GuLambdaFunction extends aws_lambda_1.Function {
46
58
  constructor(scope, id, props) {
47
- const { app, fileName, runtime, memorySize, timeout } = props;
59
+ const { app, fileName, runtime, memorySize, timeout, bucketNamePath } = props;
60
+ const bucketName = bucketNamePath
61
+ ? aws_ssm_1.StringParameter.fromStringParameterName(scope, "bucketoverride", bucketNamePath).stringValue
62
+ : core_1.GuDistributionBucketParameter.getInstance(scope).valueAsString;
48
63
  const defaultEnvironmentVariables = {
49
64
  STACK: scope.stack,
50
65
  STAGE: scope.stage,
51
66
  APP: app,
52
67
  };
53
- const bucket = aws_s3_1.Bucket.fromBucketName(scope, `${id}-bucket`, core_1.GuDistributionBucketParameter.getInstance(scope).valueAsString);
68
+ const bucket = aws_s3_1.Bucket.fromBucketName(scope, `${id}-bucket`, bucketName);
54
69
  const objectKey = types_1.GuDistributable.getObjectKey(scope, { app }, { fileName });
55
70
  const code = aws_lambda_1.Code.fromBucket(bucket, objectKey);
56
71
  super(scope, id, {
@@ -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,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;QAE9D,MAAM,2BAA2B,GAAG;YAClC,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,GAAG,EAAE,GAAG;SACT,CAAC;QAEF,MAAM,MAAM,GAAG,eAAM,CAAC,cAAc,CAClC,KAAK,EACL,GAAG,EAAE,SAAS,EACd,oCAA6B,CAAC,WAA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M,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,uGAAuG;AACvG,6CAAuC;AAEvC,uDAAuE;AAEvE,+CAA4C;AAC5C,iDAAsD;AACtD,uCAA8C;AAC9C,8CAAsF;AAGtF,kCAAqE;AACrE,gCAAoE;AA2BpE,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAa,gBAAiB,SAAQ,qBAAQ;IAI5C,YAAY,KAAc,EAAE,EAAU,EAAE,KAAsB;QAC5D,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;QAE9E,MAAM,UAAU,GAAG,cAAc;YAC/B,CAAC,CAAC,yBAAe,CAAC,uBAAuB,CAAC,KAAK,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC,WAAW;YAC9F,CAAC,CAAC,oCAA6B,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC;QAEnE,MAAM,2BAA2B,GAAG;YAClC,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,GAA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AAC,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":["/* eslint \"@guardian/tsdoc-required/tsdoc-required\": 2 -- to begin rolling this out for public APIs. */\nimport { 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 { StringParameter } from \"aws-cdk-lib/aws-ssm\";\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 * 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 * SSM parameter for the S3 bucket that contains your lambda file.\n *\n * Typically you should not override this but you may need to if, for example,\n * you are referencing a file that is shared across many apps and/or AWS\n * accounts.\n *\n * @defaultValue [[`GuDistributionBucketParameter`]]\n */\n bucketNamePath?: string;\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\n * S3. For more details on the bucket used, see\n * [[`GuDistributionBucketParameter`]]. By default, the path used will be\n * `<stack>/<stage>/<app</<fileName>`. If required, e.g. if you are sharing\n * lambda code across apps or accounts, override the source bucket using the\n * `bucketNamePath` prop.\n *\n * The default memory size of this Lambda will vary depending on the runtime\n * chosen. For Java runtimes (i.e. resource hungry Scala Lambdas!), 1024MB will\n * be used. For all other runtimes, the memory size defaults to 512MB. This can\n * be overridden via the `memorySize` prop.\n *\n * By default, the timeout for this Lambda is 30 seconds. This can be overridden\n * via the `timeout` prop.\n *\n * By default the Lambda is granted permission to read from the SSM parameter\n * store subtree specific to this Lambda (i.e. it can read all keys under\n * `/<stage>/<stack>/<app>/`). If you need to add additional permissions, you\n * 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\n * used to determine its identity.\n *\n * Note that this construct creates a Lambda without an event source. Depending\n * on your use-case, you may wish to consider using a pattern which instantiates\n * 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, bucketNamePath } = props;\n\n const bucketName = bucketNamePath\n ? StringParameter.fromStringParameterName(scope, \"bucketoverride\", bucketNamePath).stringValue\n : GuDistributionBucketParameter.getInstance(scope).valueAsString;\n\n const defaultEnvironmentVariables = {\n STACK: scope.stack,\n STAGE: scope.stage,\n APP: app,\n };\n\n const bucket = Bucket.fromBucketName(scope, `${id}-bucket`, bucketName);\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"]}
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": "50.0.0",
4
+ "version": "50.1.0",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "files": [
@@ -36,15 +36,15 @@
36
36
  "@types/lodash.camelcase": "^4.3.7",
37
37
  "@types/lodash.kebabcase": "^4.1.7",
38
38
  "@types/lodash.upperfirst": "^4.3.7",
39
- "@types/node": "18.15.5",
39
+ "@types/node": "18.15.11",
40
40
  "@types/yargs": "^17.0.19",
41
41
  "aws-cdk": "2.68.0",
42
42
  "cz-conventional-changelog": "^3.3.0",
43
- "eslint": "^8.36.0",
43
+ "eslint": "^8.37.0",
44
44
  "eslint-plugin-custom-rules": "file:tools/eslint",
45
45
  "gh-pages": "^5.0.0",
46
46
  "jest": "^29.5.0",
47
- "prettier": "^2.8.4",
47
+ "prettier": "^2.8.7",
48
48
  "semantic-release": "^19.0.5",
49
49
  "serve": "^14.2.0",
50
50
  "ts-jest": "^29.0.5",
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "@oclif/core": "2.7.1",
57
57
  "aws-cdk-lib": "2.68.0",
58
- "aws-sdk": "^2.1339.0",
58
+ "aws-sdk": "^2.1346.0",
59
59
  "chalk": "^4.1.2",
60
60
  "codemaker": "^1.78.1",
61
61
  "constructs": "10.1.273",