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

302
Visualizações
Receive data from website then trigger lambda send email and backup to DynamoDB

I am beginner, I found two instructions on the internet to get data ( Contact us - Email, Phone, etc ) to AWS - Lambda then send to my email

https://aws.amazon.com/blogs/architecture/create-dynamic-contact-forms-for-s3-static-websites-using-aws-lambda-amazon-api-gateway-and-amazon-ses/

And another one to make a AWS - Lambda function to send to Dynamo to back up.

https://www.vairix.com/tech-blog/get-and-put-data-using-lambda-and-dynamodb-simple-and-clear

I put them together, but they don't connect. For example, Lamba trigger to send info from website to my email but the other function wont collect the item to send it to Dynamo

Lambda to send email:

var AWS = require('aws-sdk');
var ses = new AWS.SES();
 
var RECEIVER = 'contactus@example.com';
var SENDER = 'contactus@example.com';

var response = {
 "isBase64Encoded": false,
 "headers": { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'example.com'},
 "statusCode": 200,
 "body": "{\"result\": \"Success.\"}"
 };

exports.handler = function (event, context) {
    console.log('Received event:', event);
    sendEmail(event, function (err, data) {
        context.done(err, null);
    });
};
 
function sendEmail (event, done) {
    var params = {
        Destination: {
            ToAddresses: [
                RECEIVER
            ]
        },
        Message: {
            Body: {
                Text: {
                    Data: 'name: ' + event.name + '\nphone: ' + event.phone + '\nemail: ' + event.email + '\ndesc: ' + event.desc,
                    Charset: 'UTF-8'
                }
            },
            Subject: {
                Data: 'Website Referral Form: ' + event.name,
                Charset: 'UTF-8'
            }
        },
        Source: SENDER
    };
    ses.sendEmail(params, done);
}

Lambda to store information in DynamoDB:

"use strict";

AWS.config.update({ region: "us-east-1" });


exports.handler = async() => {

const documentCilent = new AWS.DynamoDB.DocumentClient({region: "us-east-1"});

const params = {
    TableName: "Users",
    
    //  This part, I need the variable connect with the top part. 
    Item:{
      id : "test",     
      name: "name",
      phone: "phone",
      desc: "desc",
      email: "email"
      
      
    }
  
};

try {
    const data = await documentCilent.put(params).promise();
    console.log(data);

} catch (err) {
    console.log(err);
}
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Lambda's are independent than each other and only fire upon receiving an Event to do so. This Event can be several things - It can be an Event sent to the lambda from an API Gateway (this is what connecting your Api to your Lambda does - gives a target for the Api Event to go to). It can be an event generated by your SDK (using your languases SDK to invoke another lambda). It can be from a DynamoDB stream or an S3 put_object event.

Pretty much any thing that happens in AWS resources outputs an event of some kind, and with the right commands/setups you can have a Lambda listening for that event.

In this situation however, as these are both very light weight, it would just be more cost effective to combine them under one lambda. API gets the information, sends it to the lambda which fires an email and adds it to the Dynamodb. Anything else in this situation is kinda overkill and would increase your costs.

about 4 years ago · Juan Pablo Isaza 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