How to use !Sub with PinPoint EmailTemplate DefaultSubstitutions?

0

Hello, I'm trying to have template parameters passed onto a Pinpoint EmailTemplate resource as DefaultSubstitutions for the HtmlPart property.

Most attempts give me an invalid json message during the cloudformation processing (using sam deploy from cli).

DefaultSubstitutions: !Sub "{\"S\":\"${S}\",\"H\":\"${H}\",\"F\":\"${F}\"}"

ends up rejected as: DefaultSubstitution is not a valid JSON

Temporarily simplifying it to

DefaultSubstitutions: !Sub "{\"S\":\"${S}\"}"

ended up processed as:

"DefaultSubstitutions": {
  "Fn::Sub": "{\"S\":\"${S}\"}"
},

Help! Thanks

  • Updated the post to include the actual target goal, and the simplified (getting to the bottom of it) tests :-)

2 Answers
0

So what do you want it to end up processed as? I see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-pinpoint-emailtemplate.html#cfn-pinpoint-emailtemplate-defaultsubstitutions describes this property as a String that's a JSON object. What you've got above looks valid for that.

Also have you had a look at https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ToJsonString.html? It's interesting in that it shows JSON objects in the same format. Also it might be useful, but maybe overkill for such a simple object.

EXPERT
answered 9 months ago
  • Thanks for your answer.

    I was expecting:

    "DefaultSubstitutions": {
      "S": { "Fn::Sub": "${S}" },
      "H": { "Fn::Sub": "${H}" },
      "F": { "Fn::Sub": "${F}" }
    },
    

    I'll read through the links you've shared (thanks for those)

  • so I've tried:

    DefaultSubstitutions: Fn::ToJsonString: { "S": !Sub "${S}", "H": !Sub "${H}", "F": !Sub "${F}", }
    

    i get the error message:

    Nested mappings are not allowed in compact mappings (YAML)

    Incorrect type. Expected "string" (yaml-schema: DefaultSubstitutions)

  • also tried:

    DefaultSubstitutions: !Join ['', [ '{', '"S":', !Sub "${S}", '"H":', !Sub "${H}", '"F":', !Sub "${F}" '}' ]]
    

    which errors with: Incorrect type. Expected "string". (yaml-schema: DefaultSubstitutions)

0

I'm slowly coming to the conclusion that pinpoint is broken :-( My last attempt before giving up, the "long" form:

      DefaultSubstitutions: >
        {
          "S": { "Fn:Sub": "${S}" },
          "H": { "Fn:Sub": "${H}" },
          "F": { "Fn:Sub": "${F}" }
        }

goes through with no complaints from cloudformation, but I end up with this kind of substitutions in the outgoing email:

{Fn:Sub="${S}"}
{Fn:Sub="${H}"}
{Fn:Sub="${F}"}

which is really sad :-(

answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions