Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cloud Function Deployment Error on Flutter Web

Cloud function deployment failed

I'm working on a Flutter web app that needs to send SMS and emails through Twilio and SendGrid. To handle emails, I created a Google Cloud Function that triggers every time a new document is created in a Firestore collection called apiusers. The function is supposed to send an email using SendGrid whenever a new user is added to this collection.

 

 

Could not create or update Cloud Run service sendusernotification, Container Healthcheck failed. Revision 'sendusernotification-00001-wof' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The healtcheck timeout can be extended. Logs for this revision might contain more information.

i  functions: cleaning up build files...

⚠  functions: Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually at https://console.cloud.google.com/gcr/images/**/eu/gcf

 

 

unnamed.jpg

 

0 1 234
1 REPLY 1

Hi @Murphy_Carter,

Welcome to Google Cloud Community!

The error you're encountering during the deployment of your Cloud Function likely comes from the container failing its health check. This may occur when the deployed container doesn’t respond to the expected PORT (default is 8080) within the allocated time, or there’s an issue with the initialization process.

Here is a way to handle the problem and effectively implement your function:

  1. Add Port Handling: Make sure your function listens on process.env.PORT || 8080:
  2. Increase Timeout: Your function might need more time to start. Deploy with a higher timeout:
    gcloud functions deploy sendUserNotification --timeout=540s ...
  3. Check SendGrid & Firestore Setup: Ensure the SendGrid API key is accessible (use Secret Manager) and that the Firestore trigger works by testing with a manual document addition.
  4. Clean up Stale Images: Remove unused images to avoid extra charges:
    gcloud container images list
    gcloud container images delete [IMAGE_NAME]

Consider sharing the relevant parts of your function code or deployment command for further assistance. With these steps, your Cloud Function should deploy successfully!

I hope the above information is helpful.