我有以下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。
答案 0 :(得分:1)
CloudFormation具有一个称为Fn::Split的内部函数。从用户指南中复制:
下面的示例在每个竖线(|)处分割字符串。该函数返回[“ a”,“ b”,“ c”]。
storage_name
所以对于您而言,我想它可以翻译为
!Split [ "|" , "a|b|c" ]
或者,您也可以尝试将!Split [ ",", !Ref AWSInstanceID ]
指定为CommaDelimitedList类型,例如
AWSInstanceID
答案 1 :(得分:0)
来自Parameters - AWS CloudFormation:
List<AWS::EC2::Instance::Id>
一系列Amazon EC2实例ID,例如i-1e731a32,i-1e731a34。
因此,请尝试从以下位置更改参数:
Type: String
收件人:
Type: List<AWS::EC2::Instance::Id>