/gcp-storage-class-match-notifier

Google Cloud Function that publishes messages to Pub/Sub when the metadata of a GCS object changes and the object's storage class matches given criteria — e.g., == ARCHIVE.

Primary LanguagePythonMIT LicenseMIT

gcp-storage-class-match-notifier

Google Cloud Function that publishes messages to Pub/Sub when the metadata of a GCS object changes and the object's storage class matches given criteria — e.g., == ARCHIVE.

It has been used to notify other systems when GCS objects storage class changes due to lifecycle rules being applied. Please notice that other metadata changes will also trigger the function and publish messages to Pub/Sub if the storage class matches the criteria.

license issues continuous integration

Deployment instructions

PUBSUB_PROJECT_ID=<YOUR-PROJECT-ID>
PUBSUB_TOPIC_ID=<YOUR-PUBSUB-TOPIC-ID>
STORAGE_CLASS_MATCH_NOTIF_SA=<PUBSUB-PUBLISHER-SERVICE-ACCOUNT-EMAIL>
TRIGGER_BUCKET=<YOUR-BUCKET-NAME>

gcloud functions deploy notify-storage-class-match \
  --entry-point notify_storage_class_match \
  --runtime python39 \
  --service-account $STORAGE_CLASS_MATCH_NOTIF_SA \
  --set-env-vars PUBSUB_PROJECT_ID=$PUBSUB_PROJECT_ID,PUBSUB_TOPIC_ID=$PUBSUB_TOPIC_ID \
  --trigger-event google.storage.object.metadataUpdate \
  --trigger-resource $TRIGGER_BUCKET

The STORAGE_CLASS_MATCH_NOTIF_SA environment variable refers to the email of the IAM service account associated with the function at runtime. The service account must be granted the pubsub.publisher role on the Pub/Sub Topic identified by projects/${PUBSUB_PROJECT_ID}/topics/${PUBSUB_TOPIC_ID}.

How to contribute

Please make sure to take a moment and read the Code of Conduct.

Report issues

Please report bugs and suggest features via the GitHub Issues.

Before opening an issue, search the tracker for possible duplicates. If you find a duplicate, please add a comment saying that you encountered the problem as well.

Contribute code

Please make sure to read the Contributing Guide before making a pull request.