MCPcopy
hub / github.com/aws/aws-lambda-go / Invoke

Method Invoke

lambda/rpc_function.go:69–107  ·  view source on GitHub ↗

Invoke method try to perform a command given an InvokeRequest and an InvokeResponse

(req *messages.InvokeRequest, response *messages.InvokeResponse)

Source from the content-addressed store, hash-verified

67
68// Invoke method try to perform a command given an InvokeRequest and an InvokeResponse
69func (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
109func (fn *Function) baseContext() context.Context {
110 if fn.handler.baseContext != nil {

Callers 8

TestInvokeFunction · 0.95
TestInvokeWithContextFunction · 0.95
TestCustomErrorFunction · 0.95
TestCustomErrorRefFunction · 0.95
TestContextPlumbingFunction · 0.95
TestXAmznTraceIDFunction · 0.95

Calls 5

baseContextMethod · 0.95
NewContextFunction · 0.92
lambdaPanicResponseFunction · 0.85
lambdaErrorResponseFunction · 0.85
InvokeMethod · 0.65

Tested by 8

TestInvokeFunction · 0.76
TestInvokeWithContextFunction · 0.76
TestCustomErrorFunction · 0.76
TestCustomErrorRefFunction · 0.76
TestContextPlumbingFunction · 0.76
TestXAmznTraceIDFunction · 0.76