Skip to content

Commit 6684ba1

Browse files
committed
Update notes for SQS connector to use newer Go template
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent b9abb22 commit 6684ba1

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

docs/openfaas-pro/sqs-events.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,30 @@ On the blog: [How to integrate OpenFaaS functions with managed AWS services](htt
3737

3838
`maxMessages` - Maximum messages to fetch at once - between 1-10
3939

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.
4048

4149
## Usage
4250

4351
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.
4452

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:
4660

4761
```bash
4862
export OPENFAAS_PREFIX=ghcr.io/openfaas
49-
faas-cli new --lang go resize-image
63+
faas-cli new --lang golang-middleware resize-image
5064
```
5165

5266
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:
6175
resize-image:
6276
annotations:
6377
topic: s3-put-image
64-
lang: go
78+
lang: golang-middleware
6579
handler: ./resize-image
66-
image: ghcr.io/openfaas:resize-image
80+
image: ghcr.io/openfaas/resize-image:latest
6781
```
6882
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+
6987
Test it out:
7088

7189
* Now deploy your function with `faas-cli up`
7290
* Upload an image to your SQS queue
7391
* You'll receive a JSON payload with the details of which file was uploaded
7492
* 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
7695

7796
## Would you like a demo?
7897

0 commit comments

Comments
 (0)