Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

GCP workflow to delete storage object

I have to add a condition in gcp workflow to delete a stoarge object file(csv )if it exist. Please suggest on this.

I am using below but it's giving error

checkfileexist:
call: http.get
args:
url:  https://storage.cloud.google.com/abc/file.csv

- evaluate:
switch:
- condition: "{{ checkfileexist.statusCode == 200 }}"
next: deleteobject
next: finish


- deleteobject:
call: http.delete
args:
url: https://storage.cloud.google.com/abc/file.csv
next: finish

error - which is coming on line - condition: "{{ checkfileexist.statusCode == 200 }}" 

source: "main.evaluate, line: 42"
exception: "TypeError: in conditional predicate: expected boolean, got str
in step "evaluate", routine "main", line: 42: {"message":"TypeError:
in conditional predicate: expected boolean, got str","tags":["TypeError"]}"
}}

1 1 476
1 REPLY 1

Hi @gcloudLearning,

Welcome back to Google Cloud Community!

To fix the error in your GCP workflow to delete a storage object, you need to convert the checkfileexist.statusCode property to an integer before comparing it to 200. You can do this using the int() function.

Here is an example of a workflow that will delete a storage object if it exists:

checkfileexist:
call: http.get
args:
url: https://storage.cloud.google.com/abc/file.csv
- evaluate:
switch:
- condition: "{{ int(checkfileexist.statusCode) == 200 }}"
next: deleteobject
- next: finish

- deleteobject:
call: http.delete
args:
url: https://storage.cloud.google.com/abc/file.csv
next: finish


Once you have deployed the workflow, you can trigger it manually or by using a trigger such as a Pub/Sub message or a Cloud Storage event.