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