Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

421
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda