Search code examples
amazon-web-servicesaws-cliamazon-seslocalstack

Using conditionals in AWS SES templates doesn't work (MissingRenderingAttributeException)


I am trying to use conditionals in SES templates by following this guideline: https://docs.aws.amazon.com/ses/latest/dg/send-personalized-email-advanced.html

I should be able to create a template with dynamic content based on the value of the variable evaluation result. Still, no matter what I do, I keep getting a 'MissingRenderingAttributeException' error.

For local development I use localstack on docker.

The aws-localstack is an alias I set for communicating with the AWS CLI localstack provides

This is the test I'm running:

aws-localstack ses create-template --cli-input-json '{
    "Template": {
        "TemplateName": "test_conditionals",
        "SubjectPart": "TESTING CONDS",
        "TextPart": "{{#if lastName}}[{{lastName}}]{{/if}}",
        "HtmlPart": "{{#if lastName}}[{{lastName}}]{{/if}}"
    }
}'

aws-localstack ses test-render-template --cli-input-json '{
    "TemplateName": "test_conditionals",
    "TemplateData": "{\"lastName\":\"test-result\"}"
}'

I keep getting this error:

An error occurred (MissingRenderingAttributeException) when calling the TestRenderTemplate operation: Attribute '#if lastName' is not present in the rendering data.

How do I fix it? What am I missing?

Any suggestion would be appreciated :)


Solution

  • I found the problem, it has nothing to do with AWS, but with localstack There are many features missing in localstack library, one of them is conditionals support

    I thought about deleting this topic, but in favor of everyone who expects it to behave the same on local env by using localstack, I thought it is worth having such topic in SO, because I had to work "harder" to figure it out