[英]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.