Failed to update function after updating a Firebase secret
Sometimes we need to update an API key like in this case:
firebase functions:secrets:set STRIPE_SECRET_KEY
If the key is already by a deployed cloud function, we may get this error:
? Enter a value for STRIPE_SECRET_KEY [hidden]
✔ Created a new secret version projects/33737172103/secrets/STRIPE_SECRET_KEY/versions/2
i 1 functions are using stale version of secret STRIPE_SECRET_KEY:
onStripePaymentWritten(us-central1)
? Do you want to re-deploy the functions and destroy the stale version of secret STRIPE_SECRET_KEY?
Yes
i Updating function onStripePaymentWritten(us-central1)...
⚠ functions: HTTP Error: 400, Validation failed for trigger projects/flutter-firebase-masterclass/locations/nam5/triggers/onstripepaymentwritten-816653: The request was invalid: invalid argument: event type google.cloud.firestore.document.v1.written not supported: attribute topic not found within event type
⚠ functions: failed to update function projects/flutter-firebase-masterclass/locations/us-central1/functions/onStripePaymentWritten
Error: Failed to update function projects/flutter-firebase-masterclass/locations/us-central1/functions/onStripePaymentWritten
Having trouble? Try firebase [command] --help
To work around that, we can delete the existing function:
firebase functions:delete onStripePaymentWritten
Then, we can update the secret again:
firebase functions:secrets:set STRIPE_SECRET_KEY
And finally, we can deploy the functions again:
firebase deploy --only functions