title: Static webpage in s3 bucket and making ajax request inside the page to call lambda function
body: <p>I have uploaded a html page in s3 bucket and that html page makes an ajax post request to the api gateway url to send an email. </p>
  
  <p>The problem is that the same api gateway url if I use postman to make a post request to it the email is sent but with the html page in s3 having ajax code doesn't work.</p>
  
  <p>Any idea, or help will be helpful for me. Thanks
  ----Ajax code </p>
  
  <pre><code>    $.ajax("https://apigateway-url/email_sending", {
      "type": "POST",
      "data": JSON.stringify(formData),
      "contentType": "application/json"
      }).done(function () {
          console.log("Done")
      }).fail(function () {
          console.log("Failed");
          // console.log(data);
      });
  </code></pre>
  
  <p>I have tried so many help from net like edit cors configuration in s3 or enable cors in api gateway, but none worked for me.</p>
  
  <p>NodeJs code for send Email</p>
  
  <pre><code>    var sendemail = require('./sendemail')
      app.post('/email_sending',function(req,res){
       console.log("Request received For sending mail")
       sendemail.send(req.body,function(err, data){
  
     // res.setHeader('Access-Control-Allow-Origin', '*');
      res.end("Success");
     })
  
    })
  </code></pre>
  
  <p>sendemail module snippet is :</p>
  
  <pre><code>    ses.sendemail(data, done)
  </code></pre>
  
  <p>I considered this website but didn't get the solution : <a href="https://codehabitude.com/2016/04/05/forms-to-emails-using-aws-lambda-api-gateway/" rel="nofollow noreferrer">https://codehabitude.com/2016/04/05/forms-to-emails-using-aws-lambda-api-gateway/</a></p>