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
* tests: update go-mnq-sqs-publish example to use serverless local testing
* tests: update go-upload-file-s3-multipart example to use serverless local testing
* fix(docs): update wrong version for MultiPart Upload to S3 example in README
* tests: update cors-go example to use serverless local testing
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ Table of Contents:
34
34
|**[CORS Python](functions/cors-python/README.md)** <br/> A Python function which allows CORS requests. | python310 |[Serverless Framework]|
35
35
|**[CORS Rust](functions/cors-rust/README.md)** <br/> A Rust function which allows CORS requests. | rust165 |[Serverless Framework]|
36
36
|**[Go SQS Publish](functions/go-mnq-sqs-publish/README.md)** <br/> A Go function to publish messages to SQS. | go118 |[Serverless Framework]|
37
-
|**[Go MultiPart Upload to S3](functions/go-upload-file-s3-multipart)** <br/> A function to upload file from form-data to S3. |go119|[Serverless Framework]|
37
+
|**[Go MultiPart Upload to S3](functions/go-upload-file-s3-multipart)** <br/> A function to upload file from form-data to S3. |go120|[Serverless Framework]|
38
38
|**[Image Transform](functions/image-transform-node/README.md)** <br/> A function that resizes images from an S3 bucket. | node16 |[Serverless Framework]|
39
39
|**[Node MultiPart Upload to S3](functions/node-upload-file-s3-multipart/README.md)** <br/> A function to upload file from form-data to S3. | node19 |[Serverless Framework]|
40
40
|**[PHP write to S3](functions/php-s3/README.md)** <br/> A PHP function that connects to, and writes to an S3 bucket. | php82 |[Terraform]|
Copy file name to clipboardExpand all lines: functions/cors-go/README.md
+30-12Lines changed: 30 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ This example assumes you are familiar with how serverless functions work. If nee
6
6
7
7
This example uses the Scaleway Serverless Framework Plugin. Please set up your environment with the requirements stated in the [Scaleway Serverless Framework Plugin](https://github.com/scaleway/serverless-scaleway-functions) before trying out the example.
8
8
9
+
Additionnaly it uses the [serverless-functions-go](https://github.com/scaleway/serverless-functions-go) library for local testing.
10
+
9
11
## Context
10
12
11
13
This example shows how to handle preflight CORS requests that will be sent by a browser when invoking a function. The example uses totally permissive, open CORS, you may want to modify this to make it more secure.
@@ -18,22 +20,18 @@ This function uses Golang 1.19 runtime.
18
20
19
21
## Setup
20
22
21
-
Once your environment is set up, you can run:
23
+
Once your environment is set up, you can test your function locally with:
22
24
23
-
```console
24
-
npm install
25
+
```sh
26
+
npm install
25
27
26
-
serverless deploy
28
+
go run test/main.go
27
29
```
28
30
29
-
Then, from the given URL, you can run:
30
-
31
-
```console
32
-
# Options request
33
-
curl -i -X OPTIONS <function URL>
31
+
This will launch a local server, allowing you to test the function. For that, you can run in another terminal:
You can use this example to publish a message to an SQS queue using the MNQ namespace from the Scaleway Go SDK.
4
4
5
5
## Requirements
6
6
7
-
This example assumes you are familiar with how serverless functions work. If needed, you can check [Scaleway's official documentation](https://www.scaleway.com/en/docs/serverless/functions/quickstart/)
7
+
This example assumes that you are familiar with some products of Scaleway's ecosystem:
8
+
9
+
* how serverless functions work. If needed, you can check [Scaleway official documentation](https://www.scaleway.com/en/docs/serverless/functions/quickstart/).
10
+
* how Messaging and Queuing works. Please refer to scaleway's documentation [here](https://www.scaleway.com/en/docs/serverless/messaging/quickstart/).
8
11
9
12
This example uses the Scaleway Serverless Framework Plugin. Please set up your environment with the requirements stated in the [Scaleway Serverless Framework Plugin](https://github.com/scaleway/serverless-scaleway-functions) before trying out the example.
10
13
11
-
## Description
14
+
Additionnaly it uses the [serverless-functions-go](https://github.com/scaleway/serverless-functions-go) library for local testing.
15
+
16
+
## Context
12
17
13
-
The function of the example is publishing a message to an SQS queue. The message is a JSON object with the following structure:
18
+
This example shows how to create a queue and send a message to a SQS. It can be extended to retrieve or delete queues, send batch messages, delete or retrieve messages, etc...
19
+
20
+
The function is publishing a message to an SQS queue. The message is a JSON object with the following structure:
14
21
15
22
```json
16
23
{
@@ -23,30 +30,43 @@ This function uses Golang 1.18 runtime.
23
30
24
31
## Setup
25
32
26
-
Once your environment is set up, you can run:
33
+
To use this example, the following environment variables are needed:
27
34
28
-
```console
29
-
go run .
35
+
*`SCW_ACCESS_KEY`: Your Scaleway access key
36
+
*`SCW_SECRET_KEY`: Your Scaleway secret key
37
+
*`SCW_DEFAULT_PROJECT_ID`: Your Scaleway project ID
38
+
*`SCW_DEFAULT_REGION`: Your Scaleway region
39
+
*`SCW_DEFAULT_ZONE`: Your Scaleway zone
40
+
*`SQS_ACCESS_KEY`: Your SQS access key
41
+
*`SQS_SECRET_KEY`: Your SQS secret key
30
42
31
-
serverless deploy
43
+
Once your environment is set up, you can test your function locally with:
44
+
45
+
```shell
46
+
go run test/main.go
32
47
```
33
48
34
-
## Needed environment variables
49
+
This will launch a local server, allowing you to test the function. For that, you can run in another terminal:
35
50
36
-
-`SCW_ACCESS_KEY`: Your Scaleway access key
37
-
-`SCW_SECRET_KEY`: Your Scaleway secret key
38
-
-`SCW_DEFAULT_PROJECT_ID`: Your Scaleway project ID
This example shows how to upload a file to an S3 bucket.
4
+
5
+
## Requirements
6
+
7
+
This example assumes that you are familiar with some products of Scaleway's ecosystem:
8
+
9
+
* how serverless functions work. If needed, you can check [Scaleway official documentation](https://www.scaleway.com/en/docs/serverless/functions/quickstart/).
10
+
* how Object Storage works. Please refer to scaleway's documentation [here](https://www.scaleway.com/en/docs/storage/object/quickstart/) for more information.
11
+
12
+
This example uses the Scaleway Serverless Framework Plugin. Please set up your environment with the requirements stated in the [Scaleway Serverless Framework Plugin](https://github.com/scaleway/serverless-scaleway-functions) before trying out the example.
13
+
14
+
Additionnaly it uses the [serverless-functions-go](https://github.com/scaleway/serverless-functions-go) library for local testing.
15
+
16
+
## Context
17
+
18
+
This example shows how to upload a file to an S3 bucket using serverless function. It also shows how you can test your function locally before deploying.
19
+
20
+
This function does the following steps:
2
21
3
-
This function does the following steps :
4
22
* Read a file from HTTP request
5
23
* Save the file locally in ephemeral storage
6
24
* Send file to S3 bucket
7
25
8
-
Additionnaly it uses the [serverless-functions-go](https://github.com/scaleway/serverless-functions-go) library for local testing
26
+
This function uses Golang 1.20 runtime.
9
27
10
-
## Requirements
28
+
## Setup
11
29
12
30
If you want to enable S3 upload, ensure to create a bucket and have the following secrets variables available in your environment:
13
31
14
-
```
32
+
```sh
15
33
S3_ENABLED=true
16
34
S3_ENDPOINT= # ex: sample.s3.fr-par.scw.cloud
17
35
S3_ACCESSKEY=
@@ -20,17 +38,40 @@ S3_BUCKET_NAME=
20
38
S3_REGION= # ex: fr-par
21
39
```
22
40
23
-
If s3 is not enabled the file will be saved on the ephemeral storage of your function.
41
+
If s3 is not enabled, the file will be saved on the ephemeral storage of your function.
42
+
43
+
Once your environment is set up, you can test your function locally with:
24
44
25
45
```sh
26
-
go get
46
+
go run test/main.go
47
+
```
27
48
28
-
# for local testing :
29
-
go run cmd/main.go
49
+
This will launch a local server, allowing you to test the function. For that, you can run in another terminal (replace `go.sum` with the file you want to upload):
50
+
51
+
```sh
52
+
curl -X POST http://localhost:8080 -H "Content-Type: multipart/form-data" -F "[email protected]"
30
53
```
31
54
32
-
To call the function (replace `go.sum` with the file you want to upload):
55
+
The logs should be similar to:
33
56
34
57
```sh
35
-
curl -X POST -H "Content-Type: multipart/form-data" -F "[email protected]" http://localhost:8080
58
+
2023/04/11 11:30:06 S3 upload enabled
59
+
2023/04/11 11:30:08 successfully created upload-file-to-s3
60
+
2023/04/11 11:30:09 Successfully uploaded /var/folders/wn/qnp2ebt54mz040bgffg35xt80000gn/T/go.sum of size 1234
36
61
```
62
+
63
+
## Deploy and run
64
+
65
+
Finally, if the test succeeded, you can deploy your function with:
0 commit comments