Skip to content

Commit b91101b

Browse files
noid11bmoffatt
andauthored
add Lambda Function URLs sample (#443)
* docs: add Lambda Function URLs sample * Update README_Lambda.md Co-authored-by: Bryan Moffatt <[email protected]>
1 parent ca99aa0 commit b91101b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

events/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ This package provides input types for Lambda functions that process AWS events.
5656

5757
[Kinesis Firehose Events](README_KinesisFirehose.md)
5858

59+
[Lambda Events](README_Lambda.md)
60+
5961
[Lex Events](README_Lex.md)
6062

6163
[S3 Events](README_S3.md)

events/README_Lambda.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Overview
2+
3+
Lambda events consist of a request that was routed to a Lambda function by the Lambda Function URLs feature. When this happens, Lambda expects the result of the function to be the response that Lambda should respond with.
4+
5+
# Sample Function
6+
7+
The following is a sample class and Lambda function that receives Lambda Function URLs event record data as an input, writes some of the record data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that anything written to stdout or stderr will be logged as CloudWatch Logs events.)
8+
9+
```go
10+
package main
11+
12+
import (
13+
"context"
14+
"fmt"
15+
16+
"github.com/aws/aws-lambda-go/events"
17+
"github.com/aws/aws-lambda-go/lambda"
18+
)
19+
20+
func handleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error) {
21+
fmt.Printf("Processing request data for request %s.\n", request.RequestContext.RequestID)
22+
fmt.Printf("Body size = %d.\n", len(request.Body))
23+
24+
fmt.Println("Headers:")
25+
for key, value := range request.Headers {
26+
fmt.Printf(" %s: %s\n", key, value)
27+
}
28+
29+
return events.LambdaFunctionURLResponse{Body: request.Body, StatusCode: 200}, nil
30+
}
31+
32+
func main() {
33+
lambda.Start(handleRequest)
34+
}
35+
```

0 commit comments

Comments
 (0)