I have set up a Google Cloud Storage bucket to send notifications to a Pub/Sub topic:
gsutil notification create -t my-topic -f json gs://test-bucket
I have created a subscription to this topic to push messages to a cloud function endpoint:
gcloud pubsub subscriptions create my-sub --topic my-topic
And the cloud function is deployed with:
gcloud functions deploy promo_received --region europe-west1 --runtime python37 --trigger-topic my-topic
The purpose of the function (right now), is to check if a file being created in the test-bucket matches a specific file name, and to fire a message off to Slack when it does. Currently the function looks like this:
def promo_received(data):
date_str = datetime.today().strftime('%Y%m%d')
filename = json.loads(data)["name"]
bucket = json.loads(data)["bucket"]
if filename == 'PROM_DTLS_{}.txt.gz'.format(date_str):
msg = ":heavy_check_mark: *{}* has been uploaded to *{}*. Awaiting instructions.".format(filename, bucket)
post_to_slack(url, msg)
When I test this by dropping a file named PROM_DTLS_20190913.txt.gz, I can see the function fires, however it crashes with 2 errors:
TypeError: promo_received() takes 1 positional argument but 2 were given
TypeError: the JSON object must be str, bytes or bytearray, not LocalProxy
This is my first time attempting to do this, and I'm not sure where to start with troubleshooting. Any help would be greatly appreciated!