Skip to content

Instantly share code, notes, and snippets.

@erankitcs
Created March 14, 2021 12:53
Show Gist options
  • Save erankitcs/be5f2bd76358da2ee9e97e63bedf98ad to your computer and use it in GitHub Desktop.
Save erankitcs/be5f2bd76358da2ee9e97e63bedf98ad to your computer and use it in GitHub Desktop.
AWS Lambda function to push data into GCP Firestore.
'use strict';
const admin = require('firebase-admin');
const serviceAccount = require('serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const db = admin.firestore();
exports.handler = function(event, context, callback) {
console.log(event)
var message = event.Records[0].Sns.Message;
console.log('Message received from SNS:', message);
var message_json = JSON.parse(message);
const data = {
dominantColorForeground: message_json['color']['dominantColorForeground'],
dominantColorBackground: message_json['color']['dominantColorBackground'],
categories: message_json['categories'],
tags: message_json['description']['tags'],
captions: message_json['description']['captions'],
brands: message_json['brands'],
url: message_json['imageUrl']
};
const doc_id = message_json['imageId']
const docRef = db.collection('image_lense').doc(doc_id);
const res = docRef.set(data);
callback(null, "Success");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment