0

I have created a custom template for Dataflow Batch Jobs. Now I need to run every 5 minutes using cloud scheduler. The template is stored in cloud storage. But I'm getting 401 error, whenever I pass the URI of template in my POST request from scheduler

        URI - "https://dataflow.googleapis.com/v1b3/projects/project-id/locations/region/templates:launch?gcsPath=gs://my_bucket/templates/mytemplate 

I'm not sure what the body should contain

Error:

     jsonPayload: {
     targetType: "HTTP"
     @type: "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"
     status: "UNAUTHENTICATED"
     url: "https://storage.cloud.google.com/my_bucket/templates/mydemotemp"
     jobName: "projects/project-id/locations/us-central1/jobs/finaljob"
     }
     httpRequest: {
     status: 401

Can anyone please help as how to go about it. Since I'm new to GCP

anagha s
  • 303
  • 3
  • 11

1 Answers1

1

It could happen when the service account that you used for Cloud scheduler don't have permission to access to bucket.

You can use your service account for cloud scheduler authentication.

Set service account like below, Or refer here to get detailed guide.

enter image description here

Before setting your cloud scheduler, grant your service account a role like "Storage Object view" or higher level.

Refer here to check GCS roles that required for bucket access.

kallusis369
  • 820
  • 1
  • 10
  • I have added the service account and authetication. I'm able to access for GET also. But for POST it throwing an error – anagha s Dec 18 '20 at 13:07
  • It means your service account have permission that can view list of your bucket's object, but don't have one that can write object to bucket. Have you checked service account's permission granted properly? – kallusis369 Dec 19 '20 at 02:23
  • @anaghas Try setting up as owner the owner role at first, then downgrade it to the proper role you want it to have, this will force the roles to be re-applied. – Rafael Lemos Dec 21 '20 at 12:09
  • @kallusis369 then how is GET working and not POST? Its working fine with GET – anagha s Dec 23 '20 at 13:10
  • @Rafael Lemos could you explain how to do the same? – anagha s Dec 23 '20 at 13:11