如何在Cloudformation中指定JSON格式的字符串? [英] How to specify JSON-formatted string in Cloudformation?
问题描述
我在CloudFormation模板上拥有以下资源,可从AWS文档中创建运行Lambda函数的规则:
I have the following resource on my CloudFormation template to create a rule to run a Lambda function, from the AWS documentation:
"ScheduledRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "ScheduledRule",
"ScheduleExpression": "rate(5 minutes)",
"State": "ENABLED",
"Targets": [{
"Arn": { "Fn::GetAtt": ["myLambda", "Arn"] },
"Id": "TargetFunctionV1"
}]
}
}
我想指定输入:
{
"Arn" : String,
"Id" : String,
"Input" : String,
"InputPath" : String
}
and Input是传递给目标的JSON格式的文本字符串.此值将覆盖匹配的事件.
and Input is a JSON-formatted text string that is passed to the target. This value overrides the matched event.
我希望JSON格式的文本为:
I would like my JSON formatted text to be:
{
"mykey1": "Some Value"
}
输入时,我不知道如何在输入中指定它:
I do not know how to specify it in the Input, when I put:
"ScheduledRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "ScheduledRule",
"ScheduleExpression": "rate(5 minutes)",
"State": "ENABLED",
"Targets": [{
"Arn": { "Fn::GetAtt": ["myLambda", "Arn"] },
"Id": "TargetFunctionV1",
"Input": { "mykey1": "Some Value" }
}]
}
}
我会收到错误消息:
Value of property Input must be of type String
我应该如何正确指定它?
How should I specify it correctly?
推荐答案
我自己找到了答案:
输入":"{\"test \":\"value11 \",\"test2 \":\"value22 \"}"
"Input": "{ \"test\" : \"value11\", \"test2\" : \"value22\"}"
希望它对其他人有帮助.
Hope it helps someone else.
更新:
您基本上使用JSON.Stringify()的结果将字符串放入输入"字段.使用在线JSON.Stringify(),例如 https://onlinetexttools.com/json-stringify-text
You basically use the result of JSON.Stringify() to get the string into "Input" field. Use online JSON.Stringify() like https://onlinetexttools.com/json-stringify-text
这篇关于如何在Cloudformation中指定JSON格式的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!