GDK - AWS CDK 的 Genie 构造库
用于将 AWS 资源部署到 Gentu 和 平台 的一组可重复使用的构造 .
安装
将此库安装到您的工程中
$ npm i @genie-solutions/gdk
依赖关系
关键是:
主要版本 1.0.0 使用 AWS CDK 2.0.0 版本构建. 如果您正在使用此库新鲜度, 请使用库的 1. 0.0 版本和 AWS CDK 的 2. 0.0+ 版本 。 支持版本0.40.0的遗产指示仍保留在下.
只有立法支持
这个库使用AWS CDK的1.151.0版本来构建. 为了保证您能够使用 Cdk 和这个库, 请将您的 cdk 版本固定 .
$ npm i -g [email protected]
如果您在工程中使用本地的 CDK 软件包, 请确保您使用同一版本 。 示例: S3 软件包...
$ npm install @aws-cdk/[email protected]
结构
模块
GDK库被组织成几个模块,但被包装成单一资产. 项目结构如下:
- src/xxx:xxxx代表AWS CDK包名称的服务组件. 示例:src/ec将包含作为aws-ec构造扩展的构造.
- src/base-infra:其中包含基础基础设施构造,是进口本土的"云形"模板.
模块内容
模块包含以下类型:
- 构造 - 本库中的所有更高层次的构造 .
- 其他类型 - 所有支持构造而存在的非构造类,界面,构造和enum.
模块测试
对库的测试应当遵循与src文件夹相同的结构.
如何发布新版本
在您的分支合并为主后 :
- 把您的特性推到主机上
- 标记你的承诺,像这样:
git tag -a v<major>.<minor>.<patch> -m "<major>.<minor>.<patch>"- 举起手来.git tag -a v0.31.14 -m "0.31.14"(这里的评论非常重要) - 将标签推向主机
git push --tags origin master
Gitlab管道将发布新版本.
有用命令
npm run build将打字符编译为 jsnpm run watch监视更改并编译npm run test进行滑稽单元测试
实例
先决条件
这些变量被用来命名所有资源,生成堆栈名,标记,并确保正确的基建被锁定. 它们组成了GenieStack类型的基础.
❗ 所需变量包括:
- 环境
- 特性环境
- 应用程序
- 服务
- 版本
你可以读更多关于 维基百科的环境策略。 。 。 .
实例1
此示例创建了可依存的空堆栈 .
// 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();
实例2
基于例1,本代码包含一些正在使用的构造,GenieFargateTaskDefinition和GenieFargateService. 你会注意到道具被传递到每个构造中 此变量包含Prerequists中提及的最小要求变量,这再次帮助命名空间,标记和瞄准正确的基础设施.
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"
}
});
}
}