title: AWS Lambda using firebase-admin initializeApp timeout
body: <p>I use Lambda to Firebase message. I ref <a href="https://stackoverflow.com/questions/37325775/amazon-lambda-to-firebase">this</a>. But the lambda function still timeout because it cannot connect to google server.</p>
  
  <p>Handler.js</p>
  
  <pre><code>/ [START imports]
  const firebase = require('firebase-admin');
  const serviceAccount = require("../serviceAccount.json");
  
  module.exports.message = (event, context, callback) =&gt; {
    context.callbackWaitsForEmptyEventLoop = false;  
    const registrationToken = "xxxxxxx";
  
    const payload = {
      data: {
        score: "850",
        time: "2:45"
      }
    };
  
    // [START initialize]
    if(firebase.apps.length == 0) {   // &lt;---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
          })
        })
      });
  };
  </code></pre>
  
  <p>CloudWatch</p>
  
  <blockquote>
    <p>[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".]</p>
  </blockquote>
  
  <p>But I use same serviceAccount.json to run on my ec2 and work find.
  Does someone encounter this?</p>