Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

422
Vistas
Static webpage in s3 bucket and making ajax request inside the page to call lambda function

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.

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.

Any idea, or help will be helpful for me. Thanks ----Ajax 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);
    });

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.

NodeJs code for send Email

    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");
   })

  })

sendemail module snippet is :

    ses.sendemail(data, done)

I considered this website but didn't get the solution : https://codehabitude.com/2016/04/05/forms-to-emails-using-aws-lambda-api-gateway/

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Its very likely you aren't setting up the CORS headers correctly in apigateway. The apigateway documentation http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html clearly describes the process.

Once you've setup CORS and deployed the changes, you can verify the CORS preflight request using the below curl command

curl -H "Origin: http://example.com" \
  -H "Access-Control-Request-Method: POST" \
  -H "Access-Control-Request-Headers: X-Requested-With" \
  -X OPTIONS --verbose \
    https://apigateway-url/email_sending

Also, note that you need to deploy the changes after you setup CORS (Big blue Deploy API button - http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-deploy-api-with-console.html) before the change is reflected in your API

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda