0

I am trying to rename the cloud storage blob name but after running cloud function there is no change in blob name.

Please find below code:

from google.cloud import storage


def rename_blob(bucket_name, blob_name, new_name):
    
    """Renames a blob."""
    # The ID of your GCS bucket
    # bucket_name = "your-bucket-name"
    # The ID of the GCS object to rename
    # blob_name = "your-object-name"
    # The new ID of the GCS object
    # new_name = "new-object-name"

    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    blob = bucket.blob(blob_name)

    new_blob = bucket.rename_blob(blob, new_name)

    print("Blob {} has been renamed to {}".format(blob.name, new_blob.name))

if __name__ == "__main__":
  
    rename_blob(etlbucket,test-blob,new-blob)

requirements.txt-

google-cloud-storage

refereeing link: https://cloud.google.com/storage/docs/copying-renaming-moving-objects#code-samples_1

Thank you, Shivam

Soni Sol
  • 2,367
  • 3
  • 12
  • 23
shivam
  • 111
  • 2
  • 13
  • 1
    and what can you see in logs? any exceptions? can you provide a bit more details, please? does the cloud function service account have relevant permissions? – al-dann Apr 20 '22 at 14:36
  • there is no exception in logs @al-dann and I had provide all the required permissions – shivam Apr 20 '22 at 14:43
  • I also tried to run copy an object from one storage to another but nothing had happened. followed https://cloud.google.com/storage/docs/copying-renaming-moving-objects#code-samples_1 link which is straight forward but no output. – shivam Apr 20 '22 at 14:46
  • how do you deploy that cloud function and invoke it? cloud function should follow some signature, depending on its 'type' and how you are call it in run time. For example, a cloud function triggered by a cloud storage event - https://cloud.google.com/functions/docs/samples/functions-helloworld-storage – al-dann Apr 20 '22 at 14:48
  • I had deployed from gcp console and triggered manually. – shivam Apr 20 '22 at 14:49
  • could you share the logs of the execution an d the state of the bucket before and after the execution? – Soni Sol Jun 08 '22 at 16:22

0 Answers0