gpt4 book ai didi

amazon-web-services - 在 cloudwatch 事件规则 cloudformation 中动态附加事件名称

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

这是我的云形成模板,它将事件模式传递到子堆栈,该子堆栈实际上根据事件数据创建规则。

cloudwatchRule:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub "${s3Path}/cw-rule.yml"
Parameters:
eventPattern: !Join
- ' '
- - '{"source":["aws.iam"],"detail-type":["AWS API Call via CloudTrail"],"detail":{"eventSource":["iam.amazonaws.com"],"eventName":['
- Fn::Split:
- ','
- !Sub ${ssmParamWhichContainsEventNames}
- ']}}'
ruleState: "ENABLED"

#The value of ssmParamWhichContainsEventNames is of format #"CreateServiceSpecificCredential,DeactivateMFADevice"

当我运行此程序时,出现以下错误

Template error: every Fn::Join object requires two parameters, (1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined.. Rollback requested by user.

我尝试了各种技术来格式化 !Join !Split !Sub 的顺序我也尝试过使用 Fn::Join (全函数格式),但它一直失败。

eventPattern 参数中的 eventName 需要以下格式的输入。

"eventName":["event1","event2","event3","event4"]

我的 SSM 变量的事件名称格式为 "event1,event2,event3..." 为了使其与 eventName 兼容并使 cloudwatch 规则运行,我'必须将 "event1,event2,event3..." 转换为 '"event1","event2","event3"...'

一种选择是将 SSM 转换为我可接受的格式,但由于某种原因,这是我想要避免的事情。

任何人都可以帮我找出将 "CreateServiceSpecificCredential,DeactivateMFADevice" 转换为 ' "CreateServiceSpecificCredential","DeactivateMFADevice"' 的方法(每个值都用双引号括起来)并将整个字符串括在单引号内

我一直感觉我没有按照正确的顺序正确编写上述代码中的内部函数。

最佳答案

以防有人仍在寻找如何实现它。下面是 cloudformation 模板片段,它将逗号分隔的字符串分割成一个由单个元素组成的数组,并注入(inject)到“eventName”属性中:

cloudwatchRule:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub "${s3Path}/cw-rule.yml"
Parameters:
eventPattern: !Sub
- |
{"source":["aws.iam"],"detail-type":["AWS API Call via CloudTrail"],"detail":{"eventSource":["iam.amazonaws.com"],"eventName":[
"${eventNames}"
]}}
- eventNames: !Join
- '","'
- !Split
- ','
- !Ref ssmParamWhichContainsEventNames
ruleState: "ENABLED"

关于amazon-web-services - 在 cloudwatch 事件规则 cloudformation 中动态附加事件名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58835355/

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