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

Using secrets on pub/sub onMessagePublished event with GCP cloud functions(2nd Gen)

Is it possible to use secrets(google secret manager) dependency array(cloud functions v2) on an onMessagePublished event ?

exports.processMessage = onMessagePublished( messageTopic, { secrets: [ApiKey, Secret, sqlUsername, sqlPassword, sqlServerName] }, async (event) => {}

Basically I want to use secrets in an onMessagePublished(pub/sub) event. And in V2 functions they have to be on a dependency array

0 1 499
1 REPLY 1

Hi @hmshimanyula

Welcome and thank you for reaching out to our community.

I get that you wanted to use secrets for Pub/Sub topics (onMessagePublished event is triggered by messages published to a topic) but unfortunately it is not currently supported in Cloud Functions. 

A good workaround to try is to configure secrets in Cloud Functions, then use Pub/Sub triggers to invoke that Cloud Function. Here are some useful resources for this use case:

Let me share with you as well some related topics from our community that can be of help:

You can also have this submitted as an issue or feature request or reach out to Cloud Functions Support for better assistance.