stacktape logs prints the logs of a deployed resource from its CloudWatch log group. By default it shows recent log lines, optionally filtered by time and pattern. With --query, it runs a CloudWatch Logs Insights query instead.
Usage
The command finds the log group through your Stacktape config and the deployed stack, so run it in the project directory or pass --config.
Fetch the last hour of logs from a resource named myApi.
Fetch logs from a container workload. Use --container to specify which container's log group to target.
Two modes
Standard mode
Standard mode fetches recent log events from the resource's CloudWatch log group. By default it returns up to 100 events from the last hour. Narrow results with --since, --filter, and --limit.
The command resolves log streams for the target log group, fetches matching events, and either formats them for terminal display or outputs JSON when --raw or --agent is set.
In an interactive terminal, the command shows the same newest events (up to --limit, 100 by default) and then follows the log group, printing new events that match --filter as they arrive until you press Ctrl+C. It sends at most two CloudWatch Logs requests per second, so following a busy production log group stays within the account's request quota. When the output is piped or redirected, or with --raw or --agent, the command prints the events once and exits. --follow=false does the same in a terminal.
--follow keeps following without a terminal, for example in a coding agent's shell or in CI. Each log line is written as plain text as soon as it arrives (with --agent, as NDJSON records; see below). The command ends on Ctrl+C or SIGTERM, and when the reading end of its output closes, as with | head -20: it notices on the next line it writes. --follow cannot be combined with --raw.
Insights mode
Pass a --query flag to run a CloudWatch Logs Insights query instead. Insights mode lets you aggregate, sort, and transform log data using the Logs Insights query language. When --query is provided, the command calls CloudWatch Logs Insights and prints the returned results.
A resource with logging.logClass: infrequent-access can't be filtered or followed: CloudWatch supports neither for that log class. The command then runs a bounded Logs Insights snapshot instead, prints the events in the usual shape and exits. Use --query instead of --filter to narrow such a log group.
In Insights mode, non-agent output prints each result row with a highlighted timestamp and message. In agent mode, that JSON payload is text in a type: "log" record's message within the CLI NDJSON stream; the final result record is separate.
Important flags
startTime
Controls how far back to fetch logs. Accepts two formats:
- Relative shorthand — a number followed by a unit:
1h(1 hour),30m(30 minutes),1d(1 day),5s(5 seconds). This counts back from--until, or now when it is omitted. - Absolute date — any string the JavaScript
Dateconstructor accepts, such as2026-05-28T14:00:00Z.
When omitted, defaults to 1 hour ago.
filter
A CloudWatch Logs filter pattern applied server-side before events are returned. Supports simple text matching and structured JSON filter syntax. See the AWS filter pattern documentation for the full syntax. This flag applies in standard mode only.
Match any log line containing the word "ERROR".
Match structured JSON logs where the level field equals "error".
query
A CloudWatch Logs Insights query string. When provided, the command switches to Insights mode. Insights queries support aggregation (stats count(*)), pattern matching (parse), and field extraction — useful for understanding error rates, latency distributions, or any structured analysis across large volumes of logs.
limit
Maximum number of log events to return in standard mode. Defaults to 100. Increase for deeper debugging sessions; keep low for quick checks.
container
Specifies which container's log group to target. This flag is optional in the CLI schema and is passed to the log group resolver. Use it when the deployed resource has more than one container (e.g., a multi-container workload) and Stacktape needs a container name to identify the correct log group.
raw
Outputs logs as JSON instead of the default formatted view. In standard mode, the output is a JSON object with logGroup and events fields, where each event has timestamp, message, and logStream. Useful for piping into jq or other tools.
agent
Without --follow, --agent uses the CLI NDJSON protocol. The log payload is JSON text inside a type: "log" record's message; the final type: "result" record is separate and has result: null. Standard-mode payloads contain logGroup and events; Insights payloads contain logGroup, query and results. Parse both the protocol and the message payload, or use MCP stacktape_cli, which extracts it. Do not parse all stdout as one log object.
With --agent --follow, every line of stdout stays an NDJSON record. Each batch of new events is a type: "log" record whose message holds the same logGroup/events JSON as the one-shot payload, so the same parser reads both. The final result record follows when following ends.
--until bounds the one-shot fetch, Insights queries and the initial follow backlog, and anchors a relative --since. Following continues beyond that time.
Output format
In standard mode, the output is formatted for the terminal. Pass --raw for plain JSON, or --agent for the CLI's JSONL protocol.
--raw prints this JSON object for standard retrieval. With --agent without --follow, this is the payload encoded as text in a log record's message:
{ "logGroup": "/aws/lambda/my-stack-myApi", "events": [ { "timestamp": "2026-05-29T10:15:30.000Z", "message": "Processing request...", "logStream": "2026/05/29/[$LATEST]abc123" } ]}In Insights mode with --agent, the log record's JSON message payload includes the query and results:
{ "logGroup": "/aws/lambda/my-stack-myApi", "query": "fields @timestamp, @message | limit 10", "results": [ { "@timestamp": "2026-05-29T10:15:30", "@message": "Processing request..." } ]}If the resource has no log streams yet, the command prints an empty result. With --agent, the log record's message then contains {"logGroup": "...", "events": []}.
How log group resolution works
The command initializes the deployed stack and resolves the CloudWatch log group for the resource name you pass as the first argument. The optional --container flag is forwarded to the resolver so it can target the intended container when the resource has multiple containers.
The resolver works with compute resources that write to CloudWatch Logs. For container resources with multiple containers, pass --container so the resolver can identify the correct log group.
Examples
Fetch the last 30 minutes of logs.
Fetch only error-level logs from the last day.
Run a Logs Insights query to count errors by 5-minute window.
Get raw JSON output for piping into another tool.
Fetch logs from a specific container in a multi-container workload.
Use agent mode for structured output in a CI script.
logs FAQ
How much does CloudWatch Logs cost?
CloudWatch Logs pricing depends on ingestion, storage, retrieval, and query/analysis usage. Logs Insights queries (via --query) charge per GB of data scanned. High-throughput production services should consider setting log retention limits or using log forwarding to cheaper storage. Check the AWS CloudWatch pricing page for current rates.
Options
stacktape logs <resource-name>19 optionsThe AWS region for the operation.
For a list of available regions, see the AWS documentation.
Inside a project whose config declares
region, the flag is optional and overrides the config.21 allowed values:us-east-2us-east-1us-west-1us-west-2ap-east-1ap-south-1Show all
ap-northeast-3ap-northeast-2ap-southeast-1ap-southeast-2ap-northeast-1ca-central-1eu-central-1eu-west-1eu-west-2eu-west-3eu-north-1me-south-1sa-east-1af-south-1eu-south-1The name of the resource as defined in your Stacktape configuration.
The stage for the operation (e.g.,
production,staging,dev-john).You can set a default stage using the
defaults setcommand. Stage names use lowercase letters, numbers and dashes, with at least 2 characters. The project name, a dash and the stage form the CloudFormation stack name, which can have at most 128 characters. Stacktape shortens an AWS resource name that would be too long and adds a hash.--aws-accountstringThe name of the AWS account to use for the operation.
The account must first be connected in the Stacktape Console.
Without it, the account is chosen by
--profile,AWS_PROFILEor AWS credentials in environment variables, then by your saved default, then by your organization's only connected account.--aws-accounttakes precedence over all of them, but AWS credentials in environment variables must then belong to that account.-c, --configstringThe path to your Stacktape configuration file, relative to the current working directory.
Without it, Stacktape uses the one
stacktape.ts,stacktape.yml,stacktape.yamlorstacktape.jsin the working directory. When there are several, the command stops and asks you to choose one with this option.--containerstringThe name of the container as defined in your container compute resource configuration.
--cwdstringThe working directory for the operation.
All file paths in your configuration will be resolved relative to this directory. By default, this is the directory containing the configuration file.
--untilnumber | stringThe query end time; accepts JavaScript
Dateinputs and defaults to now.Relative
--sincecounts back from it. Metrics, logs and Logs Insights enforce it. When following logs, it bounds the initial backlog, and following then continues beyond it.--filterstringA pattern to filter the logs.
Only logs matching the pattern will be printed. For more information on filter patterns, see the AWS documentation.
--followbooleanIf
true, keeps printing new log lines as they arrive until the command is stopped.In a terminal,
logsfollows by default;--follow=falseprints once and exits. Piped, redirected, in CI or for an agent,logsprints once unless--followis set. Following without a terminal prints plain lines, one at a time, and ends on Ctrl+C,SIGTERM, or when the reading end of the output closes.-h, --helpstringIf provided, the command will not execute and will instead print help information.
--limitnumberMaximum number of items to return.
--log-level"info" | "debug" | "error"Log Level
The level of logs to print to the console.
info: Basic information about the operation.error: Only errors.debug: Detailed information for debugging.
-p, --profilestringThe AWS profile to use for the command.
You can manage profiles using the
aws-profile:*commands and set a default profile withdefaults set.For commands that use a connected AWS account,
--profile(orAWS_PROFILE) selects the connected account the profile belongs to, unless--aws-accountis set. The command fails if that account is not connected.--projectstringThe name of the Stacktape project for this operation.
Commands that target a stack take it from
projectNamein the project's config when the flag is absent.--querystringCloudWatch Logs Insights query string.
Example: "fields @timestamp, @message | filter @message like /ERROR/ | limit 50"
--quietbooleanHide progress, banners, success messages and hints.
Command output, warnings and errors are still printed.
--rawbooleanIf
true, prints logs in raw JSON format instead of pretty-printing them.--sincenumber | stringThe query start time: a relative duration such as
30m, an ISO timestamp or a supported numeric date value.Relative durations count back from
--until(now by default).
No option matches.
Related commands
stacktape metrics— fetch CloudWatch metrics of a deployed function, container, database or HTTP API.stacktape alarm list— view CloudWatch alarm states for resources in your stack.stacktape container exec— run a command inside a deployed container for live debugging.stacktape query sql— run read-only SQL queries against a deployed database from the command line.