0.5.0 • Published 4 years ago
@imaware/gcp-function v0.5.0
Google Cloud Functions Generator
Generate a Google Cloud Function within a Nx workspace with dev tools:
- Create :
nx generate @imaware/gcp-function:http functionName - Serve :
nx serve functionName - Test :
nx test functionName - Deploy :
nx deploy functionName
Setup
Before you begin
Install Node.js version 10 or greater
Obtain authentication credentials. Create local credentials by running the following command and following the oauth2 flow (read more about the command here):
gcloud auth application-default loginRead more about Google Cloud Platform Authentication.
Create a Nx workspace.
npx create-nx-workspace@latest workspaceName cd workspaceName yarn add tslib yarn add -D @imaware/gcp-function @google-cloud/functions-framework supertest @nrwl/lint @nrwl/jest @types/expressRead more about Nx Workspace
Create a function
Trigger: HTTP
nx generate @imaware/gcp-function:http functionNameTrigger: Pub/Sub
nx generate @imaware/gcp-function:pubsub functionNameTest the function
nx serve functionName
nx test functionNameDeploy the function
nx build functionName
nx deploy functionNameThe 'build' option bundle all your internal dependencies in main.js & create a new package.json with your external dependencies (version number from root/package.json.)
App Composition
Others
Reporting Errors to Stackdriver Error Reporting
// These WILL be reported to Stackdriver Error Reporting
console.error(new Error('I failed you'));
console.error('I failed you', new Error('I failed you too'));
throw new Error('I failed you'); // Will cause a cold start if not caughtNx Commands
nx lint functionName
nx format:write functionName
nx format:write functionName
nx format:check functionName
nx affected --target=build
nx build functionName --with-depsGoogle Cloud Commands
gcloud functions deploy myFunction --set-env-vars foo=bar, zoo=lop
gcloud functions myFunction --update-env-vars foo=bar, zoo=lop
gcloud functions deploy myFunction --service-account emailOfServiceAccount
gcloud functions deploy myFunction --max-instances maxInstancesCount
gcloud functions deploy myFunction --clear-max-instances
gcloud functions logs read functionNameHire Me
Joel Turcotte Gaucher - linkedin - joelturcotte.g@gmail.com