@byaga/cdk-patterns 0.8.5 → 0.9.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.
@@ -10,7 +10,9 @@ export declare class DeployStack extends Stack {
10
10
  stage: string;
11
11
  name: string;
12
12
  genName(...name: string[]): string;
13
+ genStackName(stackName: string, ...name: string[]): string;
13
14
  genId(...name: string[]): string;
15
+ genStackId(stackName: string, ...name: string[]): string;
14
16
  static genStackResourceName(stackName: string, resource: string, stage?: string): string;
15
17
  static genStackResourceId(stackName: string, resource: string, stage?: string): string;
16
18
  constructor(scope: IConstruct, props: IStackArguments);
@@ -7,19 +7,25 @@ class DeployStack extends aws_cdk_lib_1.Stack {
7
7
  stage;
8
8
  name;
9
9
  genName(...name) {
10
- return DeployStack.genStackResourceName(this.name, this.stage, name.filter(n => !!n).join('-'));
10
+ return DeployStack.genStackResourceName(this.name, name.filter(n => !!n).join('-'), this.stage);
11
+ }
12
+ genStackName(stackName, ...name) {
13
+ return DeployStack.genStackResourceName(stackName, name.filter(n => !!n).join('-'), this.stage);
11
14
  }
12
15
  genId(...name) {
13
- return DeployStack.genStackResourceId(this.name, this.stage, name.filter(n => !!n).join('-'));
16
+ return DeployStack.genStackResourceId(this.name, name.filter(n => !!n).join('-'), this.stage);
17
+ }
18
+ genStackId(stackName, ...name) {
19
+ return DeployStack.genStackResourceId(stackName, name.filter(n => !!n).join('-'), this.stage);
14
20
  }
15
21
  static genStackResourceName(stackName, resource, stage = 'develop') {
16
- let name = stackName[0].toLowerCase() + stackName.substr(1);
22
+ let name = stackName[0].toLowerCase() + stackName.substring(1);
17
23
  name = name.replace(/[A-Z]/g, v => '-' + v.toLowerCase());
18
- return `${name}-${resource}-${stage}`.toLowerCase();
24
+ return `${name}-${stage}-${resource}`.toLowerCase();
19
25
  }
20
26
  static genStackResourceId(stackName, resource, stage = 'develop') {
21
- const constructName = `${stackName}-${resource}-${stage}`;
22
- return constructName[0].toUpperCase() + constructName.substr(1).replace(/-./g, v => (v[1] || '').toUpperCase());
27
+ const constructName = `${stackName}-${stage}-${resource}`;
28
+ return constructName[0].toUpperCase() + constructName.substring(1).replace(/-./g, v => (v[1] || '').toUpperCase());
23
29
  }
24
30
  constructor(scope, props) {
25
31
  const options = (props || {});
@@ -1,12 +1,17 @@
1
1
  /// <reference types="node" />
2
2
  import { DeployStack } from "./DeployStack";
3
+ import { SourceConfiguration } from "aws-cdk-lib/aws-cloudfront";
3
4
  import IDomainConfig from "./IDomainConfig";
5
+ import { IIgnoreOptions } from "./methods/walk-directory";
4
6
  interface StaticWebSiteConfig {
5
7
  srcDir?: string;
6
8
  domain: IDomainConfig;
7
9
  env: NodeJS.ProcessEnv;
10
+ ignore?: IIgnoreOptions;
11
+ proxy?: SourceConfiguration[];
8
12
  }
9
13
  export declare class StaticWebSite {
10
14
  constructor(stack: DeployStack, id: string, props: StaticWebSiteConfig);
15
+ static defineProxy(stack: DeployStack, domainName: string, pathPattern: string): SourceConfiguration;
11
16
  }
12
17
  export {};
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
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;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
@@ -30,8 +7,6 @@ exports.StaticWebSite = void 0;
30
7
  const core_1 = require("aws-cdk-lib/core");
31
8
  const Output_1 = require("./Output");
32
9
  const child_process_1 = require("child_process");
33
- const fs = __importStar(require("fs-extra"));
34
- const path = __importStar(require("path"));
35
10
  const aws_s3_1 = require("aws-cdk-lib/aws-s3");
36
11
  const aws_s3_deployment_1 = require("aws-cdk-lib/aws-s3-deployment");
37
12
  const ApiCertificate_1 = __importDefault(require("./ApiCertificate"));
@@ -39,21 +14,30 @@ const aws_cloudfront_1 = require("aws-cdk-lib/aws-cloudfront");
39
14
  const aws_iam_1 = require("aws-cdk-lib/aws-iam");
40
15
  const aws_route53_1 = require("aws-cdk-lib/aws-route53");
41
16
  const aws_route53_targets_1 = require("aws-cdk-lib/aws-route53-targets");
17
+ const duration_1 = __importDefault(require("./methods/duration"));
18
+ const build_node_source_1 = require("./methods/build-node-source");
19
+ const walk_directory_1 = require("./methods/walk-directory");
20
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
42
21
  class StaticWebSite {
43
22
  constructor(stack, id, props) {
44
23
  console.log('Deploying Static Web Site', id);
45
- const srcDir = path.resolve("../src/", props.srcDir || '');
46
- const buildDir = path.resolve("../dist/", props.srcDir || '');
47
- console.log('Installing Prod Dependencies', id);
48
- (0, child_process_1.execSync)('npm i --production --quiet', {
49
- cwd: srcDir
24
+ const done = (0, duration_1.default)();
25
+ const childrenExcluded = props.ignore?.childrenExcluded || walk_directory_1.no;
26
+ const { buildDir, moduleChanged } = (0, build_node_source_1.buildNodeSource)('web', id, {
27
+ ignore: {
28
+ ...props.ignore,
29
+ childrenExcluded: stat => stat.name === 'out' || childrenExcluded(stat)
30
+ }
50
31
  });
51
- console.log('Building UI Source', id);
52
- (0, child_process_1.execSync)('npm run export', {
53
- cwd: srcDir,
54
- //env: props.env
55
- });
56
- fs.copySync(path.resolve(srcDir, "./out"), buildDir);
32
+ if (moduleChanged) {
33
+ console.log('Building UI Source', id);
34
+ (0, child_process_1.execSync)('npm run export', {
35
+ cwd: buildDir,
36
+ env: props.env
37
+ });
38
+ }
39
+ console.log('Total Build Duration (ms)', done());
40
+ const exportDir = buildDir + '/out';
57
41
  console.log('Creating HTTPS Certificate', id + '-certificate');
58
42
  const certificate = new ApiCertificate_1.default(stack, id + '-certificate', props.domain);
59
43
  console.log('Deploying Site Content Bucket', stack.genId(id, "content-bucket"));
@@ -61,7 +45,6 @@ class StaticWebSite {
61
45
  bucketName: certificate.domain,
62
46
  websiteIndexDocument: "index.html",
63
47
  websiteErrorDocument: "error.html",
64
- publicReadAccess: true,
65
48
  removalPolicy: core_1.RemovalPolicy.DESTROY,
66
49
  autoDeleteObjects: true
67
50
  });
@@ -71,15 +54,15 @@ class StaticWebSite {
71
54
  resources: [s3BucketSource.bucketArn, s3BucketSource.bucketArn + '/*'],
72
55
  });
73
56
  new aws_s3_deployment_1.BucketDeployment(stack, stack.genId(id, 'bucket-deployment'), {
74
- sources: [aws_s3_deployment_1.Source.asset(buildDir)],
57
+ sources: [aws_s3_deployment_1.Source.asset(exportDir)],
75
58
  destinationBucket: s3BucketSource
76
59
  });
77
60
  const originAccessIdentity = new aws_cloudfront_1.OriginAccessIdentity(stack, "WebsiteOAI");
78
61
  cloudFrontPolicy.addArnPrincipal(originAccessIdentity.cloudFrontOriginAccessIdentityS3CanonicalUserId);
62
+ s3BucketSource.grantRead(originAccessIdentity);
79
63
  const distro = new aws_cloudfront_1.CloudFrontWebDistribution(stack, stack.genId(id, 'cloudfront-web-distribution'), {
80
64
  enabled: true,
81
- //priceClass:
82
- originConfigs: [{
65
+ originConfigs: [...props.proxy || [], {
83
66
  s3OriginSource: {
84
67
  s3BucketSource,
85
68
  originAccessIdentity
@@ -103,5 +86,41 @@ class StaticWebSite {
103
86
  target: aws_route53_1.RecordTarget.fromAlias(new aws_route53_targets_1.CloudFrontTarget(distro))
104
87
  });
105
88
  }
89
+ static defineProxy(stack, domainName, pathPattern) {
90
+ return {
91
+ customOriginSource: {
92
+ domainName: domainName,
93
+ originPath: stack.stage,
94
+ originProtocolPolicy: aws_cloudfront_1.OriginProtocolPolicy.HTTPS_ONLY
95
+ },
96
+ behaviors: [{
97
+ pathPattern,
98
+ allowedMethods: aws_cloudfront_1.CloudFrontAllowedMethods.ALL,
99
+ maxTtl: aws_cdk_lib_1.Duration.seconds(0),
100
+ minTtl: aws_cdk_lib_1.Duration.seconds(0),
101
+ defaultTtl: aws_cdk_lib_1.Duration.seconds(0),
102
+ compress: false,
103
+ forwardedValues: {
104
+ queryString: true,
105
+ headers: [
106
+ "Authorization",
107
+ "User-Agent",
108
+ "X-Trace-Id",
109
+ "X-Span-Id",
110
+ "X-Correlation-Id",
111
+ 'Referrer',
112
+ 'Referer',
113
+ 'Host',
114
+ "User-Agent",
115
+ "Accept-Language",
116
+ "Cache-Control",
117
+ 'X-Viewer-Country',
118
+ 'Content-Type',
119
+ 'Content-Length'
120
+ ]
121
+ }
122
+ }]
123
+ };
124
+ }
106
125
  }
107
126
  exports.StaticWebSite = StaticWebSite;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byaga/cdk-patterns",
3
- "version": "0.8.5",
3
+ "version": "0.9.0",
4
4
  "description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "fs-extra": "^11.1.1"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/node": "^20.8.9",
25
+ "@types/node": "^20.8.10",
26
26
  "typescript": "^5.2.2"
27
27
  }
28
28
  }
package/.fleet/run.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "configurations": [
3
- {
4
- "type": "npm",
5
- "name": "cdk-patterns build",
6
- "command": "run",
7
- "scripts": "build",
8
- },
9
-
10
- ]
11
- }
@@ -1,32 +0,0 @@
1
- import {Certificate, CertificateValidation} from "aws-cdk-lib/aws-certificatemanager";
2
- import {HostedZone, IHostedZone} from "aws-cdk-lib/aws-route53";
3
- import {Output} from "./Output";
4
- import DeployStack from "./DeployStack";
5
- import IDomainConfig from "./IDomainConfig";
6
-
7
- export class ApiCertificate extends Certificate {
8
- hostedZone: IHostedZone
9
- domain: string
10
-
11
- constructor(stack: DeployStack, id: string, domain: IDomainConfig) {
12
- const certDomain = [domain.domainName]
13
- if (domain.subdomain) certDomain.splice(0, 0, domain.subdomain)
14
- const domainName = certDomain.join('.')
15
-
16
- console.log('Getting Hosted Zone', domain.hostedZone.name)
17
- const hostedZone: IHostedZone = HostedZone.fromHostedZoneAttributes(stack, stack.genId(id, 'hosted-zone'), {
18
- hostedZoneId: domain.hostedZone.id,
19
- zoneName: domain.hostedZone.name
20
- })
21
- console.log('Defining Certificate For', domainName)
22
- super(stack, stack.genId(id), {
23
- domainName,
24
- validation: CertificateValidation.fromDns(hostedZone)
25
- });
26
-
27
- this.domain = domainName
28
- new Output(stack, id, this.certificateArn)
29
- this.hostedZone = hostedZone
30
- }
31
- }
32
- export default ApiCertificate
@@ -1,25 +0,0 @@
1
- import { Construct } from 'constructs'
2
- import { CfnAuthorizer, IAuthorizer } from 'aws-cdk-lib/aws-apigateway'
3
- import { CfnAuthorizerProps } from 'aws-cdk-lib/aws-apigateway/lib/apigateway.generated'
4
-
5
- /**
6
- * Custom construct that implements a Cognito based API Gateway Authorizer.
7
- *
8
- * @see https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_author
9
- *
10
- * @see https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.CfnAuthorizer.html
11
- * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-authorizer.html
12
- * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html
13
- * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html
14
- *
15
- * @see https://github.com/aws/aws-cdk/issues/5618#issuecomment-666922559
16
- */
17
- export class CognitoApiGatewayAuthorizer extends CfnAuthorizer implements IAuthorizer {
18
- public readonly authorizerId: string
19
-
20
- constructor(scope: Construct, id: string, props: CfnAuthorizerProps) {
21
- super(scope, id, props)
22
-
23
- this.authorizerId = this.ref
24
- }
25
- }
@@ -1,56 +0,0 @@
1
- import {Stack} from 'aws-cdk-lib';
2
- import IStackArguments from './IStackArguments'
3
- import {IConstruct} from "constructs";
4
-
5
- export class DeployStack extends Stack {
6
- registry: { [t: string]: { [n: string]: any } } = {}
7
- stage: string
8
- name: string
9
-
10
- genName(...name: string[]): string {
11
- return DeployStack.genStackResourceName(this.name, this.stage, name.filter(n => !!n).join('-'))
12
- }
13
-
14
- genId(...name: string[]): string {
15
- return DeployStack.genStackResourceId(this.name, this.stage, name.filter(n => !!n).join('-'))
16
- }
17
-
18
- static genStackResourceName(stackName: string, resource: string, stage = 'develop') {
19
- let name = stackName[0].toLowerCase() + stackName.substr(1)
20
- name = name.replace(/[A-Z]/g, v => '-' + v.toLowerCase())
21
- return `${name}-${resource}-${stage}`.toLowerCase()
22
- }
23
-
24
- static genStackResourceId(stackName: string, resource: string, stage = 'develop') {
25
- const constructName = `${stackName}-${resource}-${stage}`
26
- return constructName[0].toUpperCase() + constructName.substr(1).replace(/-./g, v => (v[1] || '').toUpperCase())
27
- }
28
-
29
- constructor(scope: IConstruct, props: IStackArguments) {
30
- const options = (props || {}) as IStackArguments
31
- const {stage = 'develop'} = options
32
- super(scope, props.stackName + '-' + stage, {
33
- ...props,
34
- stackName: props.stackName + '-' + stage
35
- });
36
- const stack = this;
37
- stack.name = props.stackName || '';
38
-
39
- stack.stage = stage;
40
-
41
- stack.tags.setTag('Stage', stage);
42
- stack.tags.setTag('Stack', this.genName('ui-stack'));
43
- }
44
-
45
- get(type: string, name: string) {
46
- const items = this.registry[type]
47
- return (items && items[name]) || null
48
- }
49
-
50
- set(type: string, name: string, instance: any) {
51
- this.registry[type] = this.registry[type] || {};
52
- this.registry[type][name] = instance;
53
- return instance;
54
- }
55
- }
56
- export default DeployStack
@@ -1,40 +0,0 @@
1
- import {CfnOutput, RemovalPolicy} from 'aws-cdk-lib';
2
- import {Table, BillingMode, AttributeType} from 'aws-cdk-lib/aws-dynamodb'
3
- import {Effect, Policy, PolicyStatement} from "aws-cdk-lib/aws-iam";
4
- import {DeployStack} from "./DeployStack"
5
-
6
- interface DynamoDbTableConfig {
7
- partitionKey: string,
8
- sortKey?: string
9
- }
10
-
11
- export class DynamoDbTable extends Table {
12
- getPolicy: Policy
13
-
14
- constructor(stack: DeployStack, id: string, props: DynamoDbTableConfig) {
15
- console.log('Creating DynamoDb Table', stack.genName(id, 'data-table'))
16
- super(stack, stack.genId(id, 'data-table'), {
17
- tableName: stack.genName(id, 'data-table'),
18
- partitionKey: {name: props.partitionKey, type: AttributeType.STRING},
19
- sortKey: props.sortKey ? {name: props.sortKey, type: AttributeType.STRING} : undefined,
20
- billingMode: BillingMode.PAY_PER_REQUEST,
21
- removalPolicy: RemovalPolicy.DESTROY
22
- });
23
- stack.set('dynamo', id, this)
24
-
25
- new CfnOutput(stack, stack.genId(id, 'table'), {
26
- value: this.tableName,
27
- exportName: stack.genName(id, 'table')
28
- })
29
-
30
- this.getPolicy = new Policy(stack, stack.genId(id, 'get-policy'), {
31
- statements: [
32
- new PolicyStatement({
33
- actions: ['dynamodb:GetItem'],
34
- effect: Effect.ALLOW,
35
- resources: [this.tableArn]
36
- })
37
- ]
38
- })
39
- }
40
- }
@@ -1,93 +0,0 @@
1
- import {DeployStack} from "./DeployStack";
2
- import {Function, FunctionProps} from "aws-cdk-lib/aws-lambda";
3
- import {
4
- JsonSchema,
5
- LambdaIntegration,
6
- MethodOptions,
7
- Model,
8
- RequestValidator,
9
- IResource, Method
10
- } from "aws-cdk-lib/aws-apigateway";
11
- import {CfnOutput, Duration} from "aws-cdk-lib";
12
- import {applyHoneycombToLambda} from "./methods/apply-honeycomb-to-lambda";
13
- import {RetentionDays} from "aws-cdk-lib/aws-logs";
14
- import {RestApi} from "./RestApi";
15
-
16
- interface AddToApiOptions {
17
- requestSchema?: JsonSchema,
18
- methodOptions?: MethodOptions
19
- }
20
-
21
- export interface FunctionIntegrationProps {
22
- funcProps: FunctionProps,
23
- timeout?: Duration
24
- memory?: number
25
- }
26
-
27
- export class FunctionIntegration extends Function {
28
- stack: DeployStack
29
- name: string
30
-
31
- constructor(stack: DeployStack, id: string, options: FunctionIntegrationProps) {
32
- const props = applyHoneycombToLambda(stack, {
33
- functionName: stack.genName(id),
34
- memorySize: options.memory || 256,
35
- timeout: options.timeout || Duration.seconds(16),
36
- logRetention: RetentionDays.ONE_WEEK,
37
- ...options.funcProps
38
- })
39
-
40
- super(stack, stack.genId(id, 'lambda'), props);
41
- this.stack = stack;
42
- this.name = id;
43
- stack.set('lambda', id, this)
44
- new CfnOutput(stack, stack.genId(id, 'function-name'), {
45
- value: this.functionName,
46
- exportName: stack.genName(id, 'function-name')
47
- });
48
- }
49
-
50
- attach(api: RestApi, httpMethod: string, path: string, props: AddToApiOptions = {}) : ApiAttachPoint {
51
- const resource: IResource = api.path(path)
52
- const integration = new LambdaIntegration(this, {
53
- requestTemplates: {
54
- 'application/json': '{ "statusCode": "200" }'
55
- }
56
- })
57
-
58
- let options: MethodOptions = props?.methodOptions || {}
59
- const schema = props?.requestSchema
60
- if (schema) options = applySchema(this.stack, this.name, schema, options, resource)
61
-
62
- const method = resource.addMethod(httpMethod, integration, options)
63
-
64
- return {
65
- method,
66
- resourceArn: `arn:aws:execute-api:${this.stack.region}:${this.stack.account}:${api.restApiId}/${this.stack.stage}/${httpMethod}${path}`
67
- };
68
- }
69
- }
70
-
71
- function applySchema(stack: DeployStack, name: string, schema: JsonSchema, options: MethodOptions, path: IResource): MethodOptions {
72
- return {
73
- ...options,
74
- requestValidator: new RequestValidator(stack, stack.genId(name, 'validator'), {
75
- restApi: path.api,
76
- requestValidatorName: stack.genName(name, 'validator'),
77
- validateRequestBody: true
78
- }),
79
- requestModels: {
80
- 'application/json': new Model(stack, stack.genId(name, 'model'), {
81
- schema: schema,
82
- contentType: 'application/json',
83
- restApi: path.api,
84
- modelName: stack.genId(name, 'model')
85
- })
86
- }
87
- }
88
- }
89
-
90
- interface ApiAttachPoint {
91
- method: Method
92
- resourceArn: string
93
- }
@@ -1,5 +0,0 @@
1
- export interface ICorsConfig {
2
- maxAge?: number
3
- exposeHeaders?: string[],
4
- allowOrigin?: string|string[]
5
- }
@@ -1,8 +0,0 @@
1
- import IHostedZoneConfig from "./IHostedZoneConfig";
2
-
3
- export interface IDomainConfig {
4
- domainName: string,
5
- subdomain?: string,
6
- hostedZone: IHostedZoneConfig
7
- }
8
- export default IDomainConfig
@@ -1,5 +0,0 @@
1
- export interface IHostedZoneConfig {
2
- name: string,
3
- id: string
4
- }
5
- export default IHostedZoneConfig
@@ -1,8 +0,0 @@
1
- import {StackProps} from 'aws-cdk-lib/core';
2
-
3
- export interface IStackArguments extends StackProps {
4
- stage: string,
5
- project: string,
6
- owner: string
7
- }
8
- export default IStackArguments
@@ -1,31 +0,0 @@
1
- import {Code, FunctionOptions, Runtime} from "aws-cdk-lib/aws-lambda"
2
- import {DeployStack} from "./DeployStack";
3
- import {FunctionIntegration} from "./FunctionIntegration";
4
- import {buildNodeSource} from "./methods/build-node-source";
5
- import {Duration} from "aws-cdk-lib";
6
- import duration from "./methods/duration";
7
-
8
- interface NodeFunctionProps {
9
- funcProps?: FunctionOptions
10
- timeout?: Duration
11
- memory?: number
12
- }
13
-
14
- export class NodeJsLambda extends FunctionIntegration {
15
- constructor(stack: DeployStack, id: string, options?: NodeFunctionProps) {
16
- console.log('Defining Node Lambda', id)
17
- const done = duration()
18
- const {buildDir} = buildNodeSource('lambda', id)
19
- console.log('Total Build Duration (ms)', done())
20
-
21
- super(stack, id, {
22
- ...options,
23
- funcProps: {
24
- ...options?.funcProps,
25
- code: Code.fromAsset(buildDir),
26
- handler: `${id}.handler`,
27
- runtime: Runtime.NODEJS_18_X
28
- }
29
- })
30
- }
31
- }
@@ -1,27 +0,0 @@
1
- import {Code, LayerVersion, Runtime} from "aws-cdk-lib/aws-lambda";
2
- import {DeployStack} from "./DeployStack";
3
- import {LayerVersionOptions} from "aws-cdk-lib/aws-lambda/lib/layers";
4
- import {Architecture} from "aws-cdk-lib/aws-lambda/lib/architecture";
5
- import {buildNodeSource} from "./methods/build-node-source";
6
- import duration from "./methods/duration";
7
-
8
- interface NodeJsLambdaLayerProps extends LayerVersionOptions {
9
- readonly compatibleRuntimes?: Runtime[];
10
- readonly compatibleArchitectures?: Architecture[];
11
- }
12
-
13
- export class NodeJsLambdaLayer extends LayerVersion {
14
- constructor(stack: DeployStack, id: string, props: NodeJsLambdaLayerProps = {}) {
15
- console.log("Building Lambda Layer", id);
16
- const done = duration()
17
- const {buildDir} = buildNodeSource('lambda-layer', id, {dir:'nodejs'})
18
- console.log('Build Duration (ms)', done())
19
-
20
- super(stack, stack.genId(id), {
21
- ...props,
22
- layerVersionName: stack.genName(id),
23
- code: Code.fromAsset(buildDir)
24
- });
25
- stack.set('lambda-layer', id, this)
26
- }
27
- }
package/src/Output.ts DELETED
@@ -1,11 +0,0 @@
1
- import {CfnOutput} from 'aws-cdk-lib/core';
2
- import {DeployStack} from './DeployStack';
3
-
4
- export class Output extends CfnOutput {
5
- constructor(stack: DeployStack, name: string, value: string) {
6
- super(stack, stack.genId(name, 'output'), {
7
- value,
8
- exportName: stack.genName(name)
9
- })
10
- }
11
- }