Skip to content

(cdk-events): RuleTargetInput.fromText inserts escape characters when it should not #18695

@Martin521

Description

@Martin521

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.

  1. 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

  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-eventsRelated to CloudWatch EventsbugThis issue is a bug.cause/not-a-bugNot a bug (might still be a documentation issue, might still need work)effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions