Home > Mobile >  How to send AWS templated email from cli
How to send AWS templated email from cli

Time:08-21

I am trying to send templated email with command:

aws ses send-templated-email --source "[email protected]" --destination "[email protected]" --template-data "{ "firstName": "temp", "lastName": "temp" }" --cli-input-json file://temp.json

but I do not know why I get the following error

Invalid type for parameter Template, value: {'TemplateName': 'temp', 'SubjectPart': 'Greetings!', 'HtmlPart': '<h3>Dear {{firstName}} {{lastName}}</h3>', 'TextPart': ''}, type: <class 'dict'>, valid types: <class 'str'>

The template file content is exactly like this

{
    "Template": {
        "TemplateName": "temp",
        "SubjectPart": "Greetings!",
        "HtmlPart": "<h3>Dear {{firstName}} {{lastName}}</h3>",
        "TextPart": ""
    }
}

I do not know what I am doing wrong. How it should be correcltly done with send-templated-email command?

CodePudding user response:

You need to create the template first with aws ses create-template. You can't specify the template at runtime. After you create the template, you would reference the data like this:

aws ses send-templated-email --cli-input-json file://template-values.json

With template-values.json looking something like:

{
  "Source": "<[email protected]>",
  "Template": "temp",
  "Destination": {
    "ToAddresses": ["[email protected]"]
  },
  "TemplateData": "{ \"firstName\":\"temp\", \"lastName\": \"temp\" }"
}

AWS Ref

  • Related