feat(aws-cdk): detailed ECS service and container-level logs on cdk deployment failures#1505
Open
iankhou wants to merge 13 commits into
Open
feat(aws-cdk): detailed ECS service and container-level logs on cdk deployment failures#1505iankhou wants to merge 13 commits into
iankhou wants to merge 13 commits into
Conversation
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
…gestions to turn on cw logging format changes
5cb6bde to
2a8c6c1
Compare
There was a problem hiding this comment.
Pull request overview
This PR enhances CDK deployment diagnostics by enriching failed CloudFormation resource errors with best-effort, service-specific investigation results—initially focused on ECS services—so users can see stopped-task reasons and recent CloudWatch Logs directly in failure output.
Changes:
- Add ECS resource investigation that gathers stopped task details, container image info, and recent CloudWatch Logs (with line caps).
- Extend stack diagnosis to attach and format additional per-resource diagnostic context.
- Wire an optional “exploration SDK” (preferably lookup-role) into deploy/diagnose flows and expand the SDK ECS surface area to support investigation calls.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/@aws-cdk/toolkit-lib/test/api/diagnosing/resource-investigation.test.ts | Adds unit tests for ECS identifier parsing and ECS investigation behaviors (stopped tasks, logs, truncation). |
| packages/@aws-cdk/toolkit-lib/test/api/diagnosing/snapshots/diagnosis-formatting.test.ts.snap | Updates snapshot header text. |
| packages/@aws-cdk/toolkit-lib/test/api/aws-auth/snapshots/sdk-logger.test.ts.snap | Updates snapshot header text. |
| packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts | Passes an exploration SDK provider into the diagnoser for toolkit-driven diagnosis. |
| packages/@aws-cdk/toolkit-lib/lib/api/diagnosing/stack-diagnoser.ts | Enhances errors with additional investigation context and adds fallback diagnosis behavior. |
| packages/@aws-cdk/toolkit-lib/lib/api/diagnosing/resource-investigation.ts | Implements ECS service investigation (stopped tasks + CloudWatch Logs deep links + log truncation). |
| packages/@aws-cdk/toolkit-lib/lib/api/diagnosing/diagnosis-formatting.ts | Renders additionalContext blocks beneath resource errors in the formatted diagnosis output. |
| packages/@aws-cdk/toolkit-lib/lib/api/deployments/deployments.ts | Provides a lookup-role-based exploration SDK provider for deployments. |
| packages/@aws-cdk/toolkit-lib/lib/api/aws-auth/sdk.ts | Adds ECS methods (DescribeServices/DescribeTasks/DescribeTaskDefinition) to the SDK wrapper. |
| packages/@aws-cdk/toolkit-lib/lib/actions/diagnose/index.ts | Extends TracedResourceError with optional additionalContext and defines its shape. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+70
to
+78
| const taskDefInfo = await getTaskDefinitionInfo(ecs, taskDefinitionArn, debug); | ||
|
|
||
| if (taskDefInfo && taskDefInfo.images.length > 0) { | ||
| results.push({ source: 'Container Images', messages: taskDefInfo.images }); | ||
| } | ||
|
|
||
| const logConfigs = taskDefInfo?.logConfigs ?? []; | ||
|
|
||
| if (logConfigs.length === 0) { |
Comment on lines
+93
to
+108
| // eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism | ||
| const logResults = await Promise.all(logConfigs.map(cfg => fetchRecentLogs(cwl, cfg, region, stoppedTaskResult.taskIds, debug))); | ||
| let hasLogs = false; | ||
| for (const context of logResults) { | ||
| if (context) { | ||
| results.push(context); | ||
| hasLogs = true; | ||
| } | ||
| } | ||
|
|
||
| if (!hasLogs) { | ||
| results.push({ | ||
| source: 'CloudWatch Logs', | ||
| messages: ['No application logs found (container may not have started). Check the stopped task reasons above for details.'], | ||
| }); | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pending tests and potential cleanups with custom resource implementation. Pending dual-role implementation (allow using lookup role or deploy role).
Logs from running with https://github.com/iankhou/cdk-app-with-problems. There are several branches demonstrating different failure modes:
See the following file for log examples:
lcdk deploy results.md
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license