繁体   English   中英

将字符串转换为CommaDelimitedList Cloudformation模板

[英]Convert String to CommaDelimitedList 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

但是,AWSInstanceID转换为:

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

但这不是我想要的格式。 如何获得以下输出?

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

我想从String转换为CommaDelimitedList。

CloudFormation具有一个称为Fn :: Split的内部函数。 从用户指南中复制:

下面的示例在每个竖线(|)处分割字符串。 该函数返回[“ a”,“ b”,“ c”]。

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

所以在您的情况下,我想它会转换为

!Split [ ",", !Ref AWSInstanceID ]

或者,您也可以尝试将AWSInstanceID指定为CommaDelimitedList类型,例如

Parameters:
  AWSInstanceID:
    Type: CommaDelimitedList

参数-AWS CloudFormation

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

Amazon EC2实例ID的数组,例如i-1e731a32,i-1e731a34。

因此,尝试从以下位置更改参数:

Type: String

至:

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM