-
Notifications
You must be signed in to change notification settings - Fork 4.4k
(cdk-events): RuleTargetInput.fromText inserts escape characters when it should not #18695
Description
What is the problem?
When creating a scheduled Events.Rule for a Events.Targets.LambdaFunction with Events.RuleTargetInput, Events.RuleTargetInput.FromText mytext puts double quotation marks around mytext and escapes double quotation marks in mytext. This modified string is passed on to the event target and is also visible in the EventBridge console.
This means Events.RuleTargetInput.FromText mytext cannot be used to pass json to a lambda function. Which I thought was its intended purpose.
Reproduction Steps
Sorry, the below is dotnet F#. But it should be straightforward to reproduce it in other languages.
- Create a lambda function and an event rule by the following code:
let request = """{"Action": "Test"}"""
let ruleLambdaProps = Events.Targets.LambdaFunctionProps (Event = Events.RuleTargetInput.FromText request)
let ruleProps = Events.RuleProps (
Schedule = Events.Schedule.Cron(Events.CronOptions(Minute = "0")),
Targets = [|Events.Targets.LambdaFunction (testLambda, ruleLambdaProps)|])
do Events.Rule (this, "TestRule", ruleProps) |> ignore
- Check TestRule in the EventBridge console.
What did you expect to happen?
In the EventBridge console, when I edit the rule, under "Configure input", I expect to see {"Action": "Test"}
What actually happened?
I do see "{\"Action\": \"Test\"}"
CDK CLI Version
2.8.0
Framework Version
2.8.0
Node.js Version
v16.13.1
OS
Windows 11
Language
.NET
Language Version
dotnet (6)
Other information
No response