如何创建多个 CloudFormation 堆栈,其中一个参数更改?

huangapple go评论53阅读模式
英文:

How to create multiple cloudformation stacks where a single parameter changes?

问题

我想将城市列表作为参数输入到 SAM 模板中。例如:伦敦、纽约、迪拜。列表可能包含大量城市,比如说 50 个。

使用这个城市列表,我想为每个城市创建一个相应的日志组。例如:

  • /aws/ecs/迪拜
  • /aws/ecs/伦敦
  • /aws/ecs/纽约

我该如何实现这个?

英文:

I want to enter a list of cities as parameters to a SAM template. For Example: London, New York, Dubai. The list can have a large number of cities, say 50.

Using this list of cities, I want to create a log group pertaining to each city. For example:

  • /aws/ecs/Dubai
  • /aws/ecs/London
  • /aws/ecs/New York

How can I achieve this?

答案1

得分: 2

你可以在Cloudformation中使用Count Macro

AWSTemplateFormatVersion: "2010-09-09"
Transform: Count
Resources:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/ecs/%s
Count: ['Dubai','London','NewYork']

更多信息请查看此问题:https://stackoverflow.com/questions/57195157/how-to-loop-through-values-in-a-cloudformation-template

英文:

You can use Count Macro in Cloudformation.

AWSTemplateFormatVersion: "2010-09-09"
Transform: Count
Resources:
   Type: AWS::Logs::LogGroup
   Properties: 
       LogGroupName: /aws/ecs/%s
   Count: ['Dubai','London','NewYork']

For more information check this question: https://stackoverflow.com/questions/57195157/how-to-loop-through-values-in-a-cloudformation-template

答案2

得分: 1

我最终在CloudFormation中使用了Explode宏来解决这个问题:

https://github.com/awslabs/aws-cloudformation-templates/tree/master/aws/services/CloudFormation/MacrosExamples/Explode

英文:

I eventually used the Explode macro in CloudFormation to solve this problem:

https://github.com/awslabs/aws-cloudformation-templates/tree/master/aws/services/CloudFormation/MacrosExamples/Explode

huangapple
  • 本文由 发表于 2023年2月16日 18:30:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470944.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定