aws-cloudformation/cfn-language-discussion

Tracking Issue: Fn::ToJsonString RFC

mluk-aws opened this issue · 5 comments

Description

Provide an intrinsic function that converts an input template block into an escaped JSON string.

Original Issue: #53

Workflow

  • Tracking issue created (label: status/proposed)
  • RFC pull request submitted
  • Reviewers assigned (label: status/review)
  • Reviewers signed-off (label approved applied to pull request)
  • Final comments period (label: status/final-comments-period)
  • Approved and merged (label: status/approved)
  • Implementation started (label: status/implementing)
  • Implementation complete (label: status/done)

Author is responsible to progress the RFC according to this checklist, and
apply the relevant labels to this issue so that the RFC table in README gets
updated.

Hi have cases say it is not working at the moment

  EventPattern:
    Fn::ToJsonString:
      - test1: 'test2'
        test3: 'test4'

Stack will fail at the Transform stage with error "Transform AWS::LanguageExtensions failed with: Fn::ToJsonString resolve value type mismatch. Rollback requested by user."

Hey @jiemying,
thanks for bringing this up.

To unblock you: EventPattern supports Json objects natively. There is no need to use Fn::ToJsonString for the EventPattern attribute.

Hey @jiemying, thanks for bringing this up.

To unblock you: EventPattern supports Json objects natively. There is no need to use Fn::ToJsonString for the EventPattern attribute.

Hi, thx for coming back to me so promptly!

Yep I am aware of that, that was for reference.

The error happens at the Transform stage of the CloudFormation stack operation, no matter where I put the above test Fn::ToJsonString in the template's resources properties, the stack transform stage failed with the same error.

I suspect the object "type" passed to this intrinsic function in the back-end, does not match wanted object type of the code, hence the exception error throws. Look at the exception part of the code may be helpful.

Hey @jiemying,
if this happens even when you put Fn::ToJsonString somewhere else (where a String is expected), I would appreciate if you could provide an example template. If you still have it handy, any chance you could open a new issue in this same repo?

Close this issue as it's available via AWS::LanguageExtensions