Invoke method try to perform a command given an InvokeRequest and an InvokeResponse
(req *messages.InvokeRequest, response *messages.InvokeResponse)
| 67 | |
| 68 | // Invoke method try to perform a command given an InvokeRequest and an InvokeResponse |
| 69 | func (fn *Function) Invoke(req *messages.InvokeRequest, response *messages.InvokeResponse) error { |
| 70 | defer func() { |
| 71 | if err := recover(); err != nil { |
| 72 | response.Error = lambdaPanicResponse(err) |
| 73 | } |
| 74 | }() |
| 75 | |
| 76 | deadline := time.Unix(req.Deadline.Seconds, req.Deadline.Nanos).UTC() |
| 77 | invokeContext, cancel := context.WithDeadline(fn.baseContext(), deadline) |
| 78 | defer cancel() |
| 79 | |
| 80 | lc := &lambdacontext.LambdaContext{ |
| 81 | AwsRequestID: req.RequestId, |
| 82 | InvokedFunctionArn: req.InvokedFunctionArn, |
| 83 | Identity: lambdacontext.CognitoIdentity{ |
| 84 | CognitoIdentityID: req.CognitoIdentityId, |
| 85 | CognitoIdentityPoolID: req.CognitoIdentityPoolId, |
| 86 | }, |
| 87 | } |
| 88 | if len(req.ClientContext) > 0 { |
| 89 | if err := json.Unmarshal(req.ClientContext, &lc.ClientContext); err != nil { |
| 90 | response.Error = lambdaErrorResponse(err) |
| 91 | return nil |
| 92 | } |
| 93 | } |
| 94 | invokeContext = lambdacontext.NewContext(invokeContext, lc) |
| 95 | |
| 96 | // nolint:staticcheck |
| 97 | invokeContext = context.WithValue(invokeContext, "x-amzn-trace-id", req.XAmznTraceId) |
| 98 | os.Setenv("_X_AMZN_TRACE_ID", req.XAmznTraceId) |
| 99 | |
| 100 | payload, err := fn.handler.Invoke(invokeContext, req.Payload) |
| 101 | if err != nil { |
| 102 | response.Error = lambdaErrorResponse(err) |
| 103 | return nil |
| 104 | } |
| 105 | response.Payload = payload |
| 106 | return nil |
| 107 | } |
| 108 | |
| 109 | func (fn *Function) baseContext() context.Context { |
| 110 | if fn.handler.baseContext != nil { |