serverless / serverless-google-cloudfunctions

Serverless Google Cloud Functions Plugin – Adds Google Cloud Functions support to the Serverless Framework
https://www.serverless.com
MIT License
271 stars 127 forks source link

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

Open nspeet opened 4 years ago

nspeet commented 4 years ago

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?

steinnat commented 3 years ago

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.