serverless-google-cloudfunctions icon indicating copy to clipboard operation
serverless-google-cloudfunctions copied to clipboard

Question: Is their a serverless plugin hook for google cloud function deploy?

Open nspeet opened this issue 5 years ago • 1 comments
trafficstars

AWS has hooks such as this.hooks = { "aws:deploy:finalize:cleanup": this.afterDeploy.bind(this), };

Are there similar hooks for GCP cloud function deploys? If not, how can one create a hook for 'after deploy' of a cloud function?

nspeet avatar Sep 15 '20 14:09 nspeet

Found this: @deemetree-at-satelligence said you could use sls hooks using this plugin: https://www.npmjs.com/package/serverless-plugin-scripts


YAML FILE
service: YOUR-SERVICE-NAME

custom:
  ...
 # this comes from https://www.npmjs.com/package/serverless-plugin-scripts
  scripts:
    commands:
      make-public: gcloud functions add-iam-policy-binding ${self:service}-${self:provider.stage}-${opt:function, "YOUR-DEFAULT-FUNCTION-NAME"} --member="allUsers" --role="roles/cloudfunctions.invoker" --project=${self:provider.project} --region=${self:provider.region} | xargs echo 
    hooks:
      'after:deploy:deploy': npx sls make-public --function=YOUR-FUNCTION-NAME
...

This hook automatically makes the specified google functions public after deploy and otherwise you can run sls make-public --function= at any time, hope this helps.

steinnat avatar Nov 03 '20 23:11 steinnat