feat(lambda): fetch CloudWatch logs after Lambda invocation#677
Conversation
Fetches CloudWatch Logs for AWS Lambda invocations using FilterLogEvents paginator and streams log messages into the task logger. Includes unit tests covering log retrieval and logging behavior.
fdelbrayelle
left a comment
There was a problem hiding this comment.
Hello @shivamwayal37 👋
Could you provide screenshots where you used this plugin fix with an actual AWS actual with Lambdas and show the logs?
Thanks!
|
Hello @fdelbrayelle, Thanks for the review and approval 🙂 Thanks again! |
|
Thank you @shivamwayal37, it seems great but CI fails on a test, could you check please? 🙏 |
|
Hello @fdelbrayelle, Thanks for pointing that out! I've investigated the CI failure and can confirm it's unrelated to my changes. The failure occurred in io.kestra.plugin.aws.kinesis.ConsumeTest (java.lang.AssertionError: Expected: is <1> but: was <10>). This appears to be a flaky test in the Kinesis package. On my side, I’ve verified that all tests in io.kestra.plugin.aws.lambda.* (including the updated unit test for the new polling logic) are passing locally and in the CI logs. I have also cleaned up the code (reverted the version and removed debug logs) as requested. I will try to rerun the CI job now to see if it clears up! |
|
Hey @fdelbrayelle, Technical Improvements:
|
|
Hi @shivamwayal37 👋 Indeed there's another PR to fix the flaky tests, so LGTM! |
|
Thanks for the heads-up. The CI failures don’t seem related to this PR’s changes. The failing tests are integration-style tests (AWS CLI, CloudWatch, triggers) and are erroring due to external dependencies not being available in CI (e.g. LocalStack/CloudWatch returning 500 or connection refused on 127.0.0.1:4566). The Lambda-related changes introduced in this PR are covered by InvokeUnitTest and InvokeTest, which are passing. I’ll rebase on the latest main and re-run the checks to see if this is a transient CI issue. |
|
I noticed the latest CI failures are in integration-style tests (AwsCLITest, CloudWatch Push/Query/Trigger) that depend on external services. The errors look like LocalStack / CloudWatch not being available in CI (127.0.0.1:4566 connection refused / 500 responses). All Lambda-related tests touched by this PR (InvokeUnitTest, InvokeTest) are passing consistently. Happy to help investigate or adjust the CI setup for these tests if that would be useful. |
|
OK let's merge it seems related to the PR coming from a fork! |
|
Thanks for the review! |
|
It seems to be still failing on main @shivamwayal37 and since you updated |
|
Thanks for the heads-up 🙏 |
|
I checked main locally and can reproduce the failures. All failing tests are Testcontainers / LocalStack integration tests and fail early with Could not find a valid Docker environment (/var/run/docker.sock not found). InvokeUnitTest and other unit/mocked tests are passing consistently. This looks like a Docker availability issue in CI rather than a regression from the Invoke changes. Happy to help adjust the CI setup or skip these tests when Docker isn’t available if that helps. |
|
Hmm but it was passing before your PR so it must be related to one of your changes... Could you investigate more please? |
|
Thanks for the clarification — that’s fair. |
* feat(lambda): fetch CloudWatch logs after Lambda invocation Fetches CloudWatch Logs for AWS Lambda invocations using FilterLogEvents paginator and streams log messages into the task logger. Includes unit tests covering log retrieval and logging behavior. * fix(lambda): improve CloudWatch log polling and stabilize unit test * chore: trigger CI re-run for flaky test * Refactor fetchAndLogLambdaLogs to use RetryUtils with proper retry policy * Bump kestraVersion to 1.2.0 for RetryUtils static method * Fix annotation formatting in Invoke plugin * chore: sync with main and trigger CI for #677 * fix(lambda): stabilize CloudWatch log polling and unit tests --------- Co-authored-by: François Delbrayelle <fdelbrayelle@gmail.com>
closes kestra-io/kestra#8978
What changes are being made and why?
This PR adds support for fetching CloudWatch Logs for AWS Lambda invocations and streaming them directly into the task logger.
Key changes:
Why:
This improves observability for Lambda tasks in Kestra by allowing developers to see the Lambda execution logs directly in the task output, making debugging and monitoring easier.
How the changes have been QAed?
Added unit tests in InvokeUnitTest that:
Terminal Output:
Setup Instructions
No additional setup is required beyond standard AWS credentials with permissions to:
Contributor Checklist ✅
closes #ISSUE_IDorfixes #ISSUE_IDin the description if the PR relates to an opened issue.@Schemafor properties and outputs,@Pluginwith examples,README.mdfile with basic knowledge and specifics).rnotrendered(eg:rHost).runContext.logger()to log enough important infos where it's needed and with the best level (DEBUG, INFO, WARN or ERROR).⚙️ Properties
Property<T>carrier type, do not use@PluginProperty.@NotNulland checked during the rendering.Property<Map<String, Object>>.🌐 HTTP
io.kestra.core.http.client📦 JSON
@JsonIgnoreProperties(ignoreUnknown = true)at the mapped class level. So that we will avoid to crash the plugin if the provider add a new field suddenly.io.kestra.core.serializers)✨ New plugins / subplugins
package-info.javaunder each sub package respecting this format and choosing the right category.runContext.metric(...)you have to add a@Metric(see this doc)io.kestra.plugin.kubernetes) and in a sub package (e.g.io.kestra.plugin.kubernetes.kubectl), whether it's: all tasks/triggers in the root package OR only tasks/triggers in sub packages.src/main/resources/iconsin SVG format and not in thumbnail (keep it big):plugin-icon.svgio.kestra.plugin.aws.svgio.kestra.plugin.aws.s3, addio.kestra.plugin.aws.s3.svgSee example here.
"{{ secret('YOUR_SECRET') }}"in the examples for sensible infos such as an API KEY.Property<FetchType> fetchTypeto be able to useFETCH_ONE,FETCHand evenSTOREto store big amount of data in the internal storage."""to close examples blocks with the flow id.index.yamlfor the main plugin, and for each new subpackage add a metadata file named exactly after the subpackage (e.g.s3.yamlforio.kestra.plugin.aws.s3) undersrc/main/resources/metadata/, following the same schema.🧪 Tests
RunContextto actually run tasks).src/test/resources/flows..github/setup-unit.sh(to be set executable withchmod +x setup-unit.sh) (which can be executed locally and in the CI) all along with a newdocker-compose-ci.ymlfile (do not edit the existingdocker-compose.yml). If needed, create an executable (chmod +x cleanup-unit.sh)cleanup-unit.shto remove the potential costly resources (tables, datasets, etc).📤 Outputs
VoidOutput.