Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/44843.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
action/aws_lambda_invoke: Output logs in a progress message when `log_type` is `Tail`
```
45 changes: 29 additions & 16 deletions internal/service/lambda/invoke_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,7 @@ func (a *invokeAction) Invoke(ctx context.Context, req action.InvokeRequest, res
// Handle different invocation types
switch invocationType {
case awstypes.InvocationTypeRequestResponse:
// For synchronous invocations, we get an immediate response
statusCode := output.StatusCode
payloadLength := len(output.Payload)

var message string
if logType == awstypes.LogTypeTail && output.LogResult != nil {
message = fmt.Sprintf("Lambda function %s invoked successfully (status: %d, payload: %d bytes, logs included)",
functionName, statusCode, payloadLength)
} else {
message = fmt.Sprintf("Lambda function %s invoked successfully (status: %d, payload: %d bytes)",
functionName, statusCode, payloadLength)
}

resp.SendProgress(action.InvokeProgressEvent{
Message: message,
})
a.handleSyncInvocation(resp, functionName, output, logType)

case awstypes.InvocationTypeEvent:
// For asynchronous invocations, we only get confirmation that the request was accepted
Expand All @@ -214,3 +199,31 @@ func (a *invokeAction) Invoke(ctx context.Context, req action.InvokeRequest, res
"payload_length": len(output.Payload),
})
}

func (a *invokeAction) handleSyncInvocation(resp *action.InvokeResponse, functionName string, output *lambda.InvokeOutput, logType awstypes.LogType) {
statusCode := output.StatusCode
payloadLength := len(output.Payload)

// Send success message
resp.SendProgress(action.InvokeProgressEvent{
Message: fmt.Sprintf("Lambda function %s invoked successfully (status: %d, payload: %d bytes)",
functionName, statusCode, payloadLength),
})

// Output logs if available
if logType != awstypes.LogTypeTail || output.LogResult == nil {
return
}

logData, err := base64.StdEncoding.DecodeString(aws.ToString(output.LogResult))
if err != nil {
resp.SendProgress(action.InvokeProgressEvent{
Message: fmt.Sprintf("Failed to decode Lambda logs: %s", err),
})
return
}

resp.SendProgress(action.InvokeProgressEvent{
Message: fmt.Sprintf("Lambda function logs:\n%s", string(logData)),
})
}
2 changes: 1 addition & 1 deletion website/docs/actions/lambda_invoke.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ This action supports the following arguments:
* `client_context` - (Optional) Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object. This is only used for mobile applications and should contain information about the client application and device.
* `function_name` - (Required) Name, ARN, or partial ARN of the Lambda function to invoke. You can specify a function name (e.g., `my-function`), a qualified function name (e.g., `my-function:PROD`), or a partial ARN (e.g., `123456789012:function:my-function`).
* `invocation_type` - (Optional) Invocation type. Valid values are `RequestResponse` (default) for synchronous invocation that waits for the function to complete and returns the response, `Event` for asynchronous invocation that returns immediately after the request is accepted, and `DryRun` to validate parameters and verify permissions without actually executing the function.
* `log_type` - (Optional) Set to `Tail` to include the execution log in the response. Only applies to synchronous invocations (`RequestResponse` invocation type). Defaults to `None`. When set to `Tail`, the last 4 KB of the execution log is included in the response.
* `log_type` - (Optional) Set to `Tail` to include the execution log in the response. Only applies to synchronous invocations (`RequestResponse` invocation type). Defaults to `None`. When set to `Tail`, the last 4 KB of the execution log is included in the response and output as part of the progress messages.
* `payload` - (Required) JSON payload to send to the Lambda function. This should be a valid JSON string that represents the event data for your function. The payload size limit is 6 MB for synchronous invocations and 256 KB for asynchronous invocations.
* `region` - (Optional) Region where this action should be [run](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
* `qualifier` - (Optional) Version or alias of the Lambda function to invoke. If not specified, the `$LATEST` version will be invoked. Can be a version number (e.g., `1`) or an alias (e.g., `PROD`).
Loading