- Download this file FirebaseAdminLayer.zip
- Create a Lambda Layer with the downloaded AdminFirebase.zip
- Attach FirebaseAdminLayer to your Lambda Function
Last active
March 7, 2020 05:19
-
-
Save diegofcornejo/14e1ffb4a6d9bea3de462a4d5b861b13 to your computer and use it in GitHub Desktop.
Lambda - SNS - Process SES granular events and save into Cloud Firestore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const admin = require('firebase-admin'); | |
let serviceAccount = require('./serviceAccountKey.json'); | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount) | |
}); | |
let db = admin.firestore(); | |
var collection = 'aws-ses-events'; | |
exports.handler = async(event) => { | |
var message = JSON.parse(event.Records[0].Sns.Message); | |
let doc = { | |
"messageId": message.mail.messageId, | |
"eventType": message.eventType, | |
"timestamp": message.mail.timestamp, | |
"from": message.mail.commonHeaders.from, | |
"to": message.mail.commonHeaders.to, | |
"subject": message.mail.commonHeaders.subject, | |
"eventInfo": message[message.eventType.toLowerCase()] | |
}; | |
let promise = new Promise(function(resolve, reject) { | |
db.collection(collection).add(doc).then(ref => { | |
console.log('Added document with ID: ', ref.id); | |
resolve(ref.id); | |
}); | |
}); | |
return promise; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "service_account", | |
"project_id": "randomtechguy", | |
"private_key_id": "", | |
"private_key": "", | |
"client_email": "", | |
"client_id": "", | |
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | |
"token_uri": "https://oauth2.googleapis.com/token", | |
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | |
"client_x509_cert_url": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment