@byaga/cdk-patterns 0.11.5 → 0.11.6

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.
Files changed (111) hide show
  1. package/LICENSE.md +20 -20
  2. package/README.md +42 -42
  3. package/eslint.config.mjs +12 -0
  4. package/lib/build/copy-files.d.ts +4 -5
  5. package/lib/build/copy-files.js +26 -21
  6. package/lib/build/generate-hash.d.ts +2 -3
  7. package/lib/build/generate-hash.js +3 -5
  8. package/lib/build/get-files.d.ts +3 -3
  9. package/lib/build/get-files.js +3 -3
  10. package/lib/build/get-source-directory.d.ts +8 -8
  11. package/lib/build/get-source-directory.js +13 -13
  12. package/lib/build/hash-file.js +4 -5
  13. package/lib/build/index.d.ts +2 -0
  14. package/lib/build/index.js +21 -0
  15. package/lib/build/nodejs/build-ecmascript.d.ts +3 -3
  16. package/lib/build/nodejs/build-ecmascript.js +4 -5
  17. package/lib/build/nodejs/build-node-source.d.ts +9 -3
  18. package/lib/build/nodejs/build-node-source.js +10 -11
  19. package/lib/build/nodejs/build-typescript.d.ts +3 -3
  20. package/lib/build/nodejs/build-typescript.js +7 -10
  21. package/lib/build/nodejs/index.d.ts +1 -0
  22. package/lib/build/nodejs/index.js +5 -0
  23. package/lib/build/nodejs/install-node-modules.d.ts +4 -3
  24. package/lib/build/nodejs/install-node-modules.js +6 -6
  25. package/lib/cloud-formation/DeployStack.d.ts +11 -0
  26. package/lib/cloud-formation/DeployStack.js +2 -0
  27. package/lib/cloud-formation/create-stack.d.ts +20 -0
  28. package/lib/cloud-formation/create-stack.js +31 -0
  29. package/lib/cloud-formation/current-stack.d.ts +10 -0
  30. package/lib/cloud-formation/current-stack.js +19 -0
  31. package/lib/{generate-identifier.js → cloud-formation/generate-identifier.js} +7 -8
  32. package/lib/cloud-formation/index.d.ts +5 -0
  33. package/lib/cloud-formation/index.js +14 -0
  34. package/lib/cloud-formation/output.d.ts +2 -0
  35. package/lib/cloud-formation/output.js +12 -0
  36. package/lib/cloud-front/distribution.d.ts +16 -0
  37. package/lib/cloud-front/distribution.js +43 -0
  38. package/lib/cloud-front/index.d.ts +1 -0
  39. package/lib/cloud-front/index.js +5 -0
  40. package/lib/cloud-watch/create-log-group.js +4 -6
  41. package/lib/cloud-watch/index.d.ts +1 -0
  42. package/lib/cloud-watch/index.js +5 -0
  43. package/lib/cloud-watch/set-log-retention.d.ts +2 -0
  44. package/lib/cloud-watch/set-log-retention.js +14 -0
  45. package/lib/index.d.ts +11 -8
  46. package/lib/index.js +13 -29
  47. package/lib/lambda/create-function.d.ts +4 -2
  48. package/lib/lambda/create-function.js +15 -23
  49. package/lib/lambda/create-nodejs-lambda.d.ts +2 -2
  50. package/lib/lambda/create-nodejs-lambda.js +3 -4
  51. package/lib/lambda/index.d.ts +1 -0
  52. package/lib/lambda/index.js +5 -0
  53. package/lib/lambda-layer/apply-honeycomb-to-lambda.d.ts +1 -1
  54. package/lib/lambda-layer/apply-honeycomb-to-lambda.js +4 -5
  55. package/lib/lambda-layer/get-layer.js +4 -6
  56. package/lib/lambda-layer/index.d.ts +2 -0
  57. package/lib/lambda-layer/index.js +7 -0
  58. package/lib/lambda-layer/layer-cache.d.ts +3 -3
  59. package/lib/lambda-layer/layer-cache.js +3 -9
  60. package/lib/load-configuration.d.ts +3 -8
  61. package/lib/load-configuration.js +20 -11
  62. package/lib/recipes/ICorsConfig.d.ts +5 -0
  63. package/lib/recipes/ICorsConfig.js +2 -0
  64. package/lib/recipes/index.d.ts +1 -0
  65. package/lib/recipes/index.js +5 -0
  66. package/lib/recipes/staticWebSite.d.ts +13 -0
  67. package/lib/recipes/staticWebSite.js +54 -0
  68. package/lib/route53/IDomainConfig.d.ts +7 -0
  69. package/lib/route53/IDomainConfig.js +2 -0
  70. package/lib/route53/IHostedZoneConfig.d.ts +5 -0
  71. package/lib/route53/IHostedZoneConfig.js +2 -0
  72. package/lib/route53/apiCertificate.d.ts +13 -0
  73. package/lib/route53/apiCertificate.js +30 -0
  74. package/lib/route53/index.d.ts +3 -0
  75. package/lib/route53/index.js +5 -0
  76. package/lib/s3/bucket.d.ts +8 -0
  77. package/lib/s3/bucket.js +21 -0
  78. package/lib/s3/index.d.ts +1 -0
  79. package/lib/s3/index.js +5 -0
  80. package/lib/ssm/SsmParameter.d.ts +2 -2
  81. package/lib/ssm/StringParameter.d.ts +9 -0
  82. package/lib/ssm/StringParameter.js +15 -0
  83. package/lib/ssm/get-existing-parameter.js +4 -6
  84. package/lib/ssm/grant-read.js +1 -2
  85. package/lib/ssm/index.d.ts +1 -0
  86. package/lib/ssm/index.js +3 -1
  87. package/lib/ssm/parameter-cache.js +2 -3
  88. package/lib/ssm/string-value.js +1 -2
  89. package/lib/tools/index.d.ts +3 -0
  90. package/lib/tools/index.js +10 -0
  91. package/package.json +21 -15
  92. package/tsconfig.json +2 -2
  93. package/.fleet/run.json +0 -11
  94. package/archive/ApiAttachPoint.ts +0 -9
  95. package/archive/ApiCertificate.ts +0 -32
  96. package/archive/CognitoApiGatewayAuthorizer.ts +0 -25
  97. package/archive/DynamoDbTable.ts +0 -40
  98. package/archive/ICorsConfig.ts +0 -5
  99. package/archive/IDomainConfig.ts +0 -8
  100. package/archive/IHostedZoneConfig.ts +0 -5
  101. package/archive/NodeJsLambdaLayer.ts +0 -42
  102. package/archive/Output.ts +0 -11
  103. package/archive/RestApi.ts +0 -180
  104. package/archive/Role.ts +0 -165
  105. package/archive/StaticWebSite.ts +0 -158
  106. package/archive/index.ts +0 -18
  107. package/archive/methods/apply-schema-to-method-options.ts +0 -38
  108. package/archive/methods/attach-function-to-api.ts +0 -69
  109. package/lib/create-stack.d.ts +0 -40
  110. package/lib/create-stack.js +0 -48
  111. /package/lib/{generate-identifier.d.ts → cloud-formation/generate-identifier.d.ts} +0 -0
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.installNodeModules = void 0;
6
+ exports.installNodeModules = installNodeModules;
7
7
  const child_process_1 = require("child_process");
8
8
  const duration_1 = __importDefault(require("../../tools/duration"));
9
9
  /**
@@ -14,17 +14,17 @@ const duration_1 = __importDefault(require("../../tools/duration"));
14
14
  * It also measures and logs the duration of the `npm install` command.
15
15
  *
16
16
  * @function installNodeModules
17
- * @param {string} dir - The directory in which to run `npm install`.
18
- * @param {string[]} [omit=[]] - The types of dependencies to omit. Possible values are 'dev', 'optional', and 'peer'.
17
+ * @param dir - The directory in which to run `npm install`.
18
+ * @param omit - The types of dependencies to omit. Possible values are 'dev', 'optional', and 'peer'.
19
19
  */
20
20
  function installNodeModules(dir, omit = []) {
21
21
  // Start measuring the duration of the `npm install` command
22
22
  const installComplete = (0, duration_1.default)();
23
23
  // Run the `npm install` command in the specified directory, omitting certain types of dependencies if specified
24
- (0, child_process_1.execSync)(`npm i${omit.map(o => ` --omit=${o}`).join('')} --quite`, {
25
- cwd: dir
24
+ (0, child_process_1.spawnSync)('npm', ['i', ...omit.map(o => `--omit=${o}`), '--quiet'], {
25
+ cwd: dir,
26
+ stdio: 'inherit'
26
27
  });
27
28
  // Log the duration of the `npm install` command
28
29
  console.log('NPM Install Duration (ms)', installComplete());
29
30
  }
30
- exports.installNodeModules = installNodeModules;
@@ -0,0 +1,11 @@
1
+ import type { Stack } from "aws-cdk-lib/core";
2
+ /**
3
+ * Interface for the deploy stack.
4
+ */
5
+ export interface DeployStack<T> {
6
+ stack: Stack;
7
+ name: string;
8
+ stage: string;
9
+ project: string;
10
+ config: T;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ import type { IConstruct } from "constructs";
2
+ import type { DeployStack } from "./DeployStack";
3
+ import { type StackProps } from "aws-cdk-lib/core";
4
+ /**
5
+ * Interface for the arguments when creating a stack.
6
+ */
7
+ export interface StackArguments extends StackProps {
8
+ stackName: string;
9
+ stage?: string;
10
+ project: string;
11
+ owner: string;
12
+ region: string;
13
+ }
14
+ /**
15
+ * Creates a new stack.
16
+ * @param scope - The scope in which to define this construct.
17
+ * @param props - The arguments for creating the stack.
18
+ * @returns The created stack.
19
+ */
20
+ export declare function createStack<Config extends StackArguments>(scope: IConstruct, props: StackArguments): DeployStack<Config>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStack = createStack;
4
+ const core_1 = require("aws-cdk-lib/core");
5
+ const generate_identifier_1 = require("./generate-identifier");
6
+ const load_configuration_1 = require("../load-configuration");
7
+ const current_stack_1 = require("./current-stack");
8
+ /**
9
+ * Creates a new stack.
10
+ * @param scope - The scope in which to define this construct.
11
+ * @param props - The arguments for creating the stack.
12
+ * @returns The created stack.
13
+ */
14
+ function createStack(scope, props) {
15
+ const { stage = 'develop' } = props;
16
+ const stack = new core_1.Stack(scope, (0, generate_identifier_1.genId)(props.stackName, stage), {
17
+ ...props,
18
+ stackName: (0, generate_identifier_1.genName)(props.stackName, stage)
19
+ });
20
+ stack.tags.setTag('stage', stage);
21
+ stack.tags.setTag('stack', (0, generate_identifier_1.genName)(props.stackName, stage));
22
+ stack.tags.setTag('project', props.project);
23
+ stack.tags.setTag('owner', props.owner);
24
+ return (0, current_stack_1.setCurrentStack)({
25
+ stack,
26
+ name: props.stackName,
27
+ stage,
28
+ project: props.project,
29
+ config: (0, load_configuration_1.loadConfiguration)(stage)
30
+ });
31
+ }
@@ -0,0 +1,10 @@
1
+ import type { DeployStack } from "./DeployStack";
2
+ /**
3
+ * Helpful method to get the 'current' stack that is being defined. Hopefully this will reduce the need to pass the stack around everywhere.
4
+ */
5
+ export declare function getCurrentStack<T>(): DeployStack<T>;
6
+ /**
7
+ * This sets the 'current' stack. This should be automatic everywhere, but in case something goes wrong here is a way to force the issue
8
+ * @param stack
9
+ */
10
+ export declare function setCurrentStack<T>(stack: DeployStack<T>): DeployStack<T>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCurrentStack = getCurrentStack;
4
+ exports.setCurrentStack = setCurrentStack;
5
+ let currentStack;
6
+ /**
7
+ * Helpful method to get the 'current' stack that is being defined. Hopefully this will reduce the need to pass the stack around everywhere.
8
+ */
9
+ function getCurrentStack() {
10
+ return currentStack;
11
+ }
12
+ /**
13
+ * This sets the 'current' stack. This should be automatic everywhere, but in case something goes wrong here is a way to force the issue
14
+ * @param stack
15
+ */
16
+ function setCurrentStack(stack) {
17
+ currentStack = stack;
18
+ return stack;
19
+ }
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.genStackResourceId = exports.genStackResourceName = exports.genId = exports.genName = void 0;
4
- const create_stack_1 = require("./create-stack");
3
+ exports.genName = genName;
4
+ exports.genId = genId;
5
+ exports.genStackResourceName = genStackResourceName;
6
+ exports.genStackResourceId = genStackResourceId;
7
+ const current_stack_1 = require("./current-stack");
5
8
  /**
6
9
  * Generates a name by joining the provided strings with a hyphen.
7
10
  * Each string is converted to lowercase and any uppercase letters are replaced with a hyphen followed by the lowercase letter.
@@ -16,7 +19,6 @@ function genName(...name) {
16
19
  .join('-')
17
20
  .toLowerCase());
18
21
  }
19
- exports.genName = genName;
20
22
  /**
21
23
  * Generates an ID by joining the provided strings with a hyphen.
22
24
  * The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
@@ -26,17 +28,15 @@ exports.genName = genName;
26
28
  function genId(...name) {
27
29
  return toProperCase(genName(...name));
28
30
  }
29
- exports.genId = genId;
30
31
  /**
31
32
  * Generates a resource name for a stack by joining the stack name, resource, and stage with a hyphen.
32
33
  * @param {...} resource - The resource.
33
34
  * @returns The generated resource name.
34
35
  */
35
36
  function genStackResourceName(...resource) {
36
- const stack = (0, create_stack_1.getCurrentStack)();
37
+ const stack = (0, current_stack_1.getCurrentStack)();
37
38
  return genName(stack.name, ...resource, stack.stage);
38
39
  }
39
- exports.genStackResourceName = genStackResourceName;
40
40
  /**
41
41
  * Generates a resource ID for a stack by joining the stack name, stage, and resource.
42
42
  * The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
@@ -44,10 +44,9 @@ exports.genStackResourceName = genStackResourceName;
44
44
  * @returns The generated resource ID.
45
45
  */
46
46
  function genStackResourceId(...resource) {
47
- const stack = (0, create_stack_1.getCurrentStack)();
47
+ const stack = (0, current_stack_1.getCurrentStack)();
48
48
  return genId(stack.name, ...resource, stack.stage);
49
49
  }
50
- exports.genStackResourceId = genStackResourceId;
51
50
  function removeSpecialCharacters(name) {
52
51
  return name.replace(/[_/\\]/g, '-');
53
52
  }
@@ -0,0 +1,5 @@
1
+ export { createStack, StackArguments } from './create-stack';
2
+ export { getCurrentStack } from './current-stack';
3
+ export { DeployStack } from './DeployStack';
4
+ export { genId, genName, genStackResourceId, genStackResourceName } from './generate-identifier';
5
+ export { output } from './output';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.output = exports.genStackResourceName = exports.genStackResourceId = exports.genName = exports.genId = exports.getCurrentStack = exports.createStack = void 0;
4
+ var create_stack_1 = require("./create-stack");
5
+ Object.defineProperty(exports, "createStack", { enumerable: true, get: function () { return create_stack_1.createStack; } });
6
+ var current_stack_1 = require("./current-stack");
7
+ Object.defineProperty(exports, "getCurrentStack", { enumerable: true, get: function () { return current_stack_1.getCurrentStack; } });
8
+ var generate_identifier_1 = require("./generate-identifier");
9
+ Object.defineProperty(exports, "genId", { enumerable: true, get: function () { return generate_identifier_1.genId; } });
10
+ Object.defineProperty(exports, "genName", { enumerable: true, get: function () { return generate_identifier_1.genName; } });
11
+ Object.defineProperty(exports, "genStackResourceId", { enumerable: true, get: function () { return generate_identifier_1.genStackResourceId; } });
12
+ Object.defineProperty(exports, "genStackResourceName", { enumerable: true, get: function () { return generate_identifier_1.genStackResourceName; } });
13
+ var output_1 = require("./output");
14
+ Object.defineProperty(exports, "output", { enumerable: true, get: function () { return output_1.output; } });
@@ -0,0 +1,2 @@
1
+ import { CfnOutput } from 'aws-cdk-lib/core';
2
+ export declare function output(name: string, value: string): CfnOutput;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.output = output;
4
+ const core_1 = require("aws-cdk-lib/core");
5
+ const generate_identifier_1 = require("./generate-identifier");
6
+ const current_stack_1 = require("./current-stack");
7
+ function output(name, value) {
8
+ return new core_1.CfnOutput((0, current_stack_1.getCurrentStack)().stack, (0, generate_identifier_1.genId)(name, 'output'), {
9
+ value,
10
+ exportName: (0, generate_identifier_1.genName)(name)
11
+ });
12
+ }
@@ -0,0 +1,16 @@
1
+ import { Distribution, type ErrorResponse } from "aws-cdk-lib/aws-cloudfront";
2
+ import type { Bucket } from "aws-cdk-lib/aws-s3";
3
+ import type { CertificateDetails } from "../route53";
4
+ export interface CouldFrontDistributionConfig {
5
+ s3BucketSource: Bucket;
6
+ errorResponses?: ErrorResponse[];
7
+ shouldCache?: boolean;
8
+ certificate: CertificateDetails;
9
+ webAclId?: string;
10
+ }
11
+ /**
12
+ * Initializes a CloudFront distribution with common properties needed by your average static SPA site.
13
+ * @param id - The identifier for the distribution which will be used to compute the ids of all resources created to support it.
14
+ * @param config - The pieces of the distribution that can/should be customized for a specific use case.
15
+ */
16
+ export declare function createDistribution(id: string, config: CouldFrontDistributionConfig): Distribution;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDistribution = createDistribution;
4
+ const aws_cloudfront_1 = require("aws-cdk-lib/aws-cloudfront");
5
+ const aws_cloudfront_origins_1 = require("aws-cdk-lib/aws-cloudfront-origins");
6
+ const cloud_formation_1 = require("../cloud-formation");
7
+ const aws_iam_1 = require("aws-cdk-lib/aws-iam");
8
+ /**
9
+ * Initializes a CloudFront distribution with common properties needed by your average static SPA site.
10
+ * @param id - The identifier for the distribution which will be used to compute the ids of all resources created to support it.
11
+ * @param config - The pieces of the distribution that can/should be customized for a specific use case.
12
+ */
13
+ function createDistribution(id, config) {
14
+ const distro = new aws_cloudfront_1.Distribution((0, cloud_formation_1.getCurrentStack)().stack, (0, cloud_formation_1.genId)(id, 'distribution'), {
15
+ enabled: true,
16
+ defaultRootObject: 'index.html',
17
+ errorResponses: config.errorResponses,
18
+ defaultBehavior: {
19
+ origin: aws_cloudfront_origins_1.S3BucketOrigin.withOriginAccessControl(config.s3BucketSource, {
20
+ originAccessLevels: [aws_cloudfront_1.AccessLevel.READ]
21
+ }),
22
+ allowedMethods: aws_cloudfront_1.AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
23
+ viewerProtocolPolicy: aws_cloudfront_1.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
24
+ cachePolicy: config.shouldCache ? aws_cloudfront_1.CachePolicy.CACHING_OPTIMIZED : aws_cloudfront_1.CachePolicy.CACHING_DISABLED
25
+ },
26
+ certificate: config.certificate.certificate,
27
+ domainNames: [config.certificate.domain],
28
+ webAclId: config.webAclId
29
+ });
30
+ config.s3BucketSource.addToResourcePolicy(new aws_iam_1.PolicyStatement({
31
+ effect: aws_iam_1.Effect.ALLOW,
32
+ principals: [new aws_iam_1.ServicePrincipal('cloudfront.amazonaws.com')],
33
+ resources: [config.s3BucketSource.bucketArn, config.s3BucketSource.bucketArn + '/*'],
34
+ actions: ['s3:GetObject*', 's3:GetBucket*', 's3:List*'],
35
+ conditions: {
36
+ StringEquals: {
37
+ 'AWS:SourceArn': `arn:aws:cloudfront::${(0, cloud_formation_1.getCurrentStack)().stack.account}:distribution/${distro.distributionId}`
38
+ }
39
+ }
40
+ }));
41
+ (0, cloud_formation_1.output)(`${id}-base-url`, "https://" + config.certificate.domain);
42
+ return distro;
43
+ }
@@ -0,0 +1 @@
1
+ export { createDistribution } from './distribution';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDistribution = void 0;
4
+ var distribution_1 = require("./distribution");
5
+ Object.defineProperty(exports, "createDistribution", { enumerable: true, get: function () { return distribution_1.createDistribution; } });
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLogGroup = void 0;
3
+ exports.createLogGroup = createLogGroup;
4
4
  const aws_logs_1 = require("aws-cdk-lib/aws-logs");
5
- const generate_identifier_1 = require("../generate-identifier");
6
- const create_stack_1 = require("../create-stack");
5
+ const cloud_formation_1 = require("../cloud-formation");
7
6
  /**
8
7
  * Initializes a new function
9
8
  * @param id - The name of the resource sending logs to this log group
@@ -12,11 +11,10 @@ const create_stack_1 = require("../create-stack");
12
11
  */
13
12
  function createLogGroup(id, type, options) {
14
13
  const category = options?.category ?? 'aws';
15
- const { stack } = (0, create_stack_1.getCurrentStack)();
14
+ const { stack } = (0, cloud_formation_1.getCurrentStack)();
16
15
  const logGroupName = `/${category}/${type}/${id}`;
17
- return new aws_logs_1.LogGroup(stack, (0, generate_identifier_1.genStackResourceId)(id, 'log-group'), {
16
+ return new aws_logs_1.LogGroup(stack, (0, cloud_formation_1.genStackResourceId)(id, 'log-group'), {
18
17
  logGroupName,
19
18
  retention: options?.retention ?? aws_logs_1.RetentionDays.ONE_WEEK
20
19
  });
21
20
  }
22
- exports.createLogGroup = createLogGroup;
@@ -0,0 +1 @@
1
+ export { createLogGroup } from './create-log-group';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLogGroup = void 0;
4
+ var create_log_group_1 = require("./create-log-group");
5
+ Object.defineProperty(exports, "createLogGroup", { enumerable: true, get: function () { return create_log_group_1.createLogGroup; } });
@@ -0,0 +1,2 @@
1
+ import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
2
+ export declare const setLogRetention: (logGroup: LogGroup, retention: RetentionDays) => void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setLogRetention = void 0;
4
+ const cloud_formation_1 = require("../cloud-formation");
5
+ const aws_logs_1 = require("aws-cdk-lib/aws-logs");
6
+ const core_1 = require("aws-cdk-lib/core");
7
+ const setLogRetention = (logGroup, retention) => {
8
+ new aws_logs_1.LogRetention((0, cloud_formation_1.getCurrentStack)().stack, (0, cloud_formation_1.genStackResourceId)(logGroup.logGroupName, 'retention'), {
9
+ logGroupName: logGroup.logGroupName,
10
+ retention,
11
+ removalPolicy: core_1.RemovalPolicy.DESTROY
12
+ });
13
+ };
14
+ exports.setLogRetention = setLogRetention;
package/lib/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- export { buildNodeSource } from './build/nodejs/build-node-source';
2
- export { buildEcmaScript } from './build/nodejs/build-ecmascript';
3
- export { buildTypeScript } from './build/nodejs/build-typescript';
4
- export { createNodeJsLambda } from './lambda/create-nodejs-lambda';
5
- export { createStack, StackArguments, getCurrentStack } from './create-stack';
6
- export { StackConfiguration } from './load-configuration';
7
- export { genName, genId, genStackResourceName, genStackResourceId } from './generate-identifier';
8
- export * as ssm from "./ssm";
1
+ export * from "./build";
2
+ export * from "./cloud-formation";
3
+ export * from "./cloud-front";
4
+ export * from "./cloud-watch";
5
+ export * from "./lambda";
6
+ export * from "./lambda-layer";
7
+ export * from "./recipes";
8
+ export * from "./route53";
9
+ export * from "./s3";
10
+ export * from "./ssm";
11
+ export * from './tools';
package/lib/index.js CHANGED
@@ -10,34 +10,18 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
15
  };
25
16
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ssm = exports.genStackResourceId = exports.genStackResourceName = exports.genId = exports.genName = exports.getCurrentStack = exports.createStack = exports.createNodeJsLambda = exports.buildTypeScript = exports.buildEcmaScript = exports.buildNodeSource = void 0;
27
- var build_node_source_1 = require("./build/nodejs/build-node-source");
28
- Object.defineProperty(exports, "buildNodeSource", { enumerable: true, get: function () { return build_node_source_1.buildNodeSource; } });
29
- var build_ecmascript_1 = require("./build/nodejs/build-ecmascript");
30
- Object.defineProperty(exports, "buildEcmaScript", { enumerable: true, get: function () { return build_ecmascript_1.buildEcmaScript; } });
31
- var build_typescript_1 = require("./build/nodejs/build-typescript");
32
- Object.defineProperty(exports, "buildTypeScript", { enumerable: true, get: function () { return build_typescript_1.buildTypeScript; } });
33
- var create_nodejs_lambda_1 = require("./lambda/create-nodejs-lambda");
34
- Object.defineProperty(exports, "createNodeJsLambda", { enumerable: true, get: function () { return create_nodejs_lambda_1.createNodeJsLambda; } });
35
- var create_stack_1 = require("./create-stack");
36
- Object.defineProperty(exports, "createStack", { enumerable: true, get: function () { return create_stack_1.createStack; } });
37
- Object.defineProperty(exports, "getCurrentStack", { enumerable: true, get: function () { return create_stack_1.getCurrentStack; } });
38
- var generate_identifier_1 = require("./generate-identifier");
39
- Object.defineProperty(exports, "genName", { enumerable: true, get: function () { return generate_identifier_1.genName; } });
40
- Object.defineProperty(exports, "genId", { enumerable: true, get: function () { return generate_identifier_1.genId; } });
41
- Object.defineProperty(exports, "genStackResourceName", { enumerable: true, get: function () { return generate_identifier_1.genStackResourceName; } });
42
- Object.defineProperty(exports, "genStackResourceId", { enumerable: true, get: function () { return generate_identifier_1.genStackResourceId; } });
43
- exports.ssm = __importStar(require("./ssm"));
17
+ __exportStar(require("./build"), exports);
18
+ __exportStar(require("./cloud-formation"), exports);
19
+ __exportStar(require("./cloud-front"), exports);
20
+ __exportStar(require("./cloud-watch"), exports);
21
+ __exportStar(require("./lambda"), exports);
22
+ __exportStar(require("./lambda-layer"), exports);
23
+ __exportStar(require("./recipes"), exports);
24
+ __exportStar(require("./route53"), exports);
25
+ __exportStar(require("./s3"), exports);
26
+ __exportStar(require("./ssm"), exports);
27
+ __exportStar(require("./tools"), exports);
@@ -1,11 +1,12 @@
1
+ import { Duration } from "aws-cdk-lib/core";
1
2
  import { Function as Lambda, FunctionProps } from "aws-cdk-lib/aws-lambda";
2
- import { Duration } from "aws-cdk-lib";
3
3
  import { LogGroup } from "aws-cdk-lib/aws-logs";
4
+ type FunctionPropsWithDefaults = Partial<FunctionProps> & Pick<FunctionProps, 'code' | 'handler'>;
4
5
  /**
5
6
  * Interface for the properties of the FunctionIntegration class.
6
7
  */
7
8
  export interface FunctionIntegrationProps {
8
- funcProps?: FunctionProps;
9
+ funcProps?: FunctionPropsWithDefaults;
9
10
  timeout?: Duration;
10
11
  memory?: number;
11
12
  }
@@ -20,3 +21,4 @@ export interface FunctionIntegration {
20
21
  * @param {FunctionIntegrationProps} options - The properties of the function.
21
22
  */
22
23
  export declare function createFunction(id: string, options: FunctionIntegrationProps): FunctionIntegration;
24
+ export {};
@@ -1,45 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createFunction = void 0;
3
+ exports.createFunction = createFunction;
4
+ const core_1 = require("aws-cdk-lib/core");
4
5
  const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
5
- const aws_cdk_lib_1 = require("aws-cdk-lib");
6
- const apply_honeycomb_to_lambda_1 = require("../lambda-layer/apply-honeycomb-to-lambda");
7
6
  const aws_logs_1 = require("aws-cdk-lib/aws-logs");
8
- const generate_identifier_1 = require("../generate-identifier");
9
- const create_stack_1 = require("../create-stack");
10
- const core_1 = require("aws-cdk-lib/core");
11
- const create_log_group_1 = require("../cloud-watch/create-log-group");
7
+ const lambda_layer_1 = require("../lambda-layer");
8
+ const cloud_formation_1 = require("../cloud-formation");
9
+ const cloud_watch_1 = require("../cloud-watch");
10
+ const set_log_retention_1 = require("../cloud-watch/set-log-retention");
12
11
  /**
13
12
  * Initializes a new function
14
13
  * @param {string} id - The ID of the function.
15
14
  * @param {FunctionIntegrationProps} options - The properties of the function.
16
15
  */
17
16
  function createFunction(id, options) {
18
- const props = (0, apply_honeycomb_to_lambda_1.applyHoneycombToLambda)({
19
- functionName: (0, generate_identifier_1.genStackResourceName)(id),
17
+ const props = (0, lambda_layer_1.applyHoneycombToLambda)({
18
+ functionName: (0, cloud_formation_1.genStackResourceName)(id),
20
19
  memorySize: options.memory || 256,
21
- timeout: options.timeout || aws_cdk_lib_1.Duration.seconds(30),
20
+ timeout: options.timeout || core_1.Duration.seconds(30),
21
+ runtime: aws_lambda_1.Runtime.NODEJS_LATEST,
22
22
  ...(options.funcProps || {})
23
23
  });
24
- const { stack } = (0, create_stack_1.getCurrentStack)();
25
- const logGroup = (0, create_log_group_1.createLogGroup)(id, 'lambda');
24
+ const { stack } = (0, cloud_formation_1.getCurrentStack)();
25
+ const logGroup = (0, cloud_watch_1.createLogGroup)(id, 'lambda');
26
+ (0, set_log_retention_1.setLogRetention)(logGroup, aws_logs_1.RetentionDays.ONE_WEEK);
26
27
  const details = {
27
28
  id,
28
29
  logGroup,
29
- lambda: new aws_lambda_1.Function(stack, (0, generate_identifier_1.genStackResourceId)(id, 'lambda'), {
30
+ lambda: new aws_lambda_1.Function(stack, (0, cloud_formation_1.genStackResourceId)(id, 'lambda'), {
30
31
  ...props,
31
32
  logGroup
32
33
  })
33
34
  };
34
- new aws_cdk_lib_1.CfnOutput(stack, (0, generate_identifier_1.genStackResourceId)(id, 'function-name'), {
35
- value: details.lambda.functionName,
36
- exportName: (0, generate_identifier_1.genStackResourceName)(id, 'function-name')
37
- });
38
- new aws_logs_1.LogRetention(stack, (0, generate_identifier_1.genStackResourceId)(id, 'log-retention'), {
39
- logGroupName: logGroup.logGroupName,
40
- retention: aws_logs_1.RetentionDays.ONE_WEEK,
41
- removalPolicy: core_1.RemovalPolicy.DESTROY
42
- });
35
+ (0, cloud_formation_1.output)((0, cloud_formation_1.genId)(id, 'function-name'), details.lambda.functionName);
43
36
  return details;
44
37
  }
45
- exports.createFunction = createFunction;
@@ -1,6 +1,6 @@
1
1
  import { FunctionOptions } from "aws-cdk-lib/aws-lambda";
2
2
  import { FunctionIntegration } from "./create-function";
3
- import { Duration } from "aws-cdk-lib";
3
+ import { Duration } from "aws-cdk-lib/core";
4
4
  /**
5
5
  * Interface for the properties of a Node.js function.
6
6
  */
@@ -8,7 +8,7 @@ interface NodeFunctionProps {
8
8
  /**
9
9
  * The properties of the function.
10
10
  */
11
- funcProps?: FunctionOptions;
11
+ funcProps?: Partial<FunctionOptions>;
12
12
  /**
13
13
  * The timeout duration for the function.
14
14
  */
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createNodeJsLambda = void 0;
6
+ exports.createNodeJsLambda = createNodeJsLambda;
7
7
  const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
8
8
  const create_function_1 = require("./create-function");
9
- const build_node_source_1 = require("../build/nodejs/build-node-source");
9
+ const build_1 = require("../build");
10
10
  const duration_1 = __importDefault(require("../tools/duration"));
11
11
  /**
12
12
  * Creates a new Node.js AWS Lambda function.
@@ -19,7 +19,7 @@ function createNodeJsLambda(id, options) {
19
19
  // Measure the duration of the build process
20
20
  const done = (0, duration_1.default)();
21
21
  // Build the Node.js source code
22
- const buildDir = (0, build_node_source_1.buildNodeSource)('lambda', id);
22
+ const buildDir = (0, build_1.buildNodeSource)('lambda', id);
23
23
  console.log('Total Build Duration (ms)', done());
24
24
  // Call the parent constructor with the function properties
25
25
  return (0, create_function_1.createFunction)(id, {
@@ -35,4 +35,3 @@ function createNodeJsLambda(id, options) {
35
35
  }
36
36
  });
37
37
  }
38
- exports.createNodeJsLambda = createNodeJsLambda;
@@ -0,0 +1 @@
1
+ export { createNodeJsLambda } from './create-nodejs-lambda';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodeJsLambda = void 0;
4
+ var create_nodejs_lambda_1 = require("./create-nodejs-lambda");
5
+ Object.defineProperty(exports, "createNodeJsLambda", { enumerable: true, get: function () { return create_nodejs_lambda_1.createNodeJsLambda; } });
@@ -1,2 +1,2 @@
1
- import { FunctionProps } from "aws-cdk-lib/aws-lambda";
1
+ import type { FunctionProps } from "aws-cdk-lib/aws-lambda";
2
2
  export declare function applyHoneycombToLambda(props: FunctionProps): FunctionProps;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyHoneycombToLambda = void 0;
3
+ exports.applyHoneycombToLambda = applyHoneycombToLambda;
4
4
  const ssm_1 = require("../ssm");
5
- const create_stack_1 = require("../create-stack");
5
+ const cloud_formation_1 = require("../cloud-formation");
6
6
  const get_layer_1 = require("./get-layer");
7
7
  function applyHoneycombToLambda(props) {
8
- const { stack } = (0, create_stack_1.getCurrentStack)();
8
+ const { stack } = (0, cloud_formation_1.getCurrentStack)();
9
9
  const honeyCombLayer = (0, get_layer_1.getLayer)('hc-layer', `arn:aws:lambda:${stack.region}:702835727665:layer:honeycomb-lambda-extension-x86_64-v11-1-1:1`);
10
10
  const layers = props.layers ? [...props.layers] : [];
11
11
  const environment = { ...props.environment };
12
12
  const options = {
13
- parameterGroup: (0, create_stack_1.getCurrentStack)().project
13
+ parameterGroup: (0, cloud_formation_1.getCurrentStack)().project
14
14
  };
15
15
  layers.push(honeyCombLayer);
16
16
  environment.LIBHONEY_API_KEY = (0, ssm_1.stringValue)(`/honeycomb/api-key`, options);
@@ -22,4 +22,3 @@ function applyHoneycombToLambda(props) {
22
22
  environment
23
23
  };
24
24
  }
25
- exports.applyHoneycombToLambda = applyHoneycombToLambda;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLayer = void 0;
3
+ exports.getLayer = getLayer;
4
4
  const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
5
- const create_stack_1 = require("../create-stack");
5
+ const cloud_formation_1 = require("../cloud-formation");
6
6
  const layer_cache_1 = require("./layer-cache");
7
- const generate_identifier_1 = require("../generate-identifier");
8
7
  function getLayer(name, arn) {
9
8
  let layer = (0, layer_cache_1.get)(arn);
10
9
  if (!layer) {
@@ -13,8 +12,7 @@ function getLayer(name, arn) {
13
12
  }
14
13
  return layer;
15
14
  }
16
- exports.getLayer = getLayer;
17
15
  function createLayer(name, arn) {
18
- const { stack } = (0, create_stack_1.getCurrentStack)();
19
- return aws_lambda_1.LayerVersion.fromLayerVersionArn(stack, (0, generate_identifier_1.genStackResourceId)(name), arn);
16
+ const { stack } = (0, cloud_formation_1.getCurrentStack)();
17
+ return aws_lambda_1.LayerVersion.fromLayerVersionArn(stack, (0, cloud_formation_1.genStackResourceId)(name), arn);
20
18
  }
@@ -0,0 +1,2 @@
1
+ export { applyHoneycombToLambda } from './apply-honeycomb-to-lambda';
2
+ export { getLayer } from './get-layer';