[英]CloudFormation: Is it possible to Fn::Join a CommaDelimitedList and a String?
[英]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
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.