如何对目录中的模板进行 cloudformation 验证?

how to do cloudformation validation for templates in a directory?

我的 gitlab 存储库中有一些模板需要在传输到 S3 存储桶之前进行验证。我怎样才能让我的 gitlab ci 运行 整个模板目录的 cloudformation 而不是单独命名每个模板?

我在想类似的东西

for file in /templates/*.yml; do aws cloudformation validate-template --template-body file://$file > validation.log; done

关于如何在 gitlab 中执行此操作的任何想法 ci?

您可以使用 find/exec 命令简化此操作,同时将日志重定向到文件可能不是一个好主意,因为在作业输出中更容易看到它们。

使用安装了 aws 工具的 shell 运行器(或 docker 运行器),您可以拥有以下脚本块:

script:
  - find path_to_templates -type f -name "*.yml" -exec aws cloudformation validate-template --template-body file://{} \;

path_to_templates 替换为您在 repo 中的实际目录。它将对该目录中以 .yml 结尾的每个文件执行您的命令。