Skip to content

Commit

Permalink
docs(usage): Update generate-event command structure (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvsood authored and jfuss committed Aug 30, 2018
1 parent d729b5f commit c123579
Showing 1 changed file with 47 additions and 30 deletions.
77 changes: 47 additions & 30 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ an event too.
Run automated tests for your Lambda functions locally
-----------------------------------------------------
You can use the ``sam local invoke`` command to manually test your code
You can use the ``sam local invoke`` command to manually test your code
by running Lambda function locally. With SAM CLI, you can easily
author automated integration tests by
first running tests against local Lambda functions before deploying to the
Expand Down Expand Up @@ -103,10 +103,10 @@ configurations):
import boto3
import botocore
# Set "running_locally" flag if you are running the integration test locally
running_locally = True
if running_locally:
# Create Lambda SDK client to connect to appropriate Lambda endpoint
Expand All @@ -123,13 +123,13 @@ configurations):
)
else:
lambda_client = boto3.client('lambda')
# Invoke your Lambda function as you normally usually do. The function will run
# Invoke your Lambda function as you normally usually do. The function will run
# locally if it is configured to do so
response = lambda_client.invoke(FunctionName="HelloWorldFunction")
# Verify the response
# Verify the response
assert response == "Hello World"
This code can run without modifications against a Lambda function which
Expand All @@ -156,31 +156,49 @@ wish to connect to.
$ sam local start-api --docker-network b91847306671 -d 5858
Generate sample event source payloads
-------------------------------------
Generate sample event payloads
------------------------------

To make local development and testing of Lambda functions easier, you
can generate mock/sample event payloads for the following services:

- S3
- Kinesis Streams
- DynamoDB
- Cloudwatch Scheduled Event
- API Gateway
- SNS
can generate and customize event payloads for the following services:

- Amazon Alexa
- Amazon API Gateway
- AWS Batch
- AWS CloudFormation
- Amazon CloudFront
- AWS CodeCommit
- AWS CodePipeline
- Amazon Cognito
- AWS Config
- Amazon DynamoDB
- Amazon Kinesis
- Amazon Lex
- Amazon Rekognition
- Amazon S3
- Amazon SES
- Amazon SNS
- Amazon SQS
- AWS Step Functions

**Syntax**

.. code:: bash
$ sam local generate-event <service>
$ sam local generate-event <service> <event>
Also, you can invoke an individual lambda function locally from a sample
event payload - Here’s an example using S3:
You can generate multiple types of events from each service. For example,
to generate the event from S3 when a new object is created, use:

.. code:: bash
$ sam local generate-event s3 --bucket <bucket> --key <key> | sam local invoke <function logical id>
$ sam local generate-event s3 put
To generate the event from S3 when an object is deleted, you can use:

.. code:: bash
$ sam local generate-event s3 delete
For more options, see ``sam local generate-event --help``.

Expand Down Expand Up @@ -415,16 +433,16 @@ just the ones you deploy using SAM.

Fetch, tail, and filter Lambda function logs
--------------------------------------------
To simplify troubleshooting, SAM CLI has a command called ``sam logs``.
To simplify troubleshooting, SAM CLI has a command called ``sam logs``.
``sam logs`` lets you fetch logs generated by your Lambda
function from the command line. In addition to printing the logs on the
terminal, this command has several nifty features to help you quickly
find the bug.
find the bug.

Note: This command works for all AWS Lambda functions; not
just the ones you deploy using SAM.

**Basic Usage: Using CloudFormation Stack**
**Basic Usage: Using CloudFormation Stack**

When your function is a part
of a CloudFormation stack, you can fetch logs using the function's
Expand All @@ -434,15 +452,15 @@ LogicalID:
sam logs -n HelloWorldFunction --stack-name mystack
**Basic Usage: Using Lambda Function name**
**Basic Usage: Using Lambda Function name**

Or, you can fetch logs using the function's name

.. code:: bash
sam logs -n mystack-HelloWorldFunction-1FJ8PD
**Tail Logs**
**Tail Logs**

Add ``--tail`` option to wait for new logs and see them as
they arrive. This is very handy during deployment or when
Expand All @@ -452,14 +470,14 @@ troubleshooting a production issue.
sam logs -n HelloWorldFunction --stack-name mystack --tail
**View logs for specific time range**
**View logs for specific time range**
You can view logs for specific time range using the ``-s`` and ``-e`` options

.. code:: bash
sam logs -n HelloWorldFunction --stack-name mystack -s '10min ago' -e '2min ago'
**Filter Logs**
**Filter Logs**

Use the ``--filter`` option to quickly find logs that
match terms, phrases or values in your log events
Expand All @@ -472,7 +490,7 @@ In the output, SAM CLI will underline all occurrences of the word
“error” so you can easily locate the filter keyword within the log
output.

**Error Highlighting**
**Error Highlighting**

When your Lambda function crashes or times out,
SAM CLI will highlight the timeout message in red. This will help you
Expand All @@ -483,7 +501,7 @@ stream of log output.
:alt: SAM CLI Logs Error Highlighting


**JSON pretty printing**
**JSON pretty printing**

If your log messages print JSON strings, SAM
CLI will automatically pretty print the JSON to help you visually parse
Expand Down Expand Up @@ -550,4 +568,3 @@ Learn More
- `Getting started with SAM and the SAM CLI <getting_started.rst>`__
- `Packaging and deploying your application <deploying_serverless_applications.rst>`__
- `Advanced <advanced_usage.rst>`__

0 comments on commit c123579

Please sign in to comment.