Aws/logs
Query and analyze CloudWatch Logs for operational visibility and incident investigation.
Authentication
Uses the default AWS credential chain. Set the optional profile global argument to
resolve credentials from a named AWS shared-config profile (SSO token cache / fromIni),
enabling multi-account use within a single swamp repo.
Requires CloudWatch Logs permissions.
Required IAM Permissions
logs:DescribeLogGroupslogs:StartQuerylogs:GetQueryResultslogs:FilterLogEvents
Usage
# Create logs model (default credential chain)
swamp model create @webframp/aws/logs aws-logs --global-arg region=us-east-1
# Create logs model with a named profile for multi-account use
swamp model create @webframp/aws/logs aws-logs-prod \
--global-arg region=us-east-1 --global-arg profile=prod-account
# List log groups
swamp model method run aws-logs list_log_groups --input prefix=/aws/lambda
# Run a Logs Insights query
swamp model method run aws-logs query \
--input 'logGroupNames=["/aws/lambda/my-function"]' \
--input 'queryString=fields @timestamp, @message | filter @message like /error/i | limit 50' \
--input startTime=1h
# Find error patterns
swamp model method run aws-logs find_errors \
--input 'logGroupNames=["/aws/lambda/my-function"]' \
--input startTime=2h
# Get recent events with filter
swamp model method run aws-logs get_recent_events \
--input logGroupName=/aws/lambda/my-function \
--input filterPattern=ERRORTime Formats
The startTime and endTime parameters accept:
- Relative times:
30m,1h,2d(minutes, hours, days ago) - ISO 8601 dates:
2026-03-30T12:00:00Z
Methods
- list_log_groups - Discover log groups by prefix
- query - Run CloudWatch Logs Insights queries
- find_errors - Analyze error patterns with keyword detection
- get_recent_events - Filter recent log events
2026.07.30.2
Fixed: The query and find_errors methods now fail when a Logs Insights query
does not reach Complete status. Previously, a timed-out query (status Running) or
a terminal failure (Failed/Cancelled) was stored as a successful result with zero
rows, misleading downstream consumers.
Added: requireComplete argument on the query method (default true). Set to
false to store partial/incomplete results without error — useful for callers that
inspect the status field themselves.
Changed: When a query times out with requireComplete: true, the method cancels
the in-progress query via StopQuery before throwing, preventing orphaned scans from
continuing to consume resources.
| Argument | Type | Description |
|---|---|---|
| logGroupName | string | Log group name |
Resources
2026.07.30.1
Added: Optional profile global argument for multi-account credential resolution.
When set, credentials resolve via fromIni (supports SSO token cache and shared-config
profiles). When omitted, the default credential chain applies as before. Fully backward
compatible — no changes required for existing instances.
Changed: Internal client construction extracted into a shared makeClient helper.
No behavioral difference for instances without a profile set.
2026.07.29.1
Fixed: Terminate upgrade chain at current version (extension was uninstallable due to broken upgrade chain).
2026.07.27.1
Changed: Bump @aws-sdk/client-cloudwatch-logs 3.1094.0 → 3.1096.0
2026.07.24.1
Changed: Bump AWS SDK from 3.1091.0 to 3.1094.0 (patch-level update).
2026.07.24.1
Changed: Bump AWS SDK from 3.1091.0 to 3.1094.0 (patch-level update).
2026.07.21.1
Changed: Bumped AWS SDK dependencies to 3.1091.0 (from 3.1090.0).
Upgrade note: No behavioral changes. Routine dependency maintenance.
2026.07.18.2
Added: An upgrades array entry (no-op) to logs.ts for proper
typeVersion tracking on existing instances. No schema or behavior changes.
2026.07.18.1
Changed: Bumped @aws-sdk/client-cloudwatch-logs from 3.1069.0 to
3.1090.0 for dependency freshness. No behavior change.
2026.07.13.1
Fixed: The query method wrote its query_results resource under an
instance name built from Date.now() (query-<ts>-<firstLogGroup>), so every
run created a new resource instead of updating the existing one — unbounded
data accumulation, against the repo's "deterministic resource instance names"
rule. It now keys on a collision-resistant SHA-1 hash of the sorted log group
names plus the query string: query-<sha1>.
Changed: The analyze_errors method's error_analysis instance name
previously used only the first log group (errors-<firstLogGroup>), which
collides when different multi-group analyses share a first group. It now hashes
the full sorted log group set: errors-<sha1>.
Upgrade note: After upgrading, the first run of query / analyze_errors
writes to the new stable instance names; old instances remain until garbage
collected. Re-runs then overwrite the latest snapshot as intended.
2026.07.18.1
Changed: Bumped @aws-sdk/client-cloudwatch-logs from 3.1069.0 to
3.1090.0 for dependency freshness. No behavior change.
2026.07.13.1
Fixed: The query method wrote its query_results resource under an
instance name built from Date.now() (query-<ts>-<firstLogGroup>), so every
run created a new resource instead of updating the existing one — unbounded
data accumulation, against the repo's "deterministic resource instance names"
rule. It now keys on a collision-resistant SHA-1 hash of the sorted log group
names plus the query string: query-<sha1>.
Changed: The analyze_errors method's error_analysis instance name
previously used only the first log group (errors-<firstLogGroup>), which
collides when different multi-group analyses share a first group. It now hashes
the full sorted log group set: errors-<sha1>.
Upgrade note: After upgrading, the first run of query / analyze_errors
writes to the new stable instance names; old instances remain until garbage
collected. Re-runs then overwrite the latest snapshot as intended.
2026.07.13.1
Fixed: The query method wrote its query_results resource under an
instance name built from Date.now() (query-<ts>-<firstLogGroup>), so every
run created a new resource instead of updating the existing one — unbounded
data accumulation, against the repo's "deterministic resource instance names"
rule. It now keys on a collision-resistant SHA-1 hash of the sorted log group
names plus the query string: query-<sha1>.
Changed: The analyze_errors method's error_analysis instance name
previously used only the first log group (errors-<firstLogGroup>), which
collides when different multi-group analyses share a first group. It now hashes
the full sorted log group set: errors-<sha1>.
Upgrade note: After upgrading, the first run of query / analyze_errors
writes to the new stable instance names; old instances remain until garbage
collected. Re-runs then overwrite the latest snapshot as intended.
updated platforms
- Has README or module doc2/2earned
- README has a code example1/1earned
- README is substantive1/1earned
- Most symbols documented1/1earned
- No slow types (deprecated)1/1earned
- Dependencies pass trust audit2/2earned
- Has description1/1earned
- Platform support declared (or universal)2/2earned
- License declared1/1earned
- Verified public repository2/2earned