-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsqs.go
43 lines (35 loc) · 949 Bytes
/
sqs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package lambda
import (
"context"
"os"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambdacontext"
)
func sqs(h func(ctx context.Context, request events.SQSEvent) error) Response {
response := Response{
Payload: Payload{},
}
event := events.SQSEvent{}
err := decode(os.Getenv("LAMBDA_EVENT"), &event)
if err != nil {
response.Payload.Error = err.Error()
return response
}
ctxArgs := map[string]interface{}{}
err = decode(os.Getenv("LAMBDA_CONTEXT"), &ctxArgs)
if err != nil {
response.Payload.Error = err.Error()
return response
}
ctx := lambdacontext.NewContext(context.Background(), &lambdacontext.LambdaContext{
AwsRequestID: ctxArgs["awsRequestId"].(string),
InvokedFunctionArn: ctxArgs["invokedFunctionArn"].(string),
})
err = h(ctx, event)
if err != nil {
response.Payload.Error = err.Error()
return response
}
response.Payload.Success = err != nil
return response
}