Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
18ba6ed
chore(deps): bump actions/setup-go from 3 to 4 (#5418)
dependabot[bot] Jun 27, 2023
00b262d
chore(deps-dev): bump filelock from 3.12.0 to 3.12.2 in /requirements…
dependabot[bot] Jun 27, 2023
663c88d
feat: updating app templates repo hash with (bb905c379830c3d8edbc196b…
github-actions[bot] Jun 27, 2023
9a71591
fix: add a table for package help text. (#5298)
sriram-mv Jun 28, 2023
743d389
fix: Handle BROKEN_PIPE_ERROR (#5386)
lucashuy Jun 28, 2023
3952ff6
fix: remove circular dependency by moving parse_s3 method to its own …
mndeveci Jun 29, 2023
46f7e1f
chore(deps): bump sympy from 1.10.1 to 1.12 in /requirements (#5338)
dependabot[bot] Jun 29, 2023
30336bc
chore(deps): bump websocket-client from 1.5.1 to 1.6.1 in /requiremen…
dependabot[bot] Jun 29, 2023
4336c77
chore(deps): bump ruamel-yaml from 0.17.21 to 0.17.32 in /requirement…
dependabot[bot] Jun 29, 2023
359e43b
Updated package formatter to import package options instead of deploy…
hnnasit Jun 30, 2023
5e8df69
chore(deps): bump importlib-metadata in /requirements (#5437)
dependabot[bot] Jul 3, 2023
9877db2
feat: `sam logs` help text (#5397)
sriram-mv Jul 3, 2023
c53db02
feat: enable terraform support for local start-api command (#5389)
moelasmar Jul 3, 2023
6c9939e
Updated warning message about missing function in template (#5347)
lucashuy Jul 3, 2023
ed93c2a
chore(deps-dev): bump types-pywin32 in /requirements (#5436)
dependabot[bot] Jul 3, 2023
a105438
Merge changes from upstream
mildaniel Jul 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Flask<2.3
#Need to add latest lambda changes which will return invoke mode details
boto3>=1.26.109,==1.*
jmespath~=1.0.1
ruamel_yaml~=0.17.21
ruamel_yaml~=0.17.32
PyYAML>=5.4.1,==5.*
cookiecutter~=2.1.1
aws-sam-translator==1.70.0
Expand Down
4 changes: 2 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pytest-cov==4.1.0
# here we fix its version and upgrade it manually in the future
mypy==1.3.0
boto3-stubs[apigateway,cloudformation,ecr,iam,lambda,s3,schemas,secretsmanager,signer,stepfunctions,sts,xray]==1.26.131
types-pywin32==306.0.0.0
types-pywin32==306.0.0.2
types-PyYAML==6.0.12
types-chevron==0.14.2.4
types-psutil==5.9.5.12
Expand All @@ -33,7 +33,7 @@ pytest-rerunfailures==11.1.2
# NOTE (hawflau): DO NOT upgrade pytest-metadata and pytest-json-report unless pytest-json-report addresses https://github.com/numirias/pytest-json-report/issues/89
pytest-metadata==2.0.4
pytest-json-report==1.5.0
filelock==3.12.0
filelock==3.12.2

# formatter
black==22.6.0
Expand Down
51 changes: 45 additions & 6 deletions requirements/reproducible-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,49 @@ rich==13.3.3 \
--hash=sha256:540c7d6d26a1178e8e8b37e9ba44573a3cd1464ff6348b99ee7061b95d1c6333 \
--hash=sha256:dc84400a9d842b3a9c5ff74addd8eb798d155f36c1c91303888e0a66850d2a15
# via aws-sam-cli (setup.py)
ruamel-yaml==0.17.21 \
--hash=sha256:742b35d3d665023981bd6d16b3d24248ce5df75fdb4e2924e93a05c1f8b61ca7 \
--hash=sha256:8b7ce697a2f212752a35c1ac414471dc16c424c9573be4926b56ff3f5d23b7af
ruamel-yaml==0.17.32 \
--hash=sha256:23cd2ed620231677564646b0c6a89d138b6822a0d78656df7abda5879ec4f447 \
--hash=sha256:ec939063761914e14542972a5cba6d33c23b0859ab6342f61cf070cfc600efc2
# via aws-sam-cli (setup.py)
ruamel-yaml-clib==0.2.7 \
--hash=sha256:045e0626baf1c52e5527bd5db361bc83180faaba2ff586e763d3d5982a876a9e \
--hash=sha256:15910ef4f3e537eea7fe45f8a5d19997479940d9196f357152a09031c5be59f3 \
--hash=sha256:184faeaec61dbaa3cace407cffc5819f7b977e75360e8d5ca19461cd851a5fc5 \
--hash=sha256:1a6391a7cabb7641c32517539ca42cf84b87b667bad38b78d4d42dd23e957c81 \
--hash=sha256:1f08fd5a2bea9c4180db71678e850b995d2a5f4537be0e94557668cf0f5f9497 \
--hash=sha256:2aa261c29a5545adfef9296b7e33941f46aa5bbd21164228e833412af4c9c75f \
--hash=sha256:3110a99e0f94a4a3470ff67fc20d3f96c25b13d24c6980ff841e82bafe827cac \
--hash=sha256:3243f48ecd450eddadc2d11b5feb08aca941b5cd98c9b1db14b2fd128be8c697 \
--hash=sha256:370445fd795706fd291ab00c9df38a0caed0f17a6fb46b0f607668ecb16ce763 \
--hash=sha256:40d030e2329ce5286d6b231b8726959ebbe0404c92f0a578c0e2482182e38282 \
--hash=sha256:41d0f1fa4c6830176eef5b276af04c89320ea616655d01327d5ce65e50575c94 \
--hash=sha256:4a4d8d417868d68b979076a9be6a38c676eca060785abaa6709c7b31593c35d1 \
--hash=sha256:4b3a93bb9bc662fc1f99c5c3ea8e623d8b23ad22f861eb6fce9377ac07ad6072 \
--hash=sha256:5bc0667c1eb8f83a3752b71b9c4ba55ef7c7058ae57022dd9b29065186a113d9 \
--hash=sha256:763d65baa3b952479c4e972669f679fe490eee058d5aa85da483ebae2009d231 \
--hash=sha256:7bdb4c06b063f6fd55e472e201317a3bb6cdeeee5d5a38512ea5c01e1acbdd93 \
--hash=sha256:8831a2cedcd0f0927f788c5bdf6567d9dc9cc235646a434986a852af1cb54b4b \
--hash=sha256:91a789b4aa0097b78c93e3dc4b40040ba55bef518f84a40d4442f713b4094acb \
--hash=sha256:92460ce908546ab69770b2e576e4f99fbb4ce6ab4b245345a3869a0a0410488f \
--hash=sha256:99e77daab5d13a48a4054803d052ff40780278240a902b880dd37a51ba01a307 \
--hash=sha256:9c7617df90c1365638916b98cdd9be833d31d337dbcd722485597b43c4a215bf \
--hash=sha256:a234a20ae07e8469da311e182e70ef6b199d0fbeb6c6cc2901204dd87fb867e8 \
--hash=sha256:a7b301ff08055d73223058b5c46c55638917f04d21577c95e00e0c4d79201a6b \
--hash=sha256:be2a7ad8fd8f7442b24323d24ba0b56c51219513cfa45b9ada3b87b76c374d4b \
--hash=sha256:bf9a6bc4a0221538b1a7de3ed7bca4c93c02346853f44e1cd764be0023cd3640 \
--hash=sha256:c3ca1fbba4ae962521e5eb66d72998b51f0f4d0f608d3c0347a48e1af262efa7 \
--hash=sha256:d000f258cf42fec2b1bbf2863c61d7b8918d31ffee905da62dede869254d3b8a \
--hash=sha256:d5859983f26d8cd7bb5c287ef452e8aacc86501487634573d260968f753e1d71 \
--hash=sha256:d5e51e2901ec2366b79f16c2299a03e74ba4531ddcfacc1416639c557aef0ad8 \
--hash=sha256:da538167284de58a52109a9b89b8f6a53ff8437dd6dc26d33b57bf6699153122 \
--hash=sha256:debc87a9516b237d0466a711b18b6ebeb17ba9f391eb7f91c649c5c4ec5006c7 \
--hash=sha256:df5828871e6648db72d1c19b4bd24819b80a755c4541d3409f0f7acd0f335c80 \
--hash=sha256:ecdf1a604009bd35c674b9225a8fa609e0282d9b896c03dd441a91e5f53b534e \
--hash=sha256:efa08d63ef03d079dcae1dfe334f6c8847ba8b645d08df286358b1f5293d24ab \
--hash=sha256:f01da5790e95815eb5a8a138508c01c758e5f5bc0ce4286c4f7028b8dd7ac3d0 \
--hash=sha256:f34019dced51047d6f70cb9383b2ae2853b7fc4dce65129a5acd49f4f9256646 \
--hash=sha256:f6d3d39611ac2e4f62c3128a9eed45f19a6608670c5a2f4f07f24e8de3441d38
# via ruamel-yaml
s3transfer==0.6.0 \
--hash=sha256:06176b74f3a15f61f1b4f25a1fc29a4429040b7647133a463da8fa5bd28d5ecd \
--hash=sha256:2ed07d3866f523cc561bf4a00fc5535827981b117dd7876f036b0c1aca42c947
Expand Down Expand Up @@ -684,9 +723,9 @@ watchdog==2.1.2 \
--hash=sha256:d34ce2261f118ecd57eedeef95fc2a495fc4a40b3ed7b3bf0bd7a8ccc1ab4f8f \
--hash=sha256:edcd9ef3fd460bb8a98eb1fcf99941e9fd9f275f45f1a82cb1359ec92975d647
# via aws-sam-cli (setup.py)
websocket-client==1.5.1 \
--hash=sha256:3f09e6d8230892547132177f575a4e3e73cfdf06526e20cc02aa1c3b47184d40 \
--hash=sha256:cdf5877568b7e83aa7cf2244ab56a3213de587bbe0ce9d8b9600fc77b455d89e
websocket-client==1.6.1 \
--hash=sha256:c951af98631d24f8df89ab1019fc365f2227c0892f12fd150e935607c79dd0dd \
--hash=sha256:f1f9f2ad5291f0225a49efad77abf9e700b6fef553900623060dad6e26503b9d
# via docker
werkzeug==2.2.3 \
--hash=sha256:2e1ccc9417d4da358b9de6f174e3ac094391ea1d4fbef2d667865d819dfd0afe \
Expand Down
24 changes: 12 additions & 12 deletions requirements/reproducible-mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ idna==3.4 \
--hash=sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4 \
--hash=sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2
# via requests
importlib-metadata==6.1.0 \
--hash=sha256:43ce9281e097583d758c2c708c4376371261a02c34682491a8e98352365aad20 \
--hash=sha256:ff80f3b5394912eb1b108fcfd444dc78b7f1f3e16b16188054bd01cb9cb86f09
importlib-metadata==6.7.0 \
--hash=sha256:1aaf550d4f73e5d6783e7acb77aec43d49da8017410afae93822cc9cca98c4d4 \
--hash=sha256:cb52082e659e97afc5dac71e79de97d8681de3aa07ff18578330904a9d18e5b5
# via
# attrs
# click
Expand Down Expand Up @@ -645,9 +645,9 @@ rich==13.3.3 \
--hash=sha256:540c7d6d26a1178e8e8b37e9ba44573a3cd1464ff6348b99ee7061b95d1c6333 \
--hash=sha256:dc84400a9d842b3a9c5ff74addd8eb798d155f36c1c91303888e0a66850d2a15
# via aws-sam-cli (setup.py)
ruamel-yaml==0.17.21 \
--hash=sha256:742b35d3d665023981bd6d16b3d24248ce5df75fdb4e2924e93a05c1f8b61ca7 \
--hash=sha256:8b7ce697a2f212752a35c1ac414471dc16c424c9573be4926b56ff3f5d23b7af
ruamel-yaml==0.17.32 \
--hash=sha256:23cd2ed620231677564646b0c6a89d138b6822a0d78656df7abda5879ec4f447 \
--hash=sha256:ec939063761914e14542972a5cba6d33c23b0859ab6342f61cf070cfc600efc2
# via aws-sam-cli (setup.py)
ruamel-yaml-clib==0.2.7 \
--hash=sha256:045e0626baf1c52e5527bd5db361bc83180faaba2ff586e763d3d5982a876a9e \
Expand Down Expand Up @@ -706,9 +706,9 @@ six==1.16.0 \
# junit-xml
# python-dateutil
# serverlessrepo
sympy==1.10.1 \
--hash=sha256:5939eeffdf9e152172601463626c022a2c27e75cf6278de8d401d50c9d58787b \
--hash=sha256:df75d738930f6fe9ebe7034e59d56698f29e85f443f743e51e47df0caccc2130
sympy==1.12 \
--hash=sha256:c3588cd4295d0c0f603d0f2ae780587e64e2efeedb3521e46b9bb1d08d184fa5 \
--hash=sha256:ebf595c8dac3e0fdc4152c51878b498396ec7f30e7a914d6071e674d49420fb8
# via cfn-lint
text-unidecode==1.3 \
--hash=sha256:1311f10e8b895935241623731c2ba64f4c455287888b18189350b67134a822e8 \
Expand Down Expand Up @@ -762,9 +762,9 @@ watchdog==2.1.2 \
--hash=sha256:d34ce2261f118ecd57eedeef95fc2a495fc4a40b3ed7b3bf0bd7a8ccc1ab4f8f \
--hash=sha256:edcd9ef3fd460bb8a98eb1fcf99941e9fd9f275f45f1a82cb1359ec92975d647
# via aws-sam-cli (setup.py)
websocket-client==1.5.1 \
--hash=sha256:3f09e6d8230892547132177f575a4e3e73cfdf06526e20cc02aa1c3b47184d40 \
--hash=sha256:cdf5877568b7e83aa7cf2244ab56a3213de587bbe0ce9d8b9600fc77b455d89e
websocket-client==1.6.1 \
--hash=sha256:c951af98631d24f8df89ab1019fc365f2227c0892f12fd150e935607c79dd0dd \
--hash=sha256:f1f9f2ad5291f0225a49efad77abf9e700b6fef553900623060dad6e26503b9d
# via docker
werkzeug==2.2.3 \
--hash=sha256:2e1ccc9417d4da358b9de6f174e3ac094391ea1d4fbef2d667865d819dfd0afe \
Expand Down
6 changes: 6 additions & 0 deletions samcli/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import List, Optional, cast

import click
from rich.console import Console

from samcli.cli.formatters import RootCommandHelpTextFormatter
from samcli.commands.exceptions import AWSServiceClientError
Expand Down Expand Up @@ -44,6 +45,11 @@ def __init__(self):
self._session_id = str(uuid.uuid4())
self._experimental = False
self._exception = None
self._console = Console()

@property
def console(self):
return self._console

@property
def exception(self):
Expand Down
4 changes: 2 additions & 2 deletions samcli/cli/root/command_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"validate": "Validate an AWS SAM template.",
"build": "Build your AWS serverless function code.",
"local": "Run your AWS serverless function locally.",
"remote": "Invoke or send an event to cloud resources in your CFN stack",
"remote": "Invoke or send an event to cloud resources in your AWS Cloudformation stack.",
"package": "Package an AWS SAM application.",
"deploy": "Deploy an AWS SAM application.",
"delete": "Delete an AWS SAM application and the artifacts created by sam deploy.",
"logs": "Fetch AWS Cloudwatch logs for a function.",
"logs": "Fetch AWS Cloudwatch logs for AWS Lambda Functions or Cloudwatch Log groups.",
"publish": "Publish a packaged AWS SAM template to AWS Serverless Application Repository for easy sharing.",
"traces": "Fetch AWS X-Ray traces.",
"sync": "Sync an AWS SAM project to AWS.",
Expand Down
8 changes: 4 additions & 4 deletions samcli/commands/_utils/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def no_progressbar_click_option():
default=False,
required=False,
is_flag=True,
help="Does not showcase a progress bar when uploading artifacts to s3 and pushing docker images to ECR",
help="Does not showcase a progress bar when uploading artifacts to S3 and pushing docker images to ECR",
)


Expand Down Expand Up @@ -679,9 +679,9 @@ def resolve_s3_click_option(guided):
required=False,
is_flag=True,
callback=callback,
help="Automatically resolve s3 bucket for non-guided deployments. "
"Enabling this option will also create a managed default s3 bucket for you. "
"If you do not provide a --s3-bucket value, the managed bucket will be used. "
help="Automatically resolve AWS S3 bucket for non-guided deployments. "
"Enabling this option will also create a managed default AWS S3 bucket for you. "
"If one does not provide a --s3-bucket value, the managed bucket will be used. "
"Do not use --guided with this option.",
)

Expand Down
52 changes: 25 additions & 27 deletions samcli/commands/logs/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from samcli.cli.main import common_options as cli_framework_options
from samcli.commands._utils.command_exception_handler import command_exception_handler
from samcli.commands._utils.options import common_observability_options, generate_next_command_recommendation
from samcli.commands.logs.core.command import LogsCommand
from samcli.commands.logs.validation_and_exception_handlers import (
SAM_LOGS_ADDITIONAL_EXCEPTION_HANDLERS,
stack_name_cw_log_group_validation,
Expand All @@ -20,37 +21,34 @@

LOG = logging.getLogger(__name__)

SHORT_HELP = (
"Fetch logs for your AWS SAM Application or AWS Cloudformation stack - Lambda Functions/CloudWatch Log groups"
)

HELP_TEXT = """
Use this command to fetch logs generated by your Lambda function.\n
\b
When your functions are a part of a CloudFormation stack, you can fetch logs using the function's
LogicalID when you specify the stack name.
$ sam logs -n HelloWorldFunction --stack-name mystack \n
\b
Or, you can fetch logs using the function's name.
$ sam logs -n mystack-HelloWorldFunction-1FJ8PD36GML2Q \n
\b
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' \n
\b
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 \n
\b
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' \n
\b
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
\b
You can now fetch logs from supported resources, by only providing --stack-name parameter
$ sam logs --stack-name mystack \n
\b
You can also fetch logs from a resource which is defined in a nested stack.
$ sam logs --stack-name mystack -n MyNestedStack/HelloWorldFunction
The sam logs commands fetches logs of Lambda Functions/CloudWatch log groups
with additional filtering by options.
"""

DESCRIPTION = """
Fetch logs generated by Lambda functions or other Cloudwatch log groups with additional filtering.
"""

@click.command("logs", help=HELP_TEXT, short_help="Fetch logs for a function")

@click.command(
"logs",
short_help=SHORT_HELP,
context_settings={
"ignore_unknown_options": False,
"allow_interspersed_args": True,
"allow_extra_args": True,
"max_content_width": 120,
},
cls=LogsCommand,
help=HELP_TEXT,
description=DESCRIPTION,
requires_credentials=True,
)
@configuration_option(provider=TomlProvider(section="parameters"))
@click.option(
"--name",
Expand Down
Empty file.
119 changes: 119 additions & 0 deletions samcli/commands/logs/core/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from click import Context, style

from samcli.cli.core.command import CoreCommand
from samcli.cli.row_modifiers import RowDefinition, ShowcaseRowModifier
from samcli.commands.logs.core.formatters import LogsCommandHelpTextFormatter
from samcli.commands.logs.core.options import OPTIONS_INFO

COL_SIZE_MODIFIER = 38


class LogsCommand(CoreCommand):
class CustomFormatterContext(Context):
formatter_class = LogsCommandHelpTextFormatter

context_class = CustomFormatterContext

@staticmethod
def format_examples(ctx: Context, formatter: LogsCommandHelpTextFormatter):
with formatter.indented_section(name="Examples", extra_indents=1):
with formatter.indented_section(
name="Fetch logs with Lambda Function Logical ID and Cloudformation Stack Name"
):
formatter.write_rd(
[
RowDefinition(
text="\n",
),
RowDefinition(
name=style(f"$ {ctx.command_path} -n HelloWorldFunction --stack-name mystack"),
extra_row_modifiers=[ShowcaseRowModifier()],
),
]
)
with formatter.indented_section(name="View logs for specific time range"):
formatter.write_rd(
[
RowDefinition(
text="\n",
),
RowDefinition(
name=style(
f"$ {ctx.command_path} -n HelloWorldFunction --stack-name mystack -s "
f"'10min ago' -e '2min ago'"
),
extra_row_modifiers=[ShowcaseRowModifier()],
),
]
)
with formatter.indented_section(name="Tail new logs"):
formatter.write_rd(
[
RowDefinition(
text="\n",
),
RowDefinition(
name=style(f"$ {ctx.command_path} -n HelloWorldFunction --stack-name " f"mystack --tail"),
extra_row_modifiers=[ShowcaseRowModifier()],
),
]
)
with formatter.indented_section(name="Fetch from Cloudwatch log groups"):
formatter.write_rd(
[
RowDefinition(
text="\n",
),
RowDefinition(
name=style(
f"$ {ctx.command_path} --cw-log-group /aws/lambda/myfunction-123 "
f"--cw-log-group /aws/lambda/myfunction-456"
),
extra_row_modifiers=[ShowcaseRowModifier()],
),
]
)

with formatter.indented_section(name="Fetch logs from supported resources in Cloudformation stack"):
formatter.write_rd(
[
RowDefinition(
text="\n",
),
RowDefinition(
name=style(f"$ {ctx.command_path} ---stack-name mystack"),
extra_row_modifiers=[ShowcaseRowModifier()],
),
]
)

with formatter.indented_section(name="Fetch logs from resource defined in nested Cloudformation stack"):
formatter.write_rd(
[
RowDefinition(
text="\n",
),
RowDefinition(
name=style(
f"$ {ctx.command_path} ---stack-name mystack -n MyNestedStack/HelloWorldFunction"
),
extra_row_modifiers=[ShowcaseRowModifier()],
),
]
)

def format_options(self, ctx: Context, formatter: LogsCommandHelpTextFormatter) -> None: # type:ignore
# `ignore` is put in place here for mypy even though it is the correct behavior,
# as the `formatter_class` can be set in subclass of Command. If ignore is not set,
# mypy raises argument needs to be HelpFormatter as super class defines it.

self.format_description(formatter)
LogsCommand.format_examples(ctx, formatter)

CoreCommand._format_options(
ctx=ctx,
params=self.get_params(ctx),
formatter=formatter,
formatting_options=OPTIONS_INFO,
write_rd_overrides={"col_max": COL_SIZE_MODIFIER},
)
Loading