You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Shout out to this post for pointing out this workaround:
serverless/serverless-google-cloudfunctions#205 (comment)
Once this is natively supported in the serverless-google-cloudfunctions plugin, the serverless.yml file should be updated accordingly.
Copy file name to clipboardExpand all lines: README.md
+69-14
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,15 @@
2
2
3
3
This template project is designed to be used as a starting point for a Google Cloud Functions project using the Golang runtime and the Serverless Framework.
4
4
5
-
## Requirements
5
+
## Prerequisites
6
6
7
-
-You have the [Serverless Framework](https://www.serverless.com/framework/docs/getting-started/) installed.
8
-
-You have a project already created and configured in Google Cloud. You can follow [this guide](https://www.serverless.com/framework/docs/providers/google/guide/credentials/) to make sure its setup to work with Severless.
9
-
-You've setup your overall environment to work with GCP and the Serverless Framework. You should follow [these guides](https://www.serverless.com/framework/docs/providers/google/guide/intro/)if not.
7
+
-Install the [Serverless Framework](https://www.serverless.com/framework/docs/getting-started/)
8
+
-Install the [Google Cloud SDK](https://cloud.google.com/sdk/docs/install), and then run `gcloud auth login`to authenticate
9
+
-Create and configure a project in Google Cloud Console. You can follow [this guide](https://www.serverless.com/framework/docs/providers/google/guide/credentials/)to make sure its setup to work with Severless.
10
10
11
11
## Project structure
12
12
13
-
The root directory contains a folder for each of your microservices (i.e. Go package).
13
+
The root directory contains a folder for each microservice/package.
14
14
15
15
The `go.mod` file also resides in the root directory.
16
16
@@ -42,21 +42,15 @@ Create a directory (i.e. package) for each logical microservice you intend to de
42
42
cp -R templateservice <b>mynewservice</b>
43
43
</pre>
44
44
45
-
2. Navigate to the new directory and install the Google Cloud Functions Provider Plugin:
46
-
47
-
<pre>
48
-
cd <b>mynewservice</b> && serverless plugin install --name serverless-google-cloudfunctions
49
-
</pre>
50
-
51
-
3. Update the package name in both `fn.go` and `fn_test.go` to match your microservice/package name:
45
+
2. Update the package name in both `fn.go` and `fn_test.go` to match your microservice/package name:
52
46
53
47
<pre>
54
48
package <b>mynewservice</b>
55
49
56
50
...
57
51
</pre>
58
52
59
-
4. Open `serverless.yml` and update the configuration (i.e. service name, GCP project name, GCP credentials keyfile, etc.):
53
+
3. Open `serverless.yml` and update the configuration (i.e. service name, GCP project name, GCP credentials keyfile, etc.):
allowUnauthenticated: true # unofficial flag that ties into the post-deploy script
83
78
84
79
...
85
80
</pre>
86
81
82
+
4. Install the serverless plugin dependencies (specified in `package.json`):
83
+
84
+
<pre>
85
+
npm install
86
+
</pre>
87
+
87
88
### Additional info
88
89
89
90
Take a look at [this guide](https://cloud.google.com/functions/docs/writing#structuring_source_code) for ideas on how to structure your source code for different scenarios:
@@ -96,14 +97,68 @@ Run the following command from within your microservice/package directory to bui
96
97
cd <b>mynewservice</b> && serverless deploy
97
98
</pre>
98
99
99
-
## Remove Deployment
100
+
## Remove deployment
100
101
101
102
Run the following command from within your microservice/package directory to remove the deployment of all functions:
102
103
103
104
<pre>
104
105
cd <b>mynewservice</b> && serverless remove
105
106
</pre>
106
107
108
+
## Access control (public vs. private functions)
109
+
110
+
If you're deploying an HTTP triggered function you'll most likely want to have them be publicly accessible and google seems to make them private by default.
111
+
112
+
At this time it appears the `serverless-google-cloudfunctions` plugin does provide a way to make functions public in the `serverless.yml` file, so until this is supported by the plugin we can work around it in a few ways.
113
+
114
+
### Update manually
115
+
116
+
This can be done either through the console or the gcloud cli [as detailed here](https://cloud.google.com/run/docs/authenticating/public).
117
+
118
+
### Update via plugin commands
119
+
120
+
The included `serverless.yml` file uses the `serverless-plugin-scripts` plugin and defines 2 commands.
121
+
122
+
To make a function public, run the following from within your microservice/package directory:
123
+
124
+
```
125
+
npx sls mkfunc-pub --function=hello
126
+
```
127
+
128
+
To make a function private, run the following from within your microservice/package directory:
129
+
130
+
```
131
+
npx sls mkfunc-pvt --function=hello
132
+
```
133
+
134
+
### Update via script
135
+
136
+
This project includes a script that can automate the whole update process.
137
+
138
+
It works by first grabing all the functions defined in `serverless.yml` then sorting them as public or private (by checking for the presence of the `allowUnauthenticated: true` key-value pair in each function defined in `serverless.yml`), then finally runs either `mkfunc-pub` or `mkfunc-pvt` for each function.
139
+
140
+
To run the script manually, run the following from within your microservice/package directory:
141
+
142
+
```
143
+
../scripts/sls-update-allow-unauthenticated.sh
144
+
```
145
+
146
+
To have the script run automatically after every serverless deploy, uncomment the `custom.scripts.commands.hooks` section in the `serverless.yml` file:
0 commit comments