Skip to content

Commit 3b7d929

Browse files
committed
aws_lambda_invoke_action: Output logs
1 parent 148d66e commit 3b7d929

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

internal/service/lambda/invoke_action.go

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,7 @@ func (a *invokeAction) Invoke(ctx context.Context, req action.InvokeRequest, res
173173
// Handle different invocation types
174174
switch invocationType {
175175
case awstypes.InvocationTypeRequestResponse:
176-
// For synchronous invocations, we get an immediate response
177-
statusCode := output.StatusCode
178-
payloadLength := len(output.Payload)
179-
180-
var message string
181-
if logType == awstypes.LogTypeTail && output.LogResult != nil {
182-
message = fmt.Sprintf("Lambda function %s invoked successfully (status: %d, payload: %d bytes, logs included)",
183-
functionName, statusCode, payloadLength)
184-
} else {
185-
message = fmt.Sprintf("Lambda function %s invoked successfully (status: %d, payload: %d bytes)",
186-
functionName, statusCode, payloadLength)
187-
}
188-
189-
resp.SendProgress(action.InvokeProgressEvent{
190-
Message: message,
191-
})
176+
a.handleSyncInvocation(resp, functionName, output, logType)
192177

193178
case awstypes.InvocationTypeEvent:
194179
// For asynchronous invocations, we only get confirmation that the request was accepted
@@ -214,3 +199,31 @@ func (a *invokeAction) Invoke(ctx context.Context, req action.InvokeRequest, res
214199
"payload_length": len(output.Payload),
215200
})
216201
}
202+
203+
func (a *invokeAction) handleSyncInvocation(resp *action.InvokeResponse, functionName string, output *lambda.InvokeOutput, logType awstypes.LogType) {
204+
statusCode := output.StatusCode
205+
payloadLength := len(output.Payload)
206+
207+
// Send success message
208+
resp.SendProgress(action.InvokeProgressEvent{
209+
Message: fmt.Sprintf("Lambda function %s invoked successfully (status: %d, payload: %d bytes)",
210+
functionName, statusCode, payloadLength),
211+
})
212+
213+
// Output logs if available
214+
if logType != awstypes.LogTypeTail || output.LogResult == nil {
215+
return
216+
}
217+
218+
logData, err := base64.StdEncoding.DecodeString(aws.ToString(output.LogResult))
219+
if err != nil {
220+
resp.SendProgress(action.InvokeProgressEvent{
221+
Message: fmt.Sprintf("Failed to decode Lambda logs: %s", err),
222+
})
223+
return
224+
}
225+
226+
resp.SendProgress(action.InvokeProgressEvent{
227+
Message: fmt.Sprintf("Lambda function logs:\n%s", string(logData)),
228+
})
229+
}

0 commit comments

Comments
 (0)