@@ -37,16 +37,30 @@ On the blog: [How to integrate OpenFaaS functions with managed AWS services](htt
37
37
38
38
` maxMessages ` - Maximum messages to fetch at once - between 1-10
39
39
40
+ Each time a function is invoked by the connector it will receive the message from the queue as the HTTP body.
41
+
42
+ It'll also receive two HTTP headers:
43
+
44
+ * ` X-SQS-Message-ID ` - the ID of the message in the SQS queue for when a function needs to do something with the message
45
+ * ` X-SQS-Queue-URL ` - the URL of the SQS queue - required when a function receives messages from multiple queues
46
+
47
+ Once the message has been delivered to the function, it will be deleted from the queue.
40
48
41
49
## Usage
42
50
43
51
Once you have configured a number of topics, you can then annotate your functions so that they get triggered by any incoming messages on those topics.
44
52
45
- Create a new function:
53
+ Download a template such as the ` golang-middleware ` template:
54
+
55
+ ``` bash
56
+ faas-cli template store pull golang-middleware
57
+ ```
58
+
59
+ Then scaffold a new function using your registry in the ` OPENFAAS_PREFIX ` environment variable:
46
60
47
61
``` bash
48
62
export OPENFAAS_PREFIX=ghcr.io/openfaas
49
- faas-cli new --lang go resize-image
63
+ faas-cli new --lang golang-middleware resize-image
50
64
```
51
65
52
66
Now add an annotation for the ` s3-put-image ` queue, so that the ` resize-image ` function is invoked for any message received:
@@ -61,18 +75,23 @@ functions:
61
75
resize-image :
62
76
annotations :
63
77
topic : s3-put-image
64
- lang : go
78
+ lang : golang-middleware
65
79
handler : ./resize-image
66
- image : ghcr.io/openfaas: resize-image
80
+ image : ghcr.io/openfaas/ resize-image:latest
67
81
` ` `
68
82
83
+ Edit the HTTP handler at ` ./s3-put-image/handler.go` so it prints out the HTTP body and headers to its logs.
84
+
85
+ You can find a complete example here : [printer function written in Go](https://github.com/openfaas/store-functions/tree/master/printer).
86
+
69
87
Test it out :
70
88
71
89
* Now deploy your function with `faas-cli up`
72
90
* Upload an image to your SQS queue
73
91
* You'll receive a JSON payload with the details of which file was uploaded
74
92
* Fetch the file with the AWS SDK and resize it with a library of your choice
75
- * Finally upload it to a different S3 Bucket.
93
+ * Upload it to a different S3 Bucket.
94
+ * Now view the logs for your function to see the output
76
95
77
96
# # Would you like a demo?
78
97
0 commit comments