From c123579e974eef3678d1e08e94eaaf7f95bad8ed Mon Sep 17 00:00:00 2001 From: Dhruv Sood <37157475+SoodDhruv@users.noreply.github.com> Date: Thu, 30 Aug 2018 06:35:26 -0700 Subject: [PATCH] docs(usage): Update generate-event command structure (#638) --- docs/usage.rst | 77 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 48c30a2393..f980052496 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -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 @@ -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 @@ -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 @@ -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 + $ sam local generate-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 --key | sam local invoke + $ 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``. @@ -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 @@ -434,7 +452,7 @@ 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 @@ -442,7 +460,7 @@ Or, you can fetch logs using the function's name 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 @@ -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 @@ -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 @@ -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 @@ -550,4 +568,3 @@ Learn More - `Getting started with SAM and the SAM CLI `__ - `Packaging and deploying your application `__ - `Advanced `__ -