sam logs
Fetches logs that are generated by your Lambda function.
When your functions are a part of an AWS CloudFormation stack, you can fetch logs by using the function's logical ID when you specify the stack name.
Usage:
sam logs [OPTIONS]
Examples:
sam logs -n HelloWorldFunction --stack-name mystack # You can view logs for a specific time range using the -s (--start-time) and -e (--end-time) options sam logs -n HelloWorldFunction --stack-name mystack -s '10min ago' -e '2min ago' # You can also add the --tail option to wait for new logs and see them as they arrive. sam logs -n HelloWorldFunction --stack-name mystack --tail # Use the --filter option to quickly find logs that match terms, phrases or values in your log events. sam logs -n HelloWorldFunction --stack-name mystack --filter "error" # View the logs for a resource in a child stack. sam logs --stack-name mystack -n childstack/HelloWorldFunction # Tail logs for all supported resources in your application. sam logs --stack-name
sam-app
--tail # Fetch logs for a specific Lambda function and API Gateway API in your application. sam logs --stack-namesam-app
--nameHelloWorldFunction
--nameHelloWorldRestApi
# Fetch logs for all supported resources in your application, and additionally from the specified log groups. sam logs --cw-log-group/aws/lambda/myfunction-123
--cw-log-group/aws/lambda/myfunction-456
Options:
Option | Description |
---|---|
-n, --name TEXT |
The name of the resource for which to fetch logs. If this resource is part of an AWS CloudFormation stack,
this can be the logical ID of the function resource in the AWS CloudFormation/AWS SAM template. Multiple names
can be provided by repeating the parameter again. If resource is in a nested stack, the name can be prepended
by the name of the nested stack name to pull logs from that resource (NestedStackLogicalId/ResourceLogicalId).
If the resource name isn't given, the given stack will be scanned and log information will be pulled for all supported resources.
If you don't specify this option, AWS SAM fetches logs for all resources in the stack that you specify. The following resource types are supported:
|
--stack-name TEXT |
The name of the AWS CloudFormation stack that the resource is a part of. |
--filter TEXT |
Lets you specify an expression to quickly find logs that match terms, phrases, or values in your log events. This can be a simple keyword (for example, "error") or a pattern that's supported by Amazon CloudWatch Logs. For the syntax, see the Amazon CloudWatch Logs documentation. |
-s, --start-time TEXT |
Fetches logs starting at this time. The time can be relative values like '5mins ago', 'yesterday', or a formatted timestamp like '2018-01-01 10:10:10'. It defaults to '10mins ago'. |
-e, --end-time TEXT |
Fetches logs up to this time. The time can be relative values like '5mins ago', 'tomorrow', or a formatted timestamp like '2018-01-01 10:10:10'. |
--profile TEXT |
The specific profile from your credential file that gets AWS credentials. |
--region TEXT |
The AWS Region to deploy to. For example, us-east-1. |
-t, --tail |
Tails the log output. This ignores the end time argument and continues to fetch logs as they become available. |
--include-traces |
Includes X-Ray traces in the log output. |
--output TEXT |
Specifies the output format for logs. To print formatted logs, specify |
--cw-log-group LIST |
Includes logs from the CloudWatch Logs log groups that you specify. If you specify
this option along with name , AWS SAM includes logs from the
specified log groups in addition to logs from the named resources. |
--config-file PATH |
The path and file name of the configuration file containing default parameter values to use. The default value is "samconfig.toml" in the root of the project directory. For more information about configuration files, see AWS SAM CLI configuration file. |
--config-env TEXT |
The environment name specifying the default parameter values in the configuration file to use. The default value is "default". For more information about configuration files, see AWS SAM CLI configuration file. |
--debug |
Turns on debug logging to print debug message generated by the AWS SAM CLI and display timestamps. |
--help |
Shows this message and exits. |