@genie-solutions/gdk

中文文档
1.0.1发布于 2022/05/10ISCTypeScriptCommonJS近 30 天下载 4718

Common AWS CDK constructs for Genie

原始使用文档
文档目录12 节
  1. Installing
  2. Dependencies
  3. Structure
  4. Modules
  5. Module Contents
  6. Module Tests
  7. How to publish a new version
  8. Useful commands
  9. Examples
  10. Prerequisites
  11. Example 1
  12. Example 2

GDK - Genie Constructs Library for AWS CDK

Set of reusable constructs for deploying AWS resources to Gentu and Platform.

Installing

Installing this library into your project

$ npm i @genie-solutions/gdk

Dependencies

IMPORTANT:

Major version 1.0.0 is built using version 2.0.0 of the AWS CDK. If you are using this library fresh, please use version 1.0.0 of the library and version 2.0.0+ of the AWS CDK. Legacy instructions remain below for supporting version 0.40.0.

LEGACY SUPPORT ONLY

This library is built using using version 1.151.0 of the AWS CDK. To ensure that you are able to use cdk and this library, please pin your cdk version.

$ npm i -g [email protected]

Again also if you are using native CDK packages in your project, please ensure that you are using the same version. Example: S3 package...

$ npm install @aws-cdk/[email protected]

Structure

Modules

The GDK Library is organized into several modules but are packaged up into a single asset. The structure of the project is as follows:

  • src/xxx: where xxx represents the service component of an AWS CDK package name. Example: src/ecs will contain constructs that are extensions of aws-ecs constructs.
  • src/base-infra: this contains base infrastructure constructs that are imports of native CloudFormation templates.

Module Contents

Modules contain the following types:

  • Constructs - All higher-level constructs in this library.
  • Other Types - All non-construct classes, interfaces, structs and enums that exist to support the constructs.

Module Tests

The tests for the library should follow the same structure as the src folder.

How to publish a new version

After your branch has been merged into master:

  1. Push your feature onto master
  2. Tag your commit, like so: git tag -a v<major>.<minor>.<patch> -m "<major>.<minor>.<patch>" -- eg. git tag -a v0.31.14 -m "0.31.14" (comment here is very important)
  3. Push tag to master git push --tags origin master

Gitlab pipeline will publish new version.

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests

Examples

Prerequisites

These variables are used to namespace all resources, generate stack names, tags and to ensure that the correct base infrastructure is targeted. They form the base of a GenieStack type.

❗ Required variables include:

  1. executionEnvironment
  2. featureEnvironment
  3. application
  4. service
  5. version

You can read more about environment strategy on the wiki.

Example 1

This example creates an empty stack in which to build upon.

// The GDK includes a util module that allows developers to map environment variables to variables
export const configFromEnv =
  fromEnv({
    executionEnvironment: "EXECUTION_ENVIRONMENT",
    featureEnvironment: "FEATURE_ENVIRONMENT",
    application: "APPLICATION",
    service: "SERVICE",
    version: "VERSION",
    containerImage: "CONTAINER_IMAGE"
  });

// The service stack where everything is created
export class MyWebServiceStack extends GenieStack {
  constructor(scope: Construct, id: string, props: BaseServiceStackProps) {
    super(props, scope, id);

  }
}

const app = new App();

// Service stack is instantiated with the properties pulled from environment variables
new MyWebServiceStack(app, "MyWebServiceStack", {
  ...configFromEnv
});

app.synth();

Example 2

Building upon Example 1, this code contains a number of constructs in use, GenieFargateTaskDefinition and GenieFargateService. You will notice that props is passed around to each construct. This variable contains the minimum required variables as mentioned in Prerequisites, which again helps namespace, tag and target the correct infrastructure.


export class MyWebServiceStack extends GenieStack {
  constructor(scope: Construct, id: string, props: BaseServiceStackProps) {
    super(props, scope, id);

    const myWebServiceTaskDef = new GenieFargateTaskDefinition(this, "EcsTaskDefinition", {
      ...props,
      memoryLimitMiB: 1024,
      cpu: 512,
    });

    myWebServiceTaskDef.addGenieContainer("MyWebContainer", {
      imageName: configFromEnv.containerImage,
      port: 8086,
      cpu: 512,
      memoryLimitMiB: 1024,
      environment: {
        "THIRD_PARTY_API_URL": "http://www.somethirdparty.com/api/v2"
      },
      ...props
    });

    new GenieFargateService(this, "EcsService", {
      ...props,
      taskDefinition: myWebServiceTaskDef,
      desiredCount: 2,
      isPublic: true,
      healthCheck: {
        path: "/health",
        port: "8086"
      }
    });
  }
}

版本与发布记录

@genie-solutions/gdk 共发布 89 个版本,首次发布于 2020/04/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2022/05/104 年前
0.40.32022/04/074 年前
0.40.22022/04/074 年前
0.40.12021/06/305 年前
0.35.02020/09/306 年前
0.34.42020/09/236 年前

关于 @genie-solutions/gdk 的常见问题

@genie-solutions/gdk 是什么?

Common AWS CDK constructs for Genie

如何安装 @genie-solutions/gdk?

在项目目录运行 npm install @genie-solutions/gdk,或使用 pnpm add / yarn add / bun add。

@genie-solutions/gdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@genie-solutions/gdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@genie-solutions/gdk 可以商用吗?

@genie-solutions/gdk 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@genie-solutions/gdk 的下载量有多少?

根据 npm 官方下载统计,@genie-solutions/gdk 在 2026/10/16 – 2026/11/14 这 30 天内被下载 4,718 次,日均约 157 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@genie-solutions/gdk 还在维护吗?

最新版本 1.0.1 发布于 2022/05/10(4 年前);至今共发布 89 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/04/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。