@byaga/cdk-patterns 0.10.0 → 0.11.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.
- package/README.md +7 -1
- package/archive/ApiAttachPoint.ts +9 -0
- package/archive/ApiCertificate.ts +32 -0
- package/{lib/CognitoApiGatewayAuthorizer.d.ts → archive/CognitoApiGatewayAuthorizer.ts} +13 -7
- package/archive/DynamoDbTable.ts +40 -0
- package/archive/ICorsConfig.ts +5 -0
- package/archive/IDomainConfig.ts +8 -0
- package/archive/IHostedZoneConfig.ts +5 -0
- package/archive/NodeJsLambdaLayer.ts +42 -0
- package/archive/Output.ts +11 -0
- package/{lib/RestApi.js → archive/RestApi.ts} +96 -60
- package/{lib/Role.d.ts → archive/Role.ts} +165 -139
- package/archive/StaticWebSite.ts +159 -0
- package/archive/index.ts +18 -0
- package/archive/methods/apply-schema-to-method-options.ts +38 -0
- package/archive/methods/attach-function-to-api.ts +69 -0
- package/lib/{methods → build}/copy-files.js +1 -1
- package/lib/{methods → build/nodejs}/build-ecmascript.d.ts +2 -2
- package/lib/{methods → build/nodejs}/build-ecmascript.js +5 -5
- package/lib/{methods → build/nodejs}/build-node-source.d.ts +3 -1
- package/lib/{methods → build/nodejs}/build-node-source.js +6 -6
- package/lib/{methods → build/nodejs}/build-typescript.d.ts +2 -2
- package/lib/{methods → build/nodejs}/build-typescript.js +5 -5
- package/lib/{methods → build/nodejs}/install-node-modules.js +1 -1
- package/lib/create-stack.d.ts +41 -0
- package/lib/create-stack.js +48 -0
- package/lib/generate-identifier.d.ts +27 -0
- package/lib/generate-identifier.js +65 -0
- package/lib/index.d.ts +8 -15
- package/lib/index.js +40 -25
- package/lib/lambda/create-function.d.ts +20 -0
- package/lib/lambda/create-function.js +39 -0
- package/lib/lambda/create-nodejs-lambda.d.ts +28 -0
- package/lib/lambda/create-nodejs-lambda.js +38 -0
- package/lib/lambda-layer/apply-honeycomb-to-lambda.d.ts +2 -0
- package/lib/lambda-layer/apply-honeycomb-to-lambda.js +25 -0
- package/lib/lambda-layer/get-layer.d.ts +2 -0
- package/lib/lambda-layer/get-layer.js +20 -0
- package/lib/lambda-layer/layer-cache.d.ts +3 -0
- package/lib/lambda-layer/layer-cache.js +12 -0
- package/lib/load-configuration.d.ts +12 -0
- package/lib/load-configuration.js +42 -0
- package/lib/ssm/SsmParameter.d.ts +12 -0
- package/lib/ssm/get-existing-parameter.d.ts +9 -0
- package/lib/ssm/get-existing-parameter.js +41 -0
- package/lib/ssm/grant-read.d.ts +7 -0
- package/lib/ssm/grant-read.js +24 -0
- package/lib/ssm/index.d.ts +3 -0
- package/lib/ssm/index.js +9 -0
- package/lib/ssm/parameter-cache.d.ts +13 -0
- package/lib/ssm/parameter-cache.js +23 -0
- package/lib/ssm/string-value.d.ts +8 -0
- package/lib/ssm/string-value.js +14 -0
- package/package.json +4 -3
- package/lib/ApiCertificate.d.ts +0 -10
- package/lib/ApiCertificate.js +0 -31
- package/lib/CognitoApiGatewayAuthorizer.js +0 -24
- package/lib/DeployStack.d.ts +0 -19
- package/lib/DeployStack.js +0 -57
- package/lib/DynamoDbTable.d.ts +0 -12
- package/lib/DynamoDbTable.js +0 -34
- package/lib/FunctionIntegration.d.ts +0 -25
- package/lib/FunctionIntegration.js +0 -65
- package/lib/ICorsConfig.d.ts +0 -5
- package/lib/IDomainConfig.d.ts +0 -7
- package/lib/IDomainConfig.js +0 -2
- package/lib/IHostedZoneConfig.d.ts +0 -5
- package/lib/IHostedZoneConfig.js +0 -2
- package/lib/IStackArguments.d.ts +0 -8
- package/lib/IStackArguments.js +0 -2
- package/lib/NodeJsLambda.d.ts +0 -35
- package/lib/NodeJsLambda.js +0 -44
- package/lib/NodeJsLambdaLayer.d.ts +0 -25
- package/lib/NodeJsLambdaLayer.js +0 -35
- package/lib/Output.d.ts +0 -5
- package/lib/Output.js +0 -13
- package/lib/RestApi.d.ts +0 -28
- package/lib/Role.js +0 -27
- package/lib/SsmParameter.d.ts +0 -18
- package/lib/SsmParameter.js +0 -40
- package/lib/StaticWebSite.d.ts +0 -33
- package/lib/StaticWebSite.js +0 -136
- package/lib/methods/BuildOptions.d.ts +0 -3
- package/lib/methods/BuildOptions.js +0 -2
- package/lib/methods/apply-honeycomb-to-lambda.d.ts +0 -3
- package/lib/methods/apply-honeycomb-to-lambda.js +0 -23
- /package/lib/{methods → build}/copy-files.d.ts +0 -0
- /package/lib/{methods → build}/generate-hash.d.ts +0 -0
- /package/lib/{methods → build}/generate-hash.js +0 -0
- /package/lib/{methods → build}/get-files.d.ts +0 -0
- /package/lib/{methods → build}/get-files.js +0 -0
- /package/lib/{methods → build}/get-source-directory.d.ts +0 -0
- /package/lib/{methods → build}/get-source-directory.js +0 -0
- /package/lib/{methods → build}/hash-file.d.ts +0 -0
- /package/lib/{methods → build}/hash-file.js +0 -0
- /package/lib/{methods → build/nodejs}/install-node-modules.d.ts +0 -0
- /package/lib/{ICorsConfig.js → ssm/SsmParameter.js} +0 -0
- /package/lib/{methods → tools}/duration.d.ts +0 -0
- /package/lib/{methods → tools}/duration.js +0 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getExistingParameter = void 0;
|
4
|
+
const aws_ssm_1 = require("aws-cdk-lib/aws-ssm");
|
5
|
+
const parameter_cache_1 = require("./parameter-cache");
|
6
|
+
const create_stack_1 = require("../create-stack");
|
7
|
+
const generate_identifier_1 = require("../generate-identifier");
|
8
|
+
/**
|
9
|
+
* Retrieves an existing SSM parameter.
|
10
|
+
* If the parameter is not in the cache, it references the parameter and stores it in the cache.
|
11
|
+
* @param {string} name - The name of the parameter.
|
12
|
+
* @param {SsmParameterOptions} [options] - The options for the parameter.
|
13
|
+
* @returns {SsmParameter} The SSM parameter.
|
14
|
+
*/
|
15
|
+
function getExistingParameter(name, options) {
|
16
|
+
let param = (0, parameter_cache_1.get)(name);
|
17
|
+
if (!param) {
|
18
|
+
param = referenceParameter(name, options);
|
19
|
+
(0, parameter_cache_1.store)(name, param);
|
20
|
+
}
|
21
|
+
return param;
|
22
|
+
}
|
23
|
+
exports.getExistingParameter = getExistingParameter;
|
24
|
+
/**
|
25
|
+
* References an SSM parameter and returns it.
|
26
|
+
* @param {string} name - The name of the parameter.
|
27
|
+
* @param {SsmParameterOptions} [options] - The options for the parameter.
|
28
|
+
* @returns {SsmParameter} The SSM parameter.
|
29
|
+
*/
|
30
|
+
function referenceParameter(name, options) {
|
31
|
+
if (name[0] !== '/')
|
32
|
+
name = '/' + name;
|
33
|
+
const { stack } = (0, create_stack_1.getCurrentStack)();
|
34
|
+
const parameterName = `/${options?.parameterGroup ?? stack.stackName}${name}`;
|
35
|
+
return {
|
36
|
+
shortName: name,
|
37
|
+
parameterArn: `arn:aws:ssm:${stack.region}:${stack.account}:parameter${parameterName}`,
|
38
|
+
decryptWithKey: options?.decryptWithKey,
|
39
|
+
parameter: aws_ssm_1.StringParameter.fromStringParameterName(stack, (0, generate_identifier_1.genStackResourceId)(parameterName), parameterName)
|
40
|
+
};
|
41
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { IGrantable } from "aws-cdk-lib/aws-iam";
|
2
|
+
/**
|
3
|
+
* Grants read access to an SSM parameter for a grantee.
|
4
|
+
* @param {string} name - The name of the SSM parameter.
|
5
|
+
* @param {IGrantable} grantee - The entity to be granted read access.
|
6
|
+
*/
|
7
|
+
export declare function grantRead(name: string, grantee: IGrantable): void;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.grantRead = void 0;
|
4
|
+
const aws_iam_1 = require("aws-cdk-lib/aws-iam");
|
5
|
+
const parameter_cache_1 = require("./parameter-cache");
|
6
|
+
/**
|
7
|
+
* Grants read access to an SSM parameter for a grantee.
|
8
|
+
* @param {string} name - The name of the SSM parameter.
|
9
|
+
* @param {IGrantable} grantee - The entity to be granted read access.
|
10
|
+
*/
|
11
|
+
function grantRead(name, grantee) {
|
12
|
+
// Retrieve the SSM parameter from the cache
|
13
|
+
const grantor = (0, parameter_cache_1.get)(name);
|
14
|
+
// Add a policy to the grantee's principal that allows 'ssm:GetParameter' action on the SSM parameter
|
15
|
+
grantee.grantPrincipal.addToPrincipalPolicy(new aws_iam_1.PolicyStatement({
|
16
|
+
effect: aws_iam_1.Effect.ALLOW,
|
17
|
+
actions: ['ssm:GetParameter'],
|
18
|
+
resources: [grantor.parameterArn]
|
19
|
+
}));
|
20
|
+
// If the SSM parameter is encrypted with a key, grant the grantee decrypt permissions on the key
|
21
|
+
if (grantor.decryptWithKey)
|
22
|
+
grantor.decryptWithKey.grantDecrypt(grantee);
|
23
|
+
}
|
24
|
+
exports.grantRead = grantRead;
|
package/lib/ssm/index.js
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.stringValue = exports.grantRead = exports.getExistingParameter = void 0;
|
4
|
+
var get_existing_parameter_1 = require("./get-existing-parameter");
|
5
|
+
Object.defineProperty(exports, "getExistingParameter", { enumerable: true, get: function () { return get_existing_parameter_1.getExistingParameter; } });
|
6
|
+
var grant_read_1 = require("./grant-read");
|
7
|
+
Object.defineProperty(exports, "grantRead", { enumerable: true, get: function () { return grant_read_1.grantRead; } });
|
8
|
+
var string_value_1 = require("./string-value");
|
9
|
+
Object.defineProperty(exports, "stringValue", { enumerable: true, get: function () { return string_value_1.stringValue; } });
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { SsmParameter } from "./SsmParameter";
|
2
|
+
/**
|
3
|
+
* Retrieves an SSM parameter from the cache.
|
4
|
+
* @param {string} name - The name of the SSM parameter.
|
5
|
+
* @returns {SsmParameter} The SSM parameter.
|
6
|
+
*/
|
7
|
+
export declare function get(name: string): SsmParameter;
|
8
|
+
/**
|
9
|
+
* Stores an SSM parameter in the cache.
|
10
|
+
* @param {string} name - The name of the SSM parameter.
|
11
|
+
* @param {SsmParameter} param - The SSM parameter to store.
|
12
|
+
*/
|
13
|
+
export declare function store(name: string, param: SsmParameter): void;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.store = exports.get = void 0;
|
4
|
+
// Cache for storing SSM parameters
|
5
|
+
const paramCache = {};
|
6
|
+
/**
|
7
|
+
* Retrieves an SSM parameter from the cache.
|
8
|
+
* @param {string} name - The name of the SSM parameter.
|
9
|
+
* @returns {SsmParameter} The SSM parameter.
|
10
|
+
*/
|
11
|
+
function get(name) {
|
12
|
+
return paramCache[name];
|
13
|
+
}
|
14
|
+
exports.get = get;
|
15
|
+
/**
|
16
|
+
* Stores an SSM parameter in the cache.
|
17
|
+
* @param {string} name - The name of the SSM parameter.
|
18
|
+
* @param {SsmParameter} param - The SSM parameter to store.
|
19
|
+
*/
|
20
|
+
function store(name, param) {
|
21
|
+
paramCache[name] = param;
|
22
|
+
}
|
23
|
+
exports.store = store;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { SsmParameterOptions } from "./SsmParameter";
|
2
|
+
/**
|
3
|
+
* Retrieves the string value of an existing SSM parameter.
|
4
|
+
* @param {string} name - The name of the SSM parameter.
|
5
|
+
* @param {SsmParameterOptions} [options] - The options for the SSM parameter.
|
6
|
+
* @returns {string} The string value of the SSM parameter.
|
7
|
+
*/
|
8
|
+
export declare function stringValue(name: string, options?: SsmParameterOptions): string;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.stringValue = void 0;
|
4
|
+
const get_existing_parameter_1 = require("./get-existing-parameter");
|
5
|
+
/**
|
6
|
+
* Retrieves the string value of an existing SSM parameter.
|
7
|
+
* @param {string} name - The name of the SSM parameter.
|
8
|
+
* @param {SsmParameterOptions} [options] - The options for the SSM parameter.
|
9
|
+
* @returns {string} The string value of the SSM parameter.
|
10
|
+
*/
|
11
|
+
function stringValue(name, options) {
|
12
|
+
return (0, get_existing_parameter_1.getExistingParameter)(name, options).parameter.stringValue;
|
13
|
+
}
|
14
|
+
exports.stringValue = stringValue;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@byaga/cdk-patterns",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.11.1",
|
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",
|
@@ -24,12 +24,14 @@
|
|
24
24
|
"constructs": "^10.3.0",
|
25
25
|
"fs-extra": "^11.2.0",
|
26
26
|
"glob": "^10.3.10",
|
27
|
-
"ignore": "^5.3.0"
|
27
|
+
"ignore": "^5.3.0",
|
28
|
+
"js-yaml": "^4.1.0"
|
28
29
|
},
|
29
30
|
"devDependencies": {
|
30
31
|
"@types/fs-extra": "^11.0.4",
|
31
32
|
"@types/glob": "^8.1.0",
|
32
33
|
"@types/jest": "^29.5.11",
|
34
|
+
"@types/js-yaml": "^4.0.9",
|
33
35
|
"@types/node": "^20.11.5",
|
34
36
|
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
35
37
|
"@typescript-eslint/parser": "^6.19.0",
|
@@ -38,7 +40,6 @@
|
|
38
40
|
"jest-html-reporters": "^3.1.7",
|
39
41
|
"jest-junit": "^16.0.0",
|
40
42
|
"ts-jest": "^29.1.1",
|
41
|
-
"ts-mockito": "^2.6.1",
|
42
43
|
"typescript": "^5.3.3"
|
43
44
|
},
|
44
45
|
"repository": {
|
package/lib/ApiCertificate.d.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
|
2
|
-
import { IHostedZone } from "aws-cdk-lib/aws-route53";
|
3
|
-
import DeployStack from "./DeployStack";
|
4
|
-
import IDomainConfig from "./IDomainConfig";
|
5
|
-
export declare class ApiCertificate extends Certificate {
|
6
|
-
hostedZone: IHostedZone;
|
7
|
-
domain: string;
|
8
|
-
constructor(stack: DeployStack, id: string, domain: IDomainConfig);
|
9
|
-
}
|
10
|
-
export default ApiCertificate;
|
package/lib/ApiCertificate.js
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ApiCertificate = void 0;
|
4
|
-
const aws_certificatemanager_1 = require("aws-cdk-lib/aws-certificatemanager");
|
5
|
-
const aws_route53_1 = require("aws-cdk-lib/aws-route53");
|
6
|
-
const Output_1 = require("./Output");
|
7
|
-
class ApiCertificate extends aws_certificatemanager_1.Certificate {
|
8
|
-
hostedZone;
|
9
|
-
domain;
|
10
|
-
constructor(stack, id, domain) {
|
11
|
-
const certDomain = [domain.domainName];
|
12
|
-
if (domain.subdomain)
|
13
|
-
certDomain.splice(0, 0, domain.subdomain);
|
14
|
-
const domainName = certDomain.join('.');
|
15
|
-
console.log('Getting Hosted Zone', domain.hostedZone.name);
|
16
|
-
const hostedZone = aws_route53_1.HostedZone.fromHostedZoneAttributes(stack, stack.genId(id, 'hosted-zone'), {
|
17
|
-
hostedZoneId: domain.hostedZone.id,
|
18
|
-
zoneName: domain.hostedZone.name
|
19
|
-
});
|
20
|
-
console.log('Defining Certificate For', domainName);
|
21
|
-
super(stack, stack.genId(id), {
|
22
|
-
domainName,
|
23
|
-
validation: aws_certificatemanager_1.CertificateValidation.fromDns(hostedZone)
|
24
|
-
});
|
25
|
-
this.domain = domainName;
|
26
|
-
new Output_1.Output(stack, id, this.certificateArn);
|
27
|
-
this.hostedZone = hostedZone;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
exports.ApiCertificate = ApiCertificate;
|
31
|
-
exports.default = ApiCertificate;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.CognitoApiGatewayAuthorizer = void 0;
|
4
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
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
|
-
class CognitoApiGatewayAuthorizer extends aws_apigateway_1.CfnAuthorizer {
|
18
|
-
authorizerId;
|
19
|
-
constructor(scope, id, props) {
|
20
|
-
super(scope, id, props);
|
21
|
-
this.authorizerId = this.ref;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
exports.CognitoApiGatewayAuthorizer = CognitoApiGatewayAuthorizer;
|
package/lib/DeployStack.d.ts
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
import { Stack } from 'aws-cdk-lib';
|
2
|
-
import IStackArguments from './IStackArguments';
|
3
|
-
import { IConstruct } from "constructs";
|
4
|
-
export declare class DeployStack extends Stack {
|
5
|
-
registry: Record<string, Record<string, unknown>>;
|
6
|
-
stage: string;
|
7
|
-
name: string;
|
8
|
-
project: string;
|
9
|
-
genName(...name: string[]): string;
|
10
|
-
genStackName(stackName: string, ...name: string[]): string;
|
11
|
-
genId(...name: string[]): string;
|
12
|
-
genStackId(stackName: string, ...name: string[]): string;
|
13
|
-
static genStackResourceName(stackName: string, resource: string, stage?: string): string;
|
14
|
-
static genStackResourceId(stackName: string, resource: string, stage?: string): string;
|
15
|
-
constructor(scope: IConstruct, props: IStackArguments);
|
16
|
-
get(type: string, name: string): {} | null;
|
17
|
-
set(type: string, name: string, instance: unknown): unknown;
|
18
|
-
}
|
19
|
-
export default DeployStack;
|
package/lib/DeployStack.js
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DeployStack = void 0;
|
4
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
5
|
-
class DeployStack extends aws_cdk_lib_1.Stack {
|
6
|
-
registry = {};
|
7
|
-
stage;
|
8
|
-
name;
|
9
|
-
project;
|
10
|
-
genName(...name) {
|
11
|
-
return DeployStack.genStackResourceName(this.name, name.filter(n => !!n).join('-'), this.stage);
|
12
|
-
}
|
13
|
-
genStackName(stackName, ...name) {
|
14
|
-
return DeployStack.genStackResourceName(stackName, name.filter(n => !!n).join('-'), this.stage);
|
15
|
-
}
|
16
|
-
genId(...name) {
|
17
|
-
return DeployStack.genStackResourceId(this.name, name.filter(n => !!n).join('-'), this.stage);
|
18
|
-
}
|
19
|
-
genStackId(stackName, ...name) {
|
20
|
-
return DeployStack.genStackResourceId(stackName, name.filter(n => !!n).join('-'), this.stage);
|
21
|
-
}
|
22
|
-
static genStackResourceName(stackName, resource, stage = 'develop') {
|
23
|
-
let name = stackName[0].toLowerCase() + stackName.substring(1);
|
24
|
-
name = name.replace(/[A-Z]/g, v => '-' + v.toLowerCase());
|
25
|
-
return `${name}-${stage}-${resource}`.toLowerCase();
|
26
|
-
}
|
27
|
-
static genStackResourceId(stackName, resource, stage = 'develop') {
|
28
|
-
const constructName = `${stackName}-${stage}-${resource}`;
|
29
|
-
return constructName[0].toUpperCase() + constructName.substring(1).replace(/-./g, v => (v[1] || '').toUpperCase());
|
30
|
-
}
|
31
|
-
constructor(scope, props) {
|
32
|
-
const options = (props || {});
|
33
|
-
const { stage = 'develop' } = options;
|
34
|
-
super(scope, props.stackName + '-' + stage, {
|
35
|
-
...props,
|
36
|
-
stackName: props.stackName + '-' + stage
|
37
|
-
});
|
38
|
-
this.name = props.stackName || '';
|
39
|
-
this.stage = stage;
|
40
|
-
this.project = props.project;
|
41
|
-
this.tags.setTag('stage', stage);
|
42
|
-
this.tags.setTag('stack', this.genName('ui-stack'));
|
43
|
-
this.tags.setTag('project', props.project);
|
44
|
-
this.tags.setTag('owner', props.owner);
|
45
|
-
}
|
46
|
-
get(type, name) {
|
47
|
-
const items = this.registry[type];
|
48
|
-
return (items && items[name]) || null;
|
49
|
-
}
|
50
|
-
set(type, name, instance) {
|
51
|
-
this.registry[type] = this.registry[type] || {};
|
52
|
-
this.registry[type][name] = instance;
|
53
|
-
return instance;
|
54
|
-
}
|
55
|
-
}
|
56
|
-
exports.DeployStack = DeployStack;
|
57
|
-
exports.default = DeployStack;
|
package/lib/DynamoDbTable.d.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { Table } from 'aws-cdk-lib/aws-dynamodb';
|
2
|
-
import { Policy } from "aws-cdk-lib/aws-iam";
|
3
|
-
import { DeployStack } from "./DeployStack";
|
4
|
-
interface DynamoDbTableConfig {
|
5
|
-
partitionKey: string;
|
6
|
-
sortKey?: string;
|
7
|
-
}
|
8
|
-
export declare class DynamoDbTable extends Table {
|
9
|
-
getPolicy: Policy;
|
10
|
-
constructor(stack: DeployStack, id: string, props: DynamoDbTableConfig);
|
11
|
-
}
|
12
|
-
export {};
|
package/lib/DynamoDbTable.js
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DynamoDbTable = void 0;
|
4
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
5
|
-
const aws_dynamodb_1 = require("aws-cdk-lib/aws-dynamodb");
|
6
|
-
const aws_iam_1 = require("aws-cdk-lib/aws-iam");
|
7
|
-
class DynamoDbTable extends aws_dynamodb_1.Table {
|
8
|
-
getPolicy;
|
9
|
-
constructor(stack, id, props) {
|
10
|
-
console.log('Creating DynamoDb Table', stack.genName(id, 'data-table'));
|
11
|
-
super(stack, stack.genId(id, 'data-table'), {
|
12
|
-
tableName: stack.genName(id, 'data-table'),
|
13
|
-
partitionKey: { name: props.partitionKey, type: aws_dynamodb_1.AttributeType.STRING },
|
14
|
-
sortKey: props.sortKey ? { name: props.sortKey, type: aws_dynamodb_1.AttributeType.STRING } : undefined,
|
15
|
-
billingMode: aws_dynamodb_1.BillingMode.PAY_PER_REQUEST,
|
16
|
-
removalPolicy: aws_cdk_lib_1.RemovalPolicy.DESTROY
|
17
|
-
});
|
18
|
-
stack.set('dynamo', id, this);
|
19
|
-
new aws_cdk_lib_1.CfnOutput(stack, stack.genId(id, 'table'), {
|
20
|
-
value: this.tableName,
|
21
|
-
exportName: stack.genName(id, 'table')
|
22
|
-
});
|
23
|
-
this.getPolicy = new aws_iam_1.Policy(stack, stack.genId(id, 'get-policy'), {
|
24
|
-
statements: [
|
25
|
-
new aws_iam_1.PolicyStatement({
|
26
|
-
actions: ['dynamodb:GetItem'],
|
27
|
-
effect: aws_iam_1.Effect.ALLOW,
|
28
|
-
resources: [this.tableArn]
|
29
|
-
})
|
30
|
-
]
|
31
|
-
});
|
32
|
-
}
|
33
|
-
}
|
34
|
-
exports.DynamoDbTable = DynamoDbTable;
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import { DeployStack } from "./DeployStack";
|
2
|
-
import { Function, FunctionProps } from "aws-cdk-lib/aws-lambda";
|
3
|
-
import { JsonSchema, MethodOptions, Method } from "aws-cdk-lib/aws-apigateway";
|
4
|
-
import { Duration } from "aws-cdk-lib";
|
5
|
-
import { RestApi } from "./RestApi";
|
6
|
-
interface AddToApiOptions {
|
7
|
-
requestSchema?: JsonSchema;
|
8
|
-
methodOptions?: MethodOptions;
|
9
|
-
}
|
10
|
-
export interface FunctionIntegrationProps {
|
11
|
-
funcProps: FunctionProps;
|
12
|
-
timeout?: Duration;
|
13
|
-
memory?: number;
|
14
|
-
}
|
15
|
-
export declare class FunctionIntegration extends Function {
|
16
|
-
stack: DeployStack;
|
17
|
-
name: string;
|
18
|
-
constructor(stack: DeployStack, id: string, options: FunctionIntegrationProps);
|
19
|
-
attach(api: RestApi, httpMethod: string, path: string, props?: AddToApiOptions): ApiAttachPoint;
|
20
|
-
}
|
21
|
-
interface ApiAttachPoint {
|
22
|
-
method: Method;
|
23
|
-
resourceArn: string;
|
24
|
-
}
|
25
|
-
export {};
|
@@ -1,65 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.FunctionIntegration = void 0;
|
4
|
-
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
5
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
6
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
7
|
-
const apply_honeycomb_to_lambda_1 = require("./methods/apply-honeycomb-to-lambda");
|
8
|
-
const aws_logs_1 = require("aws-cdk-lib/aws-logs");
|
9
|
-
class FunctionIntegration extends aws_lambda_1.Function {
|
10
|
-
stack;
|
11
|
-
name;
|
12
|
-
constructor(stack, id, options) {
|
13
|
-
const props = (0, apply_honeycomb_to_lambda_1.applyHoneycombToLambda)(stack, {
|
14
|
-
functionName: stack.genName(id),
|
15
|
-
memorySize: options.memory || 256,
|
16
|
-
timeout: options.timeout || aws_cdk_lib_1.Duration.seconds(16),
|
17
|
-
logRetention: aws_logs_1.RetentionDays.ONE_WEEK,
|
18
|
-
...options.funcProps
|
19
|
-
});
|
20
|
-
super(stack, stack.genId(id, 'lambda'), props);
|
21
|
-
this.stack = stack;
|
22
|
-
this.name = id;
|
23
|
-
stack.set('lambda', id, this);
|
24
|
-
new aws_cdk_lib_1.CfnOutput(stack, stack.genId(id, 'function-name'), {
|
25
|
-
value: this.functionName,
|
26
|
-
exportName: stack.genName(id, 'function-name')
|
27
|
-
});
|
28
|
-
}
|
29
|
-
attach(api, httpMethod, path, props = {}) {
|
30
|
-
const resource = api.path(path);
|
31
|
-
const integration = new aws_apigateway_1.LambdaIntegration(this, {
|
32
|
-
requestTemplates: {
|
33
|
-
'application/json': '{ "statusCode": "200" }'
|
34
|
-
}
|
35
|
-
});
|
36
|
-
let options = props?.methodOptions || {};
|
37
|
-
const schema = props?.requestSchema;
|
38
|
-
if (schema)
|
39
|
-
options = applySchema(this.stack, this.name, schema, options, resource);
|
40
|
-
const method = resource.addMethod(httpMethod, integration, options);
|
41
|
-
return {
|
42
|
-
method,
|
43
|
-
resourceArn: `arn:aws:execute-api:${this.stack.region}:${this.stack.account}:${api.restApiId}/${this.stack.stage}/${httpMethod}${path}`
|
44
|
-
};
|
45
|
-
}
|
46
|
-
}
|
47
|
-
exports.FunctionIntegration = FunctionIntegration;
|
48
|
-
function applySchema(stack, name, schema, options, path) {
|
49
|
-
return {
|
50
|
-
...options,
|
51
|
-
requestValidator: new aws_apigateway_1.RequestValidator(stack, stack.genId(name, 'validator'), {
|
52
|
-
restApi: path.api,
|
53
|
-
requestValidatorName: stack.genName(name, 'validator'),
|
54
|
-
validateRequestBody: true
|
55
|
-
}),
|
56
|
-
requestModels: {
|
57
|
-
'application/json': new aws_apigateway_1.Model(stack, stack.genId(name, 'model'), {
|
58
|
-
schema: schema,
|
59
|
-
contentType: 'application/json',
|
60
|
-
restApi: path.api,
|
61
|
-
modelName: stack.genId(name, 'model')
|
62
|
-
})
|
63
|
-
}
|
64
|
-
};
|
65
|
-
}
|
package/lib/ICorsConfig.d.ts
DELETED
package/lib/IDomainConfig.d.ts
DELETED
package/lib/IDomainConfig.js
DELETED
package/lib/IHostedZoneConfig.js
DELETED
package/lib/IStackArguments.d.ts
DELETED
package/lib/IStackArguments.js
DELETED
package/lib/NodeJsLambda.d.ts
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import { FunctionOptions } from "aws-cdk-lib/aws-lambda";
|
2
|
-
import { DeployStack } from "./DeployStack";
|
3
|
-
import { FunctionIntegration } from "./FunctionIntegration";
|
4
|
-
import { Duration } from "aws-cdk-lib";
|
5
|
-
/**
|
6
|
-
* Interface for the properties of a Node.js function.
|
7
|
-
*/
|
8
|
-
interface NodeFunctionProps {
|
9
|
-
/**
|
10
|
-
* The properties of the function.
|
11
|
-
*/
|
12
|
-
funcProps?: FunctionOptions;
|
13
|
-
/**
|
14
|
-
* The timeout duration for the function.
|
15
|
-
*/
|
16
|
-
timeout?: Duration;
|
17
|
-
/**
|
18
|
-
* The memory size for the function.
|
19
|
-
*/
|
20
|
-
memory?: number;
|
21
|
-
}
|
22
|
-
/**
|
23
|
-
* Class representing a Node.js Lambda function.
|
24
|
-
* @extends FunctionIntegration
|
25
|
-
*/
|
26
|
-
export declare class NodeJsLambda extends FunctionIntegration {
|
27
|
-
/**
|
28
|
-
* Creates a new Node.js Lambda function.
|
29
|
-
* @param {DeployStack} stack - The deployment stack.
|
30
|
-
* @param {string} id - The ID of the function.
|
31
|
-
* @param {NodeFunctionProps} options - The properties of the function.
|
32
|
-
*/
|
33
|
-
constructor(stack: DeployStack, id: string, options?: NodeFunctionProps);
|
34
|
-
}
|
35
|
-
export {};
|
package/lib/NodeJsLambda.js
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.NodeJsLambda = void 0;
|
7
|
-
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
8
|
-
const FunctionIntegration_1 = require("./FunctionIntegration");
|
9
|
-
const build_node_source_1 = require("./methods/build-node-source");
|
10
|
-
const duration_1 = __importDefault(require("./methods/duration"));
|
11
|
-
/**
|
12
|
-
* Class representing a Node.js Lambda function.
|
13
|
-
* @extends FunctionIntegration
|
14
|
-
*/
|
15
|
-
class NodeJsLambda extends FunctionIntegration_1.FunctionIntegration {
|
16
|
-
/**
|
17
|
-
* Creates a new Node.js Lambda function.
|
18
|
-
* @param {DeployStack} stack - The deployment stack.
|
19
|
-
* @param {string} id - The ID of the function.
|
20
|
-
* @param {NodeFunctionProps} options - The properties of the function.
|
21
|
-
*/
|
22
|
-
constructor(stack, id, options) {
|
23
|
-
console.log('Defining Node Lambda', id);
|
24
|
-
// Measure the duration of the build process
|
25
|
-
const done = (0, duration_1.default)();
|
26
|
-
// Build the Node.js source code
|
27
|
-
const buildDir = (0, build_node_source_1.buildNodeSource)('lambda', id);
|
28
|
-
console.log('Total Build Duration (ms)', done());
|
29
|
-
// Call the parent constructor with the function properties
|
30
|
-
super(stack, id, {
|
31
|
-
...options,
|
32
|
-
funcProps: {
|
33
|
-
...options?.funcProps,
|
34
|
-
// The source code of the function
|
35
|
-
code: aws_lambda_1.Code.fromAsset(buildDir),
|
36
|
-
// The handler of the function
|
37
|
-
handler: `${id}.handler`,
|
38
|
-
// The runtime of the function
|
39
|
-
runtime: aws_lambda_1.Runtime.NODEJS_20_X
|
40
|
-
}
|
41
|
-
});
|
42
|
-
}
|
43
|
-
}
|
44
|
-
exports.NodeJsLambda = NodeJsLambda;
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import { 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
|
-
/**
|
6
|
-
* Interface for the properties of the NodeJsLambdaLayer class.
|
7
|
-
*/
|
8
|
-
interface NodeJsLambdaLayerProps extends LayerVersionOptions {
|
9
|
-
readonly compatibleRuntimes?: Runtime[];
|
10
|
-
readonly compatibleArchitectures?: Architecture[];
|
11
|
-
}
|
12
|
-
/**
|
13
|
-
* Class representing a Node.js AWS Lambda layer.
|
14
|
-
* Extends the LayerVersion class from the AWS CDK library.
|
15
|
-
*/
|
16
|
-
export declare class NodeJsLambdaLayer extends LayerVersion {
|
17
|
-
/**
|
18
|
-
* Constructs a new NodeJsLambdaLayer instance.
|
19
|
-
* @param {DeployStack} stack - The deployment stack.
|
20
|
-
* @param {string} id - The ID of the layer.
|
21
|
-
* @param {NodeJsLambdaLayerProps} props - The properties of the layer.
|
22
|
-
*/
|
23
|
-
constructor(stack: DeployStack, id: string, props?: NodeJsLambdaLayerProps);
|
24
|
-
}
|
25
|
-
export {};
|