
theonestack/cfhighlanderCfhighlander是一款面向CloudFormation模板开发者的功能丰富的DSL工具,旨在通过组件化方式简化AWS基础设施的编码工作。它允许开发者将AWS资源或资源集抽象为组件,通过Cfhighlander DSL和cfndsl进行描述,支持组件的继承与组合,实现模板的高效生成、验证和发布。
适用于需要管理复杂AWS基础设施的开发者,尤其适合:
通过RubyGems安装:
shellgem install cfhighlander
创建application.cfhighlander.rb文件:
rubyCfhighlanderTemplate do # 显式配置VPC组件 vpc_config = { 'maximum_availability_zones' => 2 } # 声明VPC组件并传递参数 Component name: 'vpc', template: '***', config: vpc_config do parameter name: 'Az0', value: FnSelect(0, FnGetAZs()) parameter name: 'Az1', value: FnSelect(1, FnGetAZs()) parameter name: 'DnsDomain', value: 'example.com' parameter name: 'StackMask', value: '16' end # 编译后的CloudFormation模板会自动将VPC的计算子网传递给ECS集群 Component name: 'ecs', template:'***' do parameter name: 'DnsDomain', value: 'example.com' end # 添加环境类型映射 addMapping('EnvironmentType',{ 'development' => { 'MaxNatGateways'=>'1', 'EcsAsgMin' => 1, 'EcsAsgMax' => 1, 'KeyName' => 'default', 'InstanceType' => 't2.large', 'SingleNatGateway' => true } }) end
编译模板:
shellcfcompile application
查看生成的模板中自动处理的子网参数传递:
shellcat out/yaml/application.compiled.yaml | grep -A3 SubnetCompute0
theonestack组织提供了多个公开可用的组件:
Cfhighlander DSL通过四个阶段生成CloudFormation模板:
安装后可通过cfhighlander命令使用,主要命令包括:
bashcfhighlander commands: cfhighlander cfcompile component[@version] -f, --format=FORMAT # 编译Highlander组件为CloudFormation模板 cfhighlander cfpublish component[@version] -f, --format=FORMAT # 发布CloudFormation模板及其引用的子组件 cfhighlander configcompile component[@version] # 编译Highlander组件配置 cfhighlander dslcompile component[@version] -f, --format=FORMAT # 编译组件配置并创建cfndsl模板 cfhighlander help [COMMAND] # 显示命令帮助 cfhighlander publish component[@version] [-v published_version] # 发布组件源代码
cfcompile:生成指定格式(默认yaml)的CloudFormation模板,可通过--validate选项验证模板
shellcfcompile application --format yaml --validate
cfpublish:生成并发布模板到S3,自动创建启动CloudFormation栈的URL
shellcfpublish vpc@1.2.0 --dstbucket my-templates-bucket --dstprefix published-templates
组件配置有四个层级(优先级从低到高):
component.config.yamlcomponents键或单独的component.config.yaml文件Component语句的config参数config_export导出的全局或组件特定配置rubyCfhighlanderTemplate do # 基本用法 Component 'vpc' # 指定版本和名称 Component name: 'ecs_cluster', template: '***' # 条件组件(功能开关) Component name: 'optional_bastion', template: 'bastion', conditional: true, enabled: false end
rubyCfhighlanderTemplate do Parameters do # 组件参数(可从外部组件传入或自动连接) ComponentParam 'BucketName', 'default-value', isGlobal: true # 映射参数(从外部组件映射中获取值) MappingParam 'InstanceType' do map 'EnvironmentType' key 'Environment' attribute 'InstanceType' end end end
ruby# Inline模式示例 Component name: 'vpc', template: 'vpc@latest', render: 'Inline'
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务