MCPcopy Create free account
hub / github.com/awsdocs/aws-lambda-developer-guide / handleRequest

Function handleRequest

sample-apps/blank-go/function/main.go:25–49  ·  view source on GitHub ↗
(ctx context.Context, event events.SQSEvent)

Source from the content-addressed store, hash-verified

23}
24
25func handleRequest(ctx context.Context, event events.SQSEvent) (string, error) {
26 // event
27 eventJson, _ := json.MarshalIndent(event, "", " ")
28 log.Printf("EVENT: %s", eventJson)
29 // environment variables
30 log.Printf("REGION: %s", os.Getenv("AWS_REGION"))
31 log.Println("ALL ENV VARS:")
32 for _, element := range os.Environ() {
33 log.Println(element)
34 }
35 // request context
36 lc, _ := lambdacontext.FromContext(ctx)
37 log.Printf("REQUEST ID: %s", lc.AwsRequestID)
38 // global variable
39 log.Printf("FUNCTION NAME: %s", lambdacontext.FunctionName)
40 // context method
41 deadline, _ := ctx.Deadline()
42 log.Printf("DEADLINE: %s", deadline)
43 // AWS SDK call
44 usage, err := callLambda()
45 if err != nil {
46 return "ERROR", err
47 }
48 return usage, nil
49}
50
51func main() {
52 runtime.Start(handleRequest)

Callers 1

TestMainFunction · 0.70

Calls 1

callLambdaFunction · 0.85

Tested by 1

TestMainFunction · 0.56