Skip to content

Instantly share code, notes, and snippets.

@tarlen5
Last active May 14, 2021 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarlen5/5236cbba6fe5f651889c55098d4db47c to your computer and use it in GitHub Desktop.
Save tarlen5/5236cbba6fe5f651889c55098d4db47c to your computer and use it in GitHub Desktop.
Cloud Function Accessing ObjectId of Pubsub Notification
def run(event, context):
"""
Sample code of a cloud function entrypoint that is called when a message
is published to a topic. This is run when there is a notification on a prefix
in cloud storage.
The message (event) contains the path to the objectId invoking the message.
"""
event_filename = event["attributes"]["objectId"]
event_bucket = event["attributes"]["bucketId"]
print("file `{}` was triggered in bucket `{}`".format(event_filename, event_bucket))
print("This Function was triggered by messageId {} published at {}".format(
context.event_id, context.timestamp))
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment