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
Copy file name to clipboardExpand all lines: README.md
+6-13Lines changed: 6 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -179,52 +179,45 @@ You can configure the Functions Framework using command-line flags or environmen
179
179
|`--host`|`HOST`| The host on which the Functions Framework listens for requests. Default: `0.0.0.0`|
180
180
|`--port`|`PORT`| The port on which the Functions Framework listens for requests. Default: `8080`|
181
181
|`--target`|`FUNCTION_TARGET`| The name of the exported function to be invoked in response to requests. Default: `function`|
182
-
|`--signature-type`|`FUNCTION_SIGNATURE_TYPE`| The signature used when writing your function. Controls unmarshalling rules and determines which arguments are used to invoke your function. Default: `http`; accepted values: `http` or`event` or `cloudevent`|
182
+
|`--signature-type`|`FUNCTION_SIGNATURE_TYPE`| The signature used when writing your function. Controls unmarshalling rules and determines which arguments are used to invoke your function. Default: `http`; accepted values: `http`,`event` or `cloudevent`|
183
183
|`--source`|`FUNCTION_SOURCE`| The path to the file containing your function. Default: `main.py` (in the current working directory) |
184
184
|`--debug`|`DEBUG`| A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False`|
185
185
186
-
187
186
## Enable Google Cloud Functions Events
188
187
189
188
The Functions Framework can unmarshall incoming
190
189
Google Cloud Functions [event](https://cloud.google.com/functions/docs/concepts/events-triggers#events) payloads to `data` and `context` objects.
191
190
These will be passed as arguments to your function when it receives a request.
192
191
Note that your function must use the `event`-style function signature:
193
192
194
-
195
193
```python
196
194
defhello(data, context):
197
195
print(data)
198
196
print(context)
199
197
```
200
198
201
199
To enable automatic unmarshalling, set the function signature type to `event`
202
-
using a command-line flag or an environment variable. By default, the HTTP
200
+
using the `--signature-type`command-line flag or the `FUNCTION_SIGNATURE_TYPE` environment variable. By default, the HTTP
203
201
signature will be used and automatic event unmarshalling will be disabled.
204
202
205
-
For more details on this signature type, check out the Google Cloud Functions
203
+
For more details on this signature type, see the Google Cloud Functions
See the [running example](examples/cloud_run_event).
210
208
211
209
## Enable CloudEvents
212
210
213
-
The Functions Framework can unmarshall incoming
214
-
[CloudEvent](http://cloudevents.io) payloads to a `cloudevent` object.
215
-
It will be passed as an argument to your function when it receives a request.
216
-
Note that your function must use the `cloudevent`-style function signature
217
-
211
+
The Functions framework can also unmarshall incoming [CloudEvents](http://cloudevents.io) payloads to the `cloudevent` object. This will be passed as a [cloudevent](https://github.com/cloudevents/sdk-python) to your function when it receives a request. Note that your function must use the `cloudevents`-style function signature:
218
212
219
213
```python
220
214
defhello(cloudevent):
221
-
print("Received event with ID: %s"% cloudevent.EventID())
222
-
return200
215
+
print(f"Received event with ID: {cloudevent['id']}")
223
216
```
224
217
225
218
To enable automatic unmarshalling, set the function signature type to `cloudevent` using the `--signature-type` command-line flag or the `FUNCTION_SIGNATURE_TYPE` environment variable. By default, the HTTP signature type will be used and automatic event unmarshalling will be disabled.
226
219
227
-
See the [running example](examples/cloud_run_cloudevents).
220
+
For more details on this signature type, check out the Google Cloud Functions documentation on [background functions](https://cloud.google.com/functions/docs/writing/background#cloud_pubsub_example).
*[`cloud_run_http`](./cloud_run_http/) - Deploying an HTTP function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework
4
-
*[`cloud_run_event`](./cloud_run_event/) - Deploying a [Google Cloud Functions Event](https://cloud.google.com/functions/docs/concepts/events-triggers#events) function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework
5
-
*[`cloud_run_cloudevents`](./cloud_run_cloudevents/) - Deploying a [CloudEvent](https://github.com/cloudevents/sdk-python) function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework
4
+
*[`cloud_run_event`](./cloud_run_event/) - Deploying a CloudEvent function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework
5
+
*[`cloud_run_cloudevents`](./cloud_run_cloudevents/) - Deploying a [CloudEvent](https://github.com/cloudevents/sdk-python) function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework
# Deploying a CloudEvent function to Cloud Run with the Functions Framework
2
-
This sample uses the [Cloud Events SDK](https://github.com/cloudevents/sdk-python) to send and receive a CloudEvent on Cloud Run.
1
+
# Deploying a CloudEvent Function to Cloud Run with the Functions Framework
2
+
3
+
This sample uses the [CloudEvents SDK](https://github.com/cloudevents/sdk-python) to send and receive a [CloudEvent](http://cloudevents.io) on Cloud Run.
3
4
4
5
## How to run this locally
6
+
5
7
Build the Docker image:
6
8
7
9
```commandline
8
-
docker build --tag ff_example .
10
+
docker build -t cloudevent_example .
9
11
```
10
12
11
13
Run the image and bind the correct ports:
12
14
13
15
```commandline
14
-
docker run -p:8080:8080 ff_example
16
+
docker run --rm -p 8080:8080 -e PORT=8080 cloudevent_example
0 commit comments