Я использую сообщение Lambda to Firebase. Я возвращаю this. Но функция лямбда по-прежнему не работает, потому что она не может подключиться к серверу google.AWS Lambda с использованием firebase-admin initializeApp timeout
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: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "connect ETIMEDOUT 172.217.26.45:443".]
Но я использую же serviceAccount.json работать на моем ec2 и работу находке. Кто-нибудь сталкивается с этим?
Как вы добавили файл 'serviceAccount.json'? Я предполагаю, что вы загрузили zip в Lambda, и это не просто встроенный код? – Deif
Помогает ли эта тема? http://stackoverflow.com/questions/36508974/python-request-in-aws-lambda-timing-out – jwngr
@Deif Я использую serverless для загрузки моего файла serviceAccount.json. – Jim