0
votes

I'm trying to trigger Email using SES and API gateway without using Lambda function. It will contain pdf file and text. I'm able to trigger Email using QueryString parameters, but as i need to send files also I want to map from the body. Tried body mapping in API-gateway as below,

BODY MAPPING TEMPLATE { 'Destination': { ToAddresses:'[email protected]' }, 'Message': { 'Body': { 'Text': { 'Data': 'message body ! hurray !!!', 'Charset': 'UTF-8' } }, 'Subject': { 'Data': 'subject data', 'Charset': 'UTF-8' } }, 'Source': '[email protected]' }

RESPONSE FROM SES

`{
  "Output": {
  "__type": "com.amazon.coral.service#SerializationException",
  "Message": null
 },
 "Version": "1.0"
 }`

Questions

  1. Is it possible to achieve this without using lambda?
  2. Am I using the body mapping correctly?

    Could anyone please throw light on how to achieve this? Any help highly appreciated.

1

1 Answers

1
votes

I got stuck on the same problem and finally made it. I'll share what I learned.

According to this document, request body should be in form of x-www-form-urlencoded, such as:

Action=SendRawEmail
&Destinations.member.1=allan%40example.com
&RawMessage.Data=RnJvbTp1c2VyQGV4YW1wbGUuY29tDQpTdWJqZWN0OiBUZXN0DQoNCk1lc3 ...

Also you have to set Content-Type:application/x-www-form-urlencoded header. If not, it causes exception. With this header, you can't send request with query parameter(since it includes ?) , you also have to set "Action Type" to "Use path override" and "/" in Integration Request section of API gateway console.

I also confirmed that I could send email with attachments using SendRawEmail action.

So my answer to original questions:

  1. Is it possible to achieve this without using lambda? => Yes!
  2. Am I using the body mapping correctly? => No, you have to use x-www-form-urelencoded request body.

Hope this will help.