I am using the Lambda to Firebase post. I am returning this one . But the lambda function still does not work, because it cannot connect to google server.
Handler.js
/ [START imports] const firebase = require('firebase-admin'); const serviceAccount = require("../serviceAccount.json"); module.exports.message = (event, context, callback) => { context.callbackWaitsForEmptyEventLoop = false; const registrationToken = "xxxxxxx"; const payload = { data: { score: "850", time: "2:45" } }; // [START initialize] if(firebase.apps.length == 0) { // <---Important!!! In lambda, it will cause double initialization. firebase.initializeApp({ credential: firebase.credential.cert(serviceAccount), databaseURL: 'https://messaging-xxxxx.firebaseio.com' }); } // Send a message to the device corresponding to the provided // registration token. firebase.messaging().sendToDevice(registrationToken, payload) .then(function(response) { // See the MessagingDevicesResponse reference documentation for // the contents of response. console.log("Successfully sent message:", response); callback(null, { statusCode: 200, body: JSON.stringify("Successful!"), }); }) .catch(function(error) { console.log("Error sending message:", error); callback(null, { statusCode: 500, body: JSON.stringify({ "status": "error", "message": error }) }) }); };
Cloudwatch
[Error: the access rights granted by initializeApp () through the "credential" property could not get a valid Google OAuth2 access token with the following error: "connect ETIMEDOUT 172.217.26.45:443".]
But I use the same serviceAccount.json to run on my ec2 and find a job. Does anyone come across this?
source share