Hello, I hope you are well:
I am currently testing to see how Cloud Functions works.
I want to do a process where I take a csv file that I uploaded to Cloud Storage.
I modify it, and I want to place the modified file new in Storage.
I do it using this code:
from google.cloud import storage
def Carga():
# Descargar el archivo CSV del bucket
client = storage.Client()
bucket = client.get_bucket('alvaro-prueba')
blob = bucket.blob('name.csv')
content = blob.download_as_string()
# Modificar las columnas 1 y 2
df = pd.read_csv(io.StringIO(content.decode('utf-8')))
df['column1'] = df['column1'].str.upper()
df['column2'] = df['column2'].str.replace('a', 'X')
# Subir el archivo CSV modificado al bucket
blob_modificado = bucket.blob('name_modificado.csv')
blob_modificado.upload_from_string(df.to_csv(index=False), content_type='text/csv')
Cloud Functions checks me green Check. But when I look for the file modified to bucket in Cloud Storage it is not there.
I used 1st gen
Hi Alvaro,
A few things here:
1- The channel I believe would get more track on the GCP side instead of workspace as this service is from the GCP environment instead of Workspace.
2- Cloud functions would need a trigger, I don't see the trigger being implemented here. I believe that you get the checkmark because your code compiles however a function is still needed to get the action started.
3- Have you applied requirements to your code? it seems that you are using some dependencies like "PD" but you would need to request those dependencies to be installed on your environment.
4- You might want to implement dinamic parameters instead of hardcoded ones as this would only be able to get the blob named "name.csv", you might want to do something like "latest = (`gsutil ls -l gs://some-bucket-name|sort -k 2|tail -2|head -1`)"