AWS EC2 有 dsl 吗?

发布于 2024-12-27 13:18:04 字数 114 浏览 5 评论 0原文

我正在考虑使用 Amazon 云服务(EC2、S3 等)进行托管。我一直在研究可指定用于配置各种实例的 JSON 元数据,其复杂性令我担忧。是否有一个 dsl 可以生成有效的 JSON 元数据,更重要的是验证条目?

I am looking at using Amazon cloud services (EC2, S3 etc) for hosting. I've been looking at the JSON metadata that can be specified to configure various instances and the complexity has me concerned. Is there a dsl that will generate valid JSON metadata and more importantly validate the entries?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

掐死时间 2025-01-03 13:18:05

不幸的是,我最近搜索后一片空白。我正在使用 Amazon Web Services CloudFormation(这是您所说的 JSON 元数据吗?)。

CloudFormation JSON 文件存在几个问题:

  1. 超过 1,500 行,无法阅读;
  2. 您无法表达 API 为您提供的所有内容,特别是在虚拟私有云领域;
  3. 存在很多错误需要很长时间才能修复,例如弹性负载均衡器丢失 HTTPS 信息。

因此,我一直在 Scala 中使用 Java API 进行直接 API 调用。实际上真的很好。

Java API 具有以 with 开头的“setter”风格,返回 this,以便将它们链接起来。在 Scala 中,您可以使用它们来充当穷人的 DSL。因此,您可以

val updateRequest = new UpdateAutoScalingGroupRequest()
                    .withAutoScalingGroupName(group.getAutoScalingGroupName)
                    .withAvailabilityZones(subnetAZsOfOurVPC)
                    .withVPCZoneIdentifier(subnetNamesOfOurVPC)

as.updateAutoScalingGroup(updateRequest)

使用 Java API 在 Scala 中做其他事情很容易做之类的事情。例如,在地图中按 VPC 将所有子网分组,只需执行以下操作

val subnetsByVPC = ec2.describeSubnets(new DescribeSubnetsRequest).getSubnets.groupBy(_.getVpcId)

Unfortunately, I drew a blank after searching for this recently. I'm using Amazon Web Services CloudFormation (is that the JSON metadata you're talking about?).

There are a couple of issues with CloudFormation JSON files:

  1. I'm at well over 1,500 lines and it's impossible to read,
  2. You can't express everything the API gives you, notably in the area of Virtual Private Clouds,
  3. There are lots of bugs that are taking a long time to fix, Elastic Load Balancers losing HTTPS information, for example.

So I've been using straight-up API calls in Scala using the Java API. It's actually really nice.

The Java API has a flavor of "setters" starting with with that return this so they can be chained. In Scala, you can use these to act like a poor-man's DSL. So you can do things like

val updateRequest = new UpdateAutoScalingGroupRequest()
                    .withAutoScalingGroupName(group.getAutoScalingGroupName)
                    .withAvailabilityZones(subnetAZsOfOurVPC)
                    .withVPCZoneIdentifier(subnetNamesOfOurVPC)

as.updateAutoScalingGroup(updateRequest)

Other things are easy to do in Scala with the Java API. For example, group all your Subnets by VPC in a Map, simply do

val subnetsByVPC = ec2.describeSubnets(new DescribeSubnetsRequest).getSubnets.groupBy(_.getVpcId)
琴流音 2025-01-03 13:18:05

如果有人仍在寻找 AWS CloudFormation DSL - 我们一直在使用用于 CloudFormation 的 Ruby DSL< /a>:

https://github.com/bazaarvoice/cloudformation-ruby-dsl

  • 这个简洁的项目提供了一个工具,可以将现有的 CloudFormation 模板转换为 Ruby DSL
  • 它将生成有效的 JSON 输出
  • 验证 Ruby 模板条目类似于验证常规 CloudFormation 模板(请参阅cfn-validate-template
  • 您的模板变成 Ruby 代码,因此很容易拥有可重用模块 (DRY
  • )可以定义局部变量
  • 您可以在 DSL 模板中添加注释
  • 大大提高了可读性
  • 大大减小了 DSL 模板大小

CloudFormation 请求模板正文 大小限制很烦人 - 我们必须将大型 CloudFormation 模板上传到 S3,然后使用其 S3 URL 创建/更新堆栈。

In case anyone is still looking for the AWS CloudFormation DSL - we've been using the Ruby DSL for CloudFormation:

https://github.com/bazaarvoice/cloudformation-ruby-dsl

  • This neat project provides a tool to convert your existing CloudFormation template(s) to the Ruby DSL
  • It will generate valid JSON output
  • Validating Ruby template entries is similar to validating a regular CloudFormation template (see cfn-validate-template)
  • Your template becomes Ruby code, so it's easy to have reusable modules (DRY)
  • You can define local variables
  • You can have comments in your DSL template
  • Greatly improved readability
  • Greatly reduced DSL template size

The CloudFormation request template body size limits are annoying - we have to upload our large CloudFormation templates to S3, then create/update stacks using their S3 URLs.

﹏半生如梦愿梦如真 2025-01-03 13:18:05

现在,虽然我还没有使用它:Coffin a CoffeeScript DSL for CloudFormation。

如果您不是在谈论 CloudFormation,而是在谈论更通用的 API,那么我发现的最好的界面是 AWS 自己的 aws-sdk ruby​​ gem。与他们发布的其他 SDK 不同,这些 SDK 的 make-client/make-request/get-response/look-at-result 事务做得很好,但很粗糙,Ruby SDK 在顶部封装了一个更好的域模型,因此您可以通过更高抽象级别的集合进行交互

它还具有相当好的性能功能,如果您知道不需要新的响应,您可以缓存响应以节省往返时间。

There is now, though I haven't used it yet: Coffin a CoffeeScript DSL for CloudFormation.

If you're not talking about CloudFormation, but instead more general API talking, then the nicest interface I've found is AWS' own aws-sdk ruby gem. Unlike the other SDKs that they publish which are quite nicely-done-but-crude make-client/make-request/get-response/look-at-result affairs, the ruby SDK wraps a nicer domain-model over the top, so you interact via collections at a higher abstract level.

It also has quite-nice performance features in that you can cache responses to save on round-trips, if you know you don't need fresh responses.

魔法唧唧 2025-01-03 13:18:05

我的 CloudFormation 模板超过 3000 行。我发现在 JSON 中添加注释非常有帮助!您只需在使用前将其剥离即可。有一个验证器可以验证模板并删除注释: http://cloudformation-validation.com/

I have CloudFormation templates upwards of 3000 lines. I have found that putting comments in the JSON helps tremendously!! You just have to strip it out before using it. There is a validator that would validate the template and strip out the comments: http://cloudformation-validation.com/

千仐 2025-01-03 13:18:05

不,截至 2022 年 2 月,AWS 仍然没有为基础设施即代码提供任何特定于领域的语言。它们与 Azure 的 BicepTerraform 的 HCL

这确实让我感到惊讶,因为我通常认为 AWS 比其他主要竞争对手(Azure 和 GCP)更昂贵,但处于领先地位。

但是,Cloud Formation 现在支持 JSON 和 YAML 格式。略有改善??恕我直言,当您拥有代表整个云堆栈的整个存储库时,情况并非如此。如果您使用 AWS,请使用 Terraform 来管理 IaC。

No, as of Feb 2022, AWS still does not provide any domain-specific language for infrastructure as code. They have nothing similar to Azure's Bicep or Terraform's HCL.

This really surprises me, as I generally think of AWS as being more expensive, but ahead of the curve, compared to other major competitors (Azure and GCP).

However, Cloud Formation now allows both JSON and YAML formats. Slight improvement?? IMHO, not really when you have an entire repo that represents your entire cloud stack. If you're using AWS, use Terraform to manage IaC.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文