简体   繁体   English

AWS CloudFormation:如何使用参数来形成字符串?

[英]AWS CloudFormation: how can I use parameters to form strings?

What I want to achieve is this:我想要实现的是:

AWSTemplateFormatVersion: "2010-09-09"
Description: deploy a full stack

Parameters:
  # Product Name:
  ProductName:
    Type: String
    Default: 'Docloud'
    Description: This is the string that will appear in the names of most resources. 
  # Environment Name:
  EnvName:
    Type: String
    Default: 'test-2'
    Description: This is the string that will appear in the names of most resources. 

  # EC2 instance: 
  InstanceName: 
    Type: String
    # Default: 'Earth-test-1'
    Default: 'Earth-${!ProductName}-${!EnvName}'

  # load balancing 
  NLBName:
    Type: String
    Default: 'NLB-${!ProductName}-${!EnvName}'
    Description: the name for Network Load Balancer

  TargetGroupName:
    Type: String
    Default: 'TG-${!ProductName}-${!EnvName}'
    Description: the name of the Target Group to which the traffic from the NLB goes

I want to define 2 parameters: ProductName and EnvName , and then these variables will appear throughout the template to automatically form strings such as 'TG-${ ProductName}-${ EnvName}' or 'NLB-${ ProductName}-${ EnvName}' , so that when I deploy a new stack one week later, I only need to modify ProductName and EnvName .我想定义 2 个参数: ProductNameEnvName ,然后这些变量将出现在整个模板中以自动形成字符串,例如'TG-${ ProductName}-${ EnvName}''NLB-${ ProductName}-${ EnvName}' ,这样一周后部署新栈时,只需要修改ProductNameEnvName

I have tried a couple things, but the above goal cannot be reached.我尝试了几件事,但无法达到上述目标。

Is this possible with CloudFormation now?现在使用 CloudFormation 可以吗?

No its not possible, you have to use a nested stack or Aws CDK to have composed variables.不,这是不可能的,您必须使用嵌套堆栈或 Aws CDK 来组合变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在 AWS Cloudformation json 模板的“参数”中使用“Fn::Join”吗 - Can I use "Fn::Join" in "Parameters" of AWS Cloudformation json template aws cloudformation 如何在映射块中使用条件? - aws cloudformation how can I use conditions in the mapping block? 我可以将AWS CloudFormation与自定义AMI一起使用吗? - Can I use AWS CloudFormation with a custom AMI? 我可以在AWS CloudFormation启动URL中设置参数吗? - Can I set the parameters in an AWS CloudFormation launch URL? 如何使用aws中的cloudformation在api网关中请求参数并将其传递给lambda函数? - How can I request parameters in api gateway using cloudformation in aws and pass it down to lambda function? 如何在 AWS Lambda 中加载 AWS Cloudformation 的 Output? - How Can I Load The Output of AWS Cloudformation In AWS Lambda? AWS CloudFormation CodeBuild:我可以使用 ECR 图像作为环境图像吗 - AWS CloudFormation CodeBuild: Can i use ECR image as Environment image 如何在CloudFormation模板中使用来自其他AWS账户的AssumeRole? - How can I use AssumeRole from another AWS account in a CloudFormation template? 如何在 AWS CloudFormation 的参数部分添加条件? - How to add conditions in Parameters section in AWS CloudFormation? 如何在Cloudformation模板参数中创建IAM角色下拉列表 - How can I create IAM Role Dropdown in Cloudformation Template Parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM