@byaga/cdk-patterns 0.11.4 → 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.
- package/LICENSE.md +20 -20
- package/README.md +42 -42
- package/eslint.config.mjs +12 -0
- package/lib/build/copy-files.d.ts +4 -5
- package/lib/build/copy-files.js +26 -21
- package/lib/build/generate-hash.d.ts +2 -3
- package/lib/build/generate-hash.js +3 -5
- package/lib/build/get-files.d.ts +3 -3
- package/lib/build/get-files.js +3 -3
- package/lib/build/get-source-directory.d.ts +8 -8
- package/lib/build/get-source-directory.js +13 -13
- package/lib/build/hash-file.js +4 -5
- package/lib/build/index.d.ts +2 -0
- package/lib/build/index.js +21 -0
- package/lib/build/nodejs/build-ecmascript.d.ts +3 -3
- package/lib/build/nodejs/build-ecmascript.js +4 -5
- package/lib/build/nodejs/build-node-source.d.ts +9 -3
- package/lib/build/nodejs/build-node-source.js +10 -11
- package/lib/build/nodejs/build-typescript.d.ts +3 -3
- package/lib/build/nodejs/build-typescript.js +7 -10
- package/lib/build/nodejs/index.d.ts +1 -0
- package/lib/build/nodejs/index.js +5 -0
- package/lib/build/nodejs/install-node-modules.d.ts +4 -3
- package/lib/build/nodejs/install-node-modules.js +6 -6
- package/lib/cloud-formation/DeployStack.d.ts +11 -0
- package/lib/cloud-formation/DeployStack.js +2 -0
- package/lib/cloud-formation/create-stack.d.ts +20 -0
- package/lib/cloud-formation/create-stack.js +31 -0
- package/lib/cloud-formation/current-stack.d.ts +10 -0
- package/lib/cloud-formation/current-stack.js +19 -0
- package/lib/{generate-identifier.js → cloud-formation/generate-identifier.js} +7 -8
- package/lib/cloud-formation/index.d.ts +5 -0
- package/lib/cloud-formation/index.js +14 -0
- package/lib/cloud-formation/output.d.ts +2 -0
- package/lib/cloud-formation/output.js +12 -0
- package/lib/cloud-front/distribution.d.ts +16 -0
- package/lib/cloud-front/distribution.js +43 -0
- package/lib/cloud-front/index.d.ts +1 -0
- package/lib/cloud-front/index.js +5 -0
- package/lib/cloud-watch/create-log-group.js +4 -6
- package/lib/cloud-watch/index.d.ts +1 -0
- package/lib/cloud-watch/index.js +5 -0
- package/lib/cloud-watch/set-log-retention.d.ts +2 -0
- package/lib/cloud-watch/set-log-retention.js +14 -0
- package/lib/index.d.ts +11 -8
- package/lib/index.js +13 -29
- package/lib/lambda/create-function.d.ts +4 -2
- package/lib/lambda/create-function.js +15 -23
- package/lib/lambda/create-nodejs-lambda.d.ts +2 -2
- package/lib/lambda/create-nodejs-lambda.js +3 -4
- package/lib/lambda/index.d.ts +1 -0
- package/lib/lambda/index.js +5 -0
- package/lib/lambda-layer/apply-honeycomb-to-lambda.d.ts +1 -1
- package/lib/lambda-layer/apply-honeycomb-to-lambda.js +4 -5
- package/lib/lambda-layer/get-layer.js +4 -6
- package/lib/lambda-layer/index.d.ts +2 -0
- package/lib/lambda-layer/index.js +7 -0
- package/lib/lambda-layer/layer-cache.d.ts +3 -3
- package/lib/lambda-layer/layer-cache.js +3 -9
- package/lib/load-configuration.d.ts +3 -8
- package/lib/load-configuration.js +20 -11
- package/lib/recipes/ICorsConfig.d.ts +5 -0
- package/lib/recipes/ICorsConfig.js +2 -0
- package/lib/recipes/index.d.ts +1 -0
- package/lib/recipes/index.js +5 -0
- package/lib/recipes/staticWebSite.d.ts +13 -0
- package/lib/recipes/staticWebSite.js +54 -0
- package/lib/route53/IDomainConfig.d.ts +7 -0
- package/lib/route53/IDomainConfig.js +2 -0
- package/lib/route53/IHostedZoneConfig.d.ts +5 -0
- package/lib/route53/IHostedZoneConfig.js +2 -0
- package/lib/route53/apiCertificate.d.ts +13 -0
- package/lib/route53/apiCertificate.js +30 -0
- package/lib/route53/index.d.ts +3 -0
- package/lib/route53/index.js +5 -0
- package/lib/s3/bucket.d.ts +8 -0
- package/lib/s3/bucket.js +21 -0
- package/lib/s3/index.d.ts +1 -0
- package/lib/s3/index.js +5 -0
- package/lib/ssm/SsmParameter.d.ts +2 -2
- package/lib/ssm/StringParameter.d.ts +9 -0
- package/lib/ssm/StringParameter.js +15 -0
- package/lib/ssm/get-existing-parameter.js +4 -6
- package/lib/ssm/grant-read.js +1 -2
- package/lib/ssm/index.d.ts +1 -0
- package/lib/ssm/index.js +3 -1
- package/lib/ssm/parameter-cache.js +2 -3
- package/lib/ssm/string-value.js +1 -2
- package/lib/tools/index.d.ts +3 -0
- package/lib/tools/index.js +10 -0
- package/package.json +21 -15
- package/tsconfig.json +2 -2
- package/.fleet/run.json +0 -11
- package/archive/ApiAttachPoint.ts +0 -9
- package/archive/ApiCertificate.ts +0 -32
- package/archive/CognitoApiGatewayAuthorizer.ts +0 -25
- package/archive/DynamoDbTable.ts +0 -40
- package/archive/ICorsConfig.ts +0 -5
- package/archive/IDomainConfig.ts +0 -8
- package/archive/IHostedZoneConfig.ts +0 -5
- package/archive/NodeJsLambdaLayer.ts +0 -42
- package/archive/Output.ts +0 -11
- package/archive/RestApi.ts +0 -180
- package/archive/Role.ts +0 -165
- package/archive/StaticWebSite.ts +0 -159
- package/archive/index.ts +0 -18
- package/archive/methods/apply-schema-to-method-options.ts +0 -38
- package/archive/methods/attach-function-to-api.ts +0 -69
- package/lib/create-stack.d.ts +0 -40
- package/lib/create-stack.js +0 -48
- /package/lib/{generate-identifier.d.ts → cloud-formation/generate-identifier.d.ts} +0 -0
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getLayer = exports.applyHoneycombToLambda = void 0;
|
4
|
+
var apply_honeycomb_to_lambda_1 = require("./apply-honeycomb-to-lambda");
|
5
|
+
Object.defineProperty(exports, "applyHoneycombToLambda", { enumerable: true, get: function () { return apply_honeycomb_to_lambda_1.applyHoneycombToLambda; } });
|
6
|
+
var get_layer_1 = require("./get-layer");
|
7
|
+
Object.defineProperty(exports, "getLayer", { enumerable: true, get: function () { return get_layer_1.getLayer; } });
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { ILayerVersion } from "aws-cdk-lib/aws-lambda";
|
2
|
-
export declare
|
3
|
-
export declare
|
1
|
+
import type { ILayerVersion } from "aws-cdk-lib/aws-lambda";
|
2
|
+
export declare const get: (key: string) => ILayerVersion | undefined;
|
3
|
+
export declare const store: (key: string, value: ILayerVersion) => Map<string, ILayerVersion>;
|
@@ -1,12 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.store = exports.get = void 0;
|
4
|
-
const layerCache =
|
5
|
-
|
6
|
-
|
7
|
-
}
|
8
|
-
exports.get = get;
|
9
|
-
function store(name, param) {
|
10
|
-
layerCache[name] = param;
|
11
|
-
}
|
12
|
-
exports.store = store;
|
4
|
+
const layerCache = new Map();
|
5
|
+
exports.get = layerCache.get;
|
6
|
+
exports.store = layerCache.set;
|
@@ -1,12 +1,7 @@
|
|
1
|
-
/**
|
2
|
-
* Interface for the stack configuration.
|
3
|
-
*/
|
4
|
-
export interface StackConfiguration {
|
5
|
-
}
|
6
1
|
/**
|
7
2
|
* Loads the configuration for a given stage.
|
8
3
|
* If the configuration file does not exist, an empty object is returned.
|
9
|
-
* @param
|
10
|
-
* @returns
|
4
|
+
* @param stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
|
5
|
+
* @returns The loaded configuration.
|
11
6
|
*/
|
12
|
-
export declare function loadConfiguration(stage?: string):
|
7
|
+
export declare function loadConfiguration<T extends object>(stage?: string): T;
|
@@ -15,22 +15,32 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.loadConfiguration =
|
36
|
+
exports.loadConfiguration = loadConfiguration;
|
27
37
|
const yaml = __importStar(require("js-yaml"));
|
28
38
|
const fs = __importStar(require("fs-extra"));
|
29
39
|
/**
|
30
40
|
* Loads the configuration for a given stage.
|
31
41
|
* If the configuration file does not exist, an empty object is returned.
|
32
|
-
* @param
|
33
|
-
* @returns
|
42
|
+
* @param stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
|
43
|
+
* @returns The loaded configuration.
|
34
44
|
*/
|
35
45
|
function loadConfiguration(stage = process.env.STAGE || "develop") {
|
36
46
|
const path = `config/${stage}.yml`;
|
@@ -39,4 +49,3 @@ function loadConfiguration(stage = process.env.STAGE || "develop") {
|
|
39
49
|
}
|
40
50
|
return {};
|
41
51
|
}
|
42
|
-
exports.loadConfiguration = loadConfiguration;
|
@@ -0,0 +1 @@
|
|
1
|
+
export { staticWebSite } from './staticWebSite';
|
@@ -0,0 +1,5 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.staticWebSite = void 0;
|
4
|
+
var staticWebSite_1 = require("./staticWebSite");
|
5
|
+
Object.defineProperty(exports, "staticWebSite", { enumerable: true, get: function () { return staticWebSite_1.staticWebSite; } });
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { type IDomainConfig } from "../route53";
|
2
|
+
/**
|
3
|
+
* Configuration interface for the StaticWebSite class.
|
4
|
+
*/
|
5
|
+
export interface StaticWebSiteConfig {
|
6
|
+
domain: IDomainConfig;
|
7
|
+
env?: NodeJS.ProcessEnv;
|
8
|
+
shouldCache?: boolean;
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* Sets up a basic static website in AWS with an S3 Bucket, CloudFront Distribution, and Route53 A-Name Record.
|
12
|
+
*/
|
13
|
+
export declare function staticWebSite(id: string, props: StaticWebSiteConfig): void;
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.staticWebSite = staticWebSite;
|
4
|
+
const child_process_1 = require("child_process");
|
5
|
+
const aws_s3_deployment_1 = require("aws-cdk-lib/aws-s3-deployment");
|
6
|
+
const aws_route53_1 = require("aws-cdk-lib/aws-route53");
|
7
|
+
const aws_route53_targets_1 = require("aws-cdk-lib/aws-route53-targets");
|
8
|
+
const cloud_formation_1 = require("../cloud-formation");
|
9
|
+
const build_1 = require("../build");
|
10
|
+
const s3_1 = require("../s3");
|
11
|
+
const route53_1 = require("../route53");
|
12
|
+
const tools_1 = require("../tools");
|
13
|
+
const cloud_front_1 = require("../cloud-front");
|
14
|
+
/**
|
15
|
+
* Sets up a basic static website in AWS with an S3 Bucket, CloudFront Distribution, and Route53 A-Name Record.
|
16
|
+
*/
|
17
|
+
function staticWebSite(id, props) {
|
18
|
+
console.log('Deploying Static Web Site', id);
|
19
|
+
const { stack } = (0, cloud_formation_1.getCurrentStack)();
|
20
|
+
const done = (0, tools_1.duration)();
|
21
|
+
const buildDir = (0, build_1.getBuildDirectory)('web', id);
|
22
|
+
const cwd = (0, build_1.getSourceDirectory)('web', id);
|
23
|
+
(0, child_process_1.spawnSync)('npm i', { cwd });
|
24
|
+
console.log('Building UI Source', id);
|
25
|
+
(0, child_process_1.spawnSync)('npm run export', { cwd });
|
26
|
+
console.log('Total Build Duration (ms)', done());
|
27
|
+
const certificate = (0, route53_1.apiCertificate)(id + '-certificate', props.domain);
|
28
|
+
const s3BucketSource = (0, s3_1.createBucket)(`${id}-content`, {
|
29
|
+
bucketName: certificate.domain
|
30
|
+
});
|
31
|
+
const distribution = (0, cloud_front_1.createDistribution)(id, {
|
32
|
+
shouldCache: props.shouldCache,
|
33
|
+
s3BucketSource,
|
34
|
+
certificate,
|
35
|
+
errorResponses: [{
|
36
|
+
httpStatus: 404,
|
37
|
+
responseHttpStatus: 200,
|
38
|
+
responsePagePath: '/index.html'
|
39
|
+
}]
|
40
|
+
});
|
41
|
+
new aws_s3_deployment_1.BucketDeployment(stack, (0, cloud_formation_1.genId)(id, 'bucket-deployment'), {
|
42
|
+
sources: [aws_s3_deployment_1.Source.asset(buildDir)],
|
43
|
+
destinationBucket: s3BucketSource,
|
44
|
+
distribution,
|
45
|
+
distributionPaths: props.shouldCache ? ['/*'] : undefined,
|
46
|
+
memoryLimit: 2048
|
47
|
+
});
|
48
|
+
console.log('Configuring Route53 A-Name Record', props.domain.domainName);
|
49
|
+
new aws_route53_1.ARecord(stack, (0, cloud_formation_1.genId)('alias'), {
|
50
|
+
zone: certificate.hostedZone,
|
51
|
+
recordName: certificate.domain,
|
52
|
+
target: aws_route53_1.RecordTarget.fromAlias(new aws_route53_targets_1.CloudFrontTarget(distribution))
|
53
|
+
});
|
54
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
|
2
|
+
import { IHostedZone } from "aws-cdk-lib/aws-route53";
|
3
|
+
import IDomainConfig from "./IDomainConfig";
|
4
|
+
export interface CertificateDetails {
|
5
|
+
domain: string;
|
6
|
+
hostedZone: IHostedZone;
|
7
|
+
certificate: Certificate;
|
8
|
+
}
|
9
|
+
export declare function apiCertificate(id: string, domain: IDomainConfig): {
|
10
|
+
domain: string;
|
11
|
+
hostedZone: IHostedZone;
|
12
|
+
certificate: Certificate;
|
13
|
+
};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.apiCertificate = apiCertificate;
|
4
|
+
const aws_certificatemanager_1 = require("aws-cdk-lib/aws-certificatemanager");
|
5
|
+
const aws_route53_1 = require("aws-cdk-lib/aws-route53");
|
6
|
+
const cloud_formation_1 = require("../cloud-formation");
|
7
|
+
function apiCertificate(id, domain) {
|
8
|
+
console.log('Defining HTTPS Certificate', id + '-certificate');
|
9
|
+
const { stack } = (0, cloud_formation_1.getCurrentStack)();
|
10
|
+
const certDomain = [domain.domainName];
|
11
|
+
if (domain.subdomain)
|
12
|
+
certDomain.splice(0, 0, domain.subdomain);
|
13
|
+
const domainName = certDomain.join('.');
|
14
|
+
console.log('Getting Hosted Zone', domain.hostedZone.name);
|
15
|
+
const hostedZone = aws_route53_1.HostedZone.fromHostedZoneAttributes(stack, (0, cloud_formation_1.genId)(id, 'hosted-zone'), {
|
16
|
+
hostedZoneId: domain.hostedZone.id,
|
17
|
+
zoneName: domain.hostedZone.name
|
18
|
+
});
|
19
|
+
console.log('Defining Certificate For', domainName);
|
20
|
+
const certificate = new aws_certificatemanager_1.Certificate(stack, (0, cloud_formation_1.genId)(id), {
|
21
|
+
domainName,
|
22
|
+
validation: aws_certificatemanager_1.CertificateValidation.fromDns(hostedZone)
|
23
|
+
});
|
24
|
+
(0, cloud_formation_1.output)(id, certificate.certificateArn);
|
25
|
+
return {
|
26
|
+
domain: domainName,
|
27
|
+
hostedZone,
|
28
|
+
certificate
|
29
|
+
};
|
30
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.apiCertificate = void 0;
|
4
|
+
var apiCertificate_1 = require("./apiCertificate");
|
5
|
+
Object.defineProperty(exports, "apiCertificate", { enumerable: true, get: function () { return apiCertificate_1.apiCertificate; } });
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { Bucket } from "aws-cdk-lib/aws-s3";
|
2
|
+
import { RemovalPolicy } from "aws-cdk-lib";
|
3
|
+
export interface BucketConfig {
|
4
|
+
bucketName: string;
|
5
|
+
versioned?: boolean;
|
6
|
+
removalPolicy?: RemovalPolicy;
|
7
|
+
}
|
8
|
+
export declare function createBucket(id: string, config?: BucketConfig): Bucket;
|
package/lib/s3/bucket.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createBucket = createBucket;
|
4
|
+
const aws_s3_1 = require("aws-cdk-lib/aws-s3");
|
5
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
6
|
+
const cloud_formation_1 = require("../cloud-formation");
|
7
|
+
function createBucket(id, config) {
|
8
|
+
console.log('Defining S3 Bucket', (0, cloud_formation_1.genId)(id, "bucket"));
|
9
|
+
const bucket = new aws_s3_1.Bucket((0, cloud_formation_1.getCurrentStack)().stack, (0, cloud_formation_1.genId)(id, 'bucket'), {
|
10
|
+
bucketName: config?.bucketName ?? (0, cloud_formation_1.genName)(id, 'bucket'),
|
11
|
+
blockPublicAccess: aws_s3_1.BlockPublicAccess.BLOCK_ALL,
|
12
|
+
accessControl: aws_s3_1.BucketAccessControl.PRIVATE,
|
13
|
+
publicReadAccess: false,
|
14
|
+
removalPolicy: config?.removalPolicy ?? aws_cdk_lib_1.RemovalPolicy.DESTROY,
|
15
|
+
autoDeleteObjects: true,
|
16
|
+
enforceSSL: true,
|
17
|
+
versioned: config?.versioned ?? false
|
18
|
+
});
|
19
|
+
(0, cloud_formation_1.output)((0, cloud_formation_1.genName)(id, 'bucket'), bucket.bucketName);
|
20
|
+
return bucket;
|
21
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { createBucket } from './bucket';
|
package/lib/s3/index.js
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createBucket = void 0;
|
4
|
+
var bucket_1 = require("./bucket");
|
5
|
+
Object.defineProperty(exports, "createBucket", { enumerable: true, get: function () { return bucket_1.createBucket; } });
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { IStringParameter } from "aws-cdk-lib/aws-ssm";
|
2
|
-
import { IKey } from "aws-cdk-lib/aws-kms";
|
1
|
+
import type { IStringParameter } from "aws-cdk-lib/aws-ssm";
|
2
|
+
import type { IKey } from "aws-cdk-lib/aws-kms";
|
3
3
|
export interface SsmParameterOptions {
|
4
4
|
decryptWithKey?: IKey;
|
5
5
|
parameterGroup?: string;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Construct, type IConstruct } from "constructs";
|
2
|
+
export interface StringParameterProps {
|
3
|
+
readonly stringValue: string;
|
4
|
+
}
|
5
|
+
export declare class StringParameter extends Construct {
|
6
|
+
stringValue: string;
|
7
|
+
static fromStringParameterName(scope: IConstruct, id: string, parameterName: string): StringParameter;
|
8
|
+
constructor(scope: IConstruct, id: string, props: StringParameterProps);
|
9
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.StringParameter = void 0;
|
4
|
+
const constructs_1 = require("constructs");
|
5
|
+
class StringParameter extends constructs_1.Construct {
|
6
|
+
stringValue;
|
7
|
+
static fromStringParameterName(scope, id, parameterName) {
|
8
|
+
return new StringParameter(scope, id, { stringValue: parameterName });
|
9
|
+
}
|
10
|
+
constructor(scope, id, props) {
|
11
|
+
super(scope, id);
|
12
|
+
this.stringValue = props.stringValue;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
exports.StringParameter = StringParameter;
|
@@ -1,10 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getExistingParameter =
|
3
|
+
exports.getExistingParameter = getExistingParameter;
|
4
4
|
const aws_ssm_1 = require("aws-cdk-lib/aws-ssm");
|
5
5
|
const parameter_cache_1 = require("./parameter-cache");
|
6
|
-
const
|
7
|
-
const generate_identifier_1 = require("../generate-identifier");
|
6
|
+
const cloud_formation_1 = require("../cloud-formation");
|
8
7
|
/**
|
9
8
|
* Retrieves an existing SSM parameter.
|
10
9
|
* If the parameter is not in the cache, it references the parameter and stores it in the cache.
|
@@ -20,7 +19,6 @@ function getExistingParameter(name, options) {
|
|
20
19
|
}
|
21
20
|
return param;
|
22
21
|
}
|
23
|
-
exports.getExistingParameter = getExistingParameter;
|
24
22
|
/**
|
25
23
|
* References an SSM parameter and returns it.
|
26
24
|
* @param {string} name - The name of the parameter.
|
@@ -30,12 +28,12 @@ exports.getExistingParameter = getExistingParameter;
|
|
30
28
|
function referenceParameter(name, options) {
|
31
29
|
if (name[0] !== '/')
|
32
30
|
name = '/' + name;
|
33
|
-
const { stack } = (0,
|
31
|
+
const { stack } = (0, cloud_formation_1.getCurrentStack)();
|
34
32
|
const parameterName = `/${options?.parameterGroup ?? stack.stackName}${name}`;
|
35
33
|
return {
|
36
34
|
shortName: name,
|
37
35
|
parameterArn: `arn:aws:ssm:${stack.region}:${stack.account}:parameter${parameterName}`,
|
38
36
|
decryptWithKey: options?.decryptWithKey,
|
39
|
-
parameter: aws_ssm_1.StringParameter.fromStringParameterName(stack, (0,
|
37
|
+
parameter: aws_ssm_1.StringParameter.fromStringParameterName(stack, (0, cloud_formation_1.genStackResourceId)(parameterName), parameterName)
|
40
38
|
};
|
41
39
|
}
|
package/lib/ssm/grant-read.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.grantRead =
|
3
|
+
exports.grantRead = grantRead;
|
4
4
|
const aws_iam_1 = require("aws-cdk-lib/aws-iam");
|
5
5
|
const parameter_cache_1 = require("./parameter-cache");
|
6
6
|
/**
|
@@ -21,4 +21,3 @@ function grantRead(name, grantee) {
|
|
21
21
|
if (grantor.decryptWithKey)
|
22
22
|
grantor.decryptWithKey.grantDecrypt(grantee);
|
23
23
|
}
|
24
|
-
exports.grantRead = grantRead;
|
package/lib/ssm/index.d.ts
CHANGED
package/lib/ssm/index.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.stringValue = exports.grantRead = exports.getExistingParameter = void 0;
|
3
|
+
exports.stringValue = exports.grantRead = exports.getExistingParameter = exports.StringParameter = void 0;
|
4
|
+
var aws_ssm_1 = require("aws-cdk-lib/aws-ssm");
|
5
|
+
Object.defineProperty(exports, "StringParameter", { enumerable: true, get: function () { return aws_ssm_1.StringParameter; } });
|
4
6
|
var get_existing_parameter_1 = require("./get-existing-parameter");
|
5
7
|
Object.defineProperty(exports, "getExistingParameter", { enumerable: true, get: function () { return get_existing_parameter_1.getExistingParameter; } });
|
6
8
|
var grant_read_1 = require("./grant-read");
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.get = get;
|
4
|
+
exports.store = store;
|
4
5
|
// Cache for storing SSM parameters
|
5
6
|
const paramCache = {};
|
6
7
|
/**
|
@@ -11,7 +12,6 @@ const paramCache = {};
|
|
11
12
|
function get(name) {
|
12
13
|
return paramCache[name];
|
13
14
|
}
|
14
|
-
exports.get = get;
|
15
15
|
/**
|
16
16
|
* Stores an SSM parameter in the cache.
|
17
17
|
* @param {string} name - The name of the SSM parameter.
|
@@ -20,4 +20,3 @@ exports.get = get;
|
|
20
20
|
function store(name, param) {
|
21
21
|
paramCache[name] = param;
|
22
22
|
}
|
23
|
-
exports.store = store;
|
package/lib/ssm/string-value.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.stringValue =
|
3
|
+
exports.stringValue = stringValue;
|
4
4
|
const get_existing_parameter_1 = require("./get-existing-parameter");
|
5
5
|
/**
|
6
6
|
* Retrieves the string value of an existing SSM parameter.
|
@@ -11,4 +11,3 @@ const get_existing_parameter_1 = require("./get-existing-parameter");
|
|
11
11
|
function stringValue(name, options) {
|
12
12
|
return (0, get_existing_parameter_1.getExistingParameter)(name, options).parameter.stringValue;
|
13
13
|
}
|
14
|
-
exports.stringValue = stringValue;
|
@@ -0,0 +1,10 @@
|
|
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.duration = exports.hrDuration = void 0;
|
7
|
+
const duration_1 = __importDefault(require("./duration"));
|
8
|
+
exports.duration = duration_1.default;
|
9
|
+
var duration_2 = require("./duration");
|
10
|
+
Object.defineProperty(exports, "hrDuration", { enumerable: true, get: function () { return duration_2.hrDuration; } });
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@byaga/cdk-patterns",
|
3
|
-
"version": "0.11.
|
3
|
+
"version": "0.11.6",
|
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",
|
7
7
|
"scripts": {
|
8
8
|
"clean": "rimraf ./lib",
|
9
|
-
"build": "npm run clean && tsc",
|
10
|
-
"lint": "eslint
|
9
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
10
|
+
"lint": "eslint src",
|
11
11
|
"test": "jest ./src",
|
12
12
|
"preversion": "npm run lint && npm test && npm run build"
|
13
13
|
},
|
@@ -19,28 +19,34 @@
|
|
19
19
|
"author": "VeryFineHat",
|
20
20
|
"license": "MIT",
|
21
21
|
"dependencies": {
|
22
|
-
"aws-cdk": "^2.
|
23
|
-
"aws-cdk-lib": "^2.
|
24
|
-
"constructs": "^10.
|
22
|
+
"aws-cdk": "^2.171.1",
|
23
|
+
"aws-cdk-lib": "^2.171.1",
|
24
|
+
"constructs": "^10.4.2",
|
25
25
|
"fs-extra": "^11.2.0",
|
26
|
-
"glob": "^
|
27
|
-
"ignore": "^
|
26
|
+
"glob": "^11.0.0",
|
27
|
+
"ignore": "^6.0.2",
|
28
28
|
"js-yaml": "^4.1.0"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
|
+
"@eslint/js": "^9.16.0",
|
31
32
|
"@types/fs-extra": "^11.0.4",
|
32
33
|
"@types/glob": "^8.1.0",
|
33
|
-
"@types/jest": "^29.5.
|
34
|
+
"@types/jest": "^29.5.14",
|
34
35
|
"@types/js-yaml": "^4.0.9",
|
35
|
-
"@types/node": "^
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"eslint": "^8.56.0",
|
36
|
+
"@types/node": "^22.10.1",
|
37
|
+
"eslint": "^9.16.0",
|
38
|
+
"globals": "^15.13.0",
|
39
39
|
"jest": "^29.7.0",
|
40
40
|
"jest-html-reporters": "^3.1.7",
|
41
41
|
"jest-junit": "^16.0.0",
|
42
|
-
"
|
43
|
-
"
|
42
|
+
"rimraf": "^6.0.1",
|
43
|
+
"ts-jest": "^29.2.5",
|
44
|
+
"ts-node": "^10.9.2",
|
45
|
+
"typescript": "^5.7.2",
|
46
|
+
"typescript-eslint": "^8.17.0"
|
47
|
+
},
|
48
|
+
"exports": {
|
49
|
+
".": "./lib/index.js"
|
44
50
|
},
|
45
51
|
"repository": {
|
46
52
|
"type": "git",
|
package/tsconfig.json
CHANGED
package/.fleet/run.json
DELETED
@@ -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
|
-
}
|