4
votes

I'm setting up an API from an App which allows the App user to contact someone for follow-up, but hides the email address from the sender (and allows it to be changed without a new release of the App).

I've managed to setup an AWS API Gateway GET method which sends email directly via SES

https://...aws.com/em/send/en?body=The+email+is+here

Using a path override of

Action=SendEmail
&Source=source%40mydomain.org
&Destination.ToAddresses.member.1=follow.up%40anydomain.com
&Message.Subject.Data=Request+For+Followup
&Message.Body.Text.Data={body}

I would much prefer to use a POST method - but am really struggling to work out what should go in the Action parameter and how to create the mapping template - or even if it is possible to create an application/x-www-form-urlencoded request without having to resort to a lambda function - although the AWS documentation does include a $util.urlEncode() function.

http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

Edit:

I am trying to use a POST method to AWS Gateway and a POST to SES with the contents in the request body, but it is just not clear to me how to create the mapping template and I can't find any examples for SES.

Testing it with the mapping template (as per the example in the documentation)

Source=source%40mydomain.org
&Destination.ToAddresses.member.1=follow.up%40anydomain.com
&Message.Subject.Data=Request+For+Followup
&Message.Body.Text.Data=The+message+goes+here

And a content type application/x-www-form-urlencoded AWS gateway gives the error:

{
"message": "Unsupported Media Type"
}

If I use a mapping template

{
"Action":"SendEmail",
"Source":"[email protected]",
"Destination":{
    "ToAddresses":{
        "member":["[email protected]"]
        }
    },
"Message":{
    "Subject": {
        "Data":"Request For Followup"
        },
    "Body":{
        "Text":{
            "Data":"The message goes here"
            }
        }
    }
}

and a content type of application/json AWS gateway gives the error

{
  "Output": {
    "__type": "com.amazon.coral.service#UnknownOperationException",
    "message": null
  },
  "Version": "1.0"
}
1
It's not clear from the question what you're specifically trying to achieve. Do you want to make API Gateway accept a POST method with the email contents in the request body? If so, it should be a simple change from what you have now. If you're having issues, please post the specific problem you're seeing. Note: If the SES API accepts data in the request body you will need to use a mapping template. If not you will need to use path override parameters as you have done.RyanG
Thanks Ryan. I am trying to put the email contents in the request body, yes, but cannot work out what goes in the mapping template.QuantumTiger
You need to model your integration according to the SES API. The mapping template output should match what SES expects in the request body for the SendEmail operation. It's not immediately obvious from the docs, but I don't expect they take the action/etc in the request body. I think you will need to send the data in the request path as you have done earlier.RyanG
Well; it seems sending it in the request path does work. But the documentation definitely appears to show request body is possible. Just a shame API Gateway does not support application/x-www-form-urlencodedQuantumTiger
There's nothing stopping you from outputting "x-www-form-urlencoded" from your mapping template if that's what SES expects. Your API can accept JSON and convert it to form data via "application/json" mapping template. You may need to override the integration content-type header to set it to "x-www-form-urlencoded" to send to SES though.RyanG

1 Answers

1
votes

Your mapping template configuration must be in a POST format, not in the JSON, since SES service doesn't support json. For example, this config has worked out for me:

Action=SendEmail&
Message.Body.Text.Data=Some+text&
Message.Subject.Data=New+message&
[email protected]
&[email protected]
&[email protected]

Also, your path override must be SendEmail only for the case above