Search code examples
amazon-web-servicesamazon-s3aws-lambdaamazon-ses

Facing issues adding destination while creating a dynamic contact form for S3 static website using AWS Lambda


I have been trying to create a email form for my website using AWS Lambda, Amazon API Gateway and SES.

I followed the instructions provided in the blog by AWS. The instructions for adding destinations and creating a link between the mailFwd and the destinations are not provided by the article.

Also, there is a part of the article which mentions adding a code snippet under the policy so that SES can access the lambda function. I can't find where the policy section is.

2


Solution

  • The application flow looks like this:

    JavaScript / HTML -> API Gateway -> AWS Lambda Function mailfwd -> SES
    

    This means, your frontend sends an HTTP request to the API Gateway which forwards an HTTP event to your Lambda function and your Lambda function processes the mail data from the HTTP event and forwards it to SES.

    To avoid any confusion: SES is neither calling nor accessing your Lambda function, it's only the other way around. In order to allow the Lambda function to call SES and send a mail, you have to copy the IAM policy from the blog post (the policy about ses:SendMail) to the policy of your Lambda function's IAM role. (I admit that the blog post's wording is a bit confusing here).

    Besides that, you don't need to create any links between the services. You only need to tell API Gateway which Lambda function to call if an HTTP request comes in. In this case you choose the mailfwd function as mentioned in the article:

    1. Select your newly-created resource and choose “create method.” Choose a POST. Here, you will choose our AWS Lambda Function. To do this, select “mailfwd” from the drop down.