gpt4 book ai didi

amazon-web-services - 将字符串转换为 CommaDelimitedList Cloudformation 模板

转载 作者:行者123 更新时间:2023-12-03 07:36:18 24 4
gpt4 key购买 nike

我有以下 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 的内部函数。从用户指南复制:

The following example splits a string at each vertical bar (|). The function returns ["a", "b", "c"].

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

所以在你的例子中,我想它会转化为

!Split [ ",", !Ref AWSInstanceID ]

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

Parameters:
AWSInstanceID:
Type: CommaDelimitedList

关于amazon-web-services - 将字符串转换为 CommaDelimitedList Cloudformation 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56212846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com