简体   繁体   English

将字符串转换为CommaDelimitedList Cloudformation模板

[英]Convert String to CommaDelimitedList Cloudformation Template

I have the following Cloudformation Template: 我有以下Cloudformation模板:

AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  serviceRoleArn:
    Type: String
    Description: The role that's used when the task is executed.
  AWSInstanceID:
    Type: String
  awsSSMMaintenanceWindowTargetId:
    Type: String
  awsSSMMaintenanceWindowId:
    Type: String
  automationSSMTaskRole:
    Type: String
  automationSSMTaskType:
    Type: String
  automationSSMTaskDescription:
    Type: String
  automationSSMTaskARN:
    Type: String

Resources:
  startInstanceTask:
    Type: 'AWS::SSM::MaintenanceWindowTask'
    Properties:
      MaxErrors: "2"
      Description: !Ref "automationSSMTaskDescription"
      ServiceRoleArn:
        Ref: serviceRoleArn
      Priority: 1
      MaxConcurrency: "1"
      Targets:
      - Values:
        - !Ref "awsSSMMaintenanceWindowTargetId"
        Key: WindowTargetIds
      Name: !Ref "automationSSMTaskType"
      TaskArn: !Ref "automationSSMTaskARN"
      WindowId: !Ref "awsSSMMaintenanceWindowId"
      TaskType: "AUTOMATION"
      TaskInvocationParameters:
        MaintenanceWindowAutomationParameters:
          DocumentVersion: "$DEFAULT"
          Parameters:
            InstanceId:
              - !Ref AWSInstanceID
            AutomationAssumeRole:
              - Ref: automationSSMTaskRole

However, AWSInstanceID is converting to: 但是,AWSInstanceID转换为:

"InstanceId": ["i-0375357htn1a8ad40,i-0d0f0f724tytf4d37,i-0e61cc61hthf8c2b2"]

But this is not the format I want. 但这不是我想要的格式。 How do I get the following output? 如何获得以下输出?

"InstanceId": [
    "i-0375357htn1a8ad40",
    "i-0d0f0f724tytf4d37",
    "i-0e61cc61hthf8c2b2"
]

I would like to convert from String to CommaDelimitedList. 我想从String转换为CommaDelimitedList。

CloudFormation has an intrinsic function called Fn::Split . CloudFormation具有一个称为Fn :: Split的内部函数。 Copied from the user guide: 从用户指南中复制:

The following example splits a string at each vertical bar (|). 下面的示例在每个竖线(|)处分割字符串。 The function returns ["a", "b", "c"]. 该函数返回[“ a”,“ b”,“ c”]。

!Split [ "|" , "a|b|c" ]

So in your case, I guess it translates to 所以在您的情况下,我想它会转换为

!Split [ ",", !Ref AWSInstanceID ]

Alternatively, you could also try and specify the AWSInstanceID as a CommaDelimitedList type, eg 或者,您也可以尝试将AWSInstanceID指定为CommaDelimitedList类型,例如

Parameters:
  AWSInstanceID:
    Type: CommaDelimitedList

From Parameters - AWS CloudFormation : 参数-AWS CloudFormation

List<AWS::EC2::Instance::Id>

An array of Amazon EC2 instance IDs, such as i-1e731a32, i-1e731a34. Amazon EC2实例ID的数组,例如i-1e731a32,i-1e731a34。

So, try changing your Parameter from: 因此,尝试从以下位置更改参数:

Type: String

to: 至:

Type: List<AWS::EC2::Instance::Id>

暂无
暂无

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

相关问题 CloudFormation:是否可以 Fn::Join 一个 CommaDelimitedList 和一个字符串? - CloudFormation: Is it possible to Fn::Join a CommaDelimitedList and a String? AWS Cloudformation - 将 CommaDelimitedList 参数转换为字符串以将其作为环境变量传递给 Lamda Function - AWS Cloudformation - Convert CommaDelimitedList Parameter to String for passing it as environment variable to Lamda Function 如何在 CloudFormation 模板中将字符串转换为大写 - How to convert string to uppercase in CloudFormation template Cloudformation:用于 ListenerCertificate 资源的证书 ARN 的逗号分隔列表 - Cloudformation: CommaDelimitedList of Cert ARNs for ListenerCertificate Resource 如何转换 CommaDelimitedList 参数以在 CloudFormation 中构建 ARN - How to transform CommaDelimitedList parameter to build ARNs in CloudFormation AWS:cloudformation CommaDelimitedList 和手动列表不匹配 - AWS: cloudformation CommaDelimitedList and manual list not matching CommaDelimitedList、fn:if 和 fn:select 的 AWS Cloudformation 组合 - AWS Cloudformation combination of CommaDelimitedList, fn:if and fn:select 在 Cloudformation 脚本中为 CommaDelimitedList 类型的参数强制执行 AllowedPattern - Enforce AllowedPattern for parameter of type CommaDelimitedList in Cloudformation script 将 AWS CloudFormation 转换为 Terraform 模板 - Convert AWS CloudFormation to Terraform template 在传递CommaDelimitedList类型的参数值时看到AWS CLI Cloudformation错误 - Aws cli cloudformation error seen on passing parameter value of type CommaDelimitedList
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM