Select your cookie preferences

We use cookies and similar tools to enhance your experience, provide our services, deliver relevant advertising, and make improvements. Approved third parties also use these tools to help us deliver advertising and provide certain site features.

Serverless Snippets Collection

Filters (84 snippets)
Snippet Type

Services

Language

Snippet Tags

Use serverless snippets to quickly find community shared code. Filter by type and copy the code directly into your application.

aws lambda list-functions --function-version ALL --output text --query "Functions[?Runtime=='python2.7'].FunctionArn"
                    
                  
Find all Lambda functions with a specific runtime

Using AWS CLI to find all instances of a specific runtime

aws cloudformation describe-stacks --stack-name  --query "Stacks[*].Outputs[*].{OutputKey: OutputKey, OutputValue: OutputValue, Description: Description}"
                    
                  
List all or specific CloudFormation Stack Outputs

An AWS CLI command to list all or a specific CloudFormation output(s) of a particular stack

aws cloudformation list-stacks
or
aws cloudformation list-stacks  --query "StackSummaries[*].{StackId: StackId, StackName: StackName}"
                    
                  
List CloudFormation Stacks

An AWS CLI command to list all CloudFormation Stacks and a query to show how to only show StackId and StackName

aws logs tail {LogGroupName} --follow --format json
                    
                  
Tails the logs for a CloudWatch Logs group

An AWS CLI command to tail a CloudWatch log group

filter status=200
| stats avg(integrationLatency), max(integrationLatency), 
min(integrationLatency) by bin(1m)
                    
                  
Integration latency report

Create API Gateway integration latency report for your API Gateway access log group.

fields @timestamp, status, ip, path, httpMethod
| sort @timestamp desc
| limit 10
                    
                  
Last 10 requests

Get last 10 requests in your API Gateway access log group.

fields @timestamp, status, ip, path, httpMethod
| filter status>=400 and status<=499
| sort @timestamp desc
| limit 10
                    
                  
Last 10 4xx errors

Returns the last 10 4xx errors in your API Gateway access log group.

fields @timestamp, status, ip, path, httpMethod
| filter status>=500 and status<=599
| sort @timestamp desc
| limit 10
                    
                  
Last 10 5xx errors

Get the last 10 5xx errors in your API Gateway access log group.

fields @timestamp, status, ip, path, httpMethod, responseLatency
| sort responseLatency desc
| limit 10
                    
                  
Longest running requests

Identify 10 longest running API Gateway requests in your API Gateway access log group.

stats count(*) as requestCount by path
| sort requestCount desc
| limit 10
                    
                  
Most popular API paths

Get list of most popular API paths in your API Gateway access log group.

stats count(*) as errorCount by status, path, httpMethod
| filter status>=400 and status<=499
| limit 10
                    
                  
Paths with most 4xx errors

Get list of paths that returned most of 4xx response status codes in your API Gateway access log group.

stats count(*) as errorCount by status, path, httpMethod
| filter status>=500 and status<=599
| limit 10
                    
                  
Paths with most 5xx errors

Get list of paths that returned most of 5xx response status codes in your API Gateway access log group.

stats count(*) as accessDeniedCount by status, path, httpMethod
| filter status=403 or status=401
| limit 10
                    
                  
Paths with most access denied responses

Get list of paths that returned most of 401 and 403 response status codes in your API Gateway access log group.

stats count(*) as requestCount by apiKey
| sort requestCount desc
| limit 10
                    
                  
Most used API keys

Get list of most active API keys in your API Gateway access log group

stats count(*) as requestCount by ip
| sort requestCount desc
| limit 10
                    
                  
Most active IPs

Get list of most active IPs in your API Gateway access log group

filter (eventName="StartInstances" or eventName="StopInstances") and awsRegion="us-east-2"
                    
                  
EC2 hosts that started or stopped in an AWS Region with AWS CloudTrail

Find the Amazon EC2 hosts that were started or stopped in a given AWS Region.

filter eventName="CreateUser"
    | fields awsRegion, requestParameters.userName, responseElements.user.arn
                    
                  
Find information for newly created IAM users using CloudTrail

Find the AWS Regions, user names, and ARNs of newly created IAM users.

stats count(*) by eventSource, eventName, awsRegion
                    
                  
Find the number of log entries with AWS CloudTrail

Find the number of log entries for each service, event type, and AWS Region.

filter @type = "REPORT" |
    stats avg(@duration), max(@duration), min(@duration) by bin(5m)
                    
                  
Lambda latency report

Create a latency report for your Lambda functions

fields @timestamp
| filter `detail-type` like /sample-value/ # replace sample-value with actual value to be searched
| sort @timestamp desc
                    
                  
Events that match a pattern for detail-type value

Get the EventBridge events that match a pattern for detail-type value

fields @timestamp, @message
| stats count(*) as numberOfEvents by `detail-type`
| sort numberOfEvents desc
                    
                  
Number of events grouped by detail-type

Get the number of EventBridge events grouped by detail-type.

fields @timestamp
| filter detail.field-value >= N1 and detail.field-value <= N2 # replace field-value, N1, N2 with actual values. N1 and N2 are the numeric range.
| sort @timestamp desc
                    
                  
Events with detail field value falling in a given numeric range

Get the EventBridge events for a given detail field that has values within a given numeric range

fields @timestamp
| filter detail.field-name = "field-value"   # replace field-name and field-value with actual values
| sort @timestamp desc
                    
                  
Filter Events by value of a detail field

Get the EventBridge events by filtering on a detail field

fields @timestamp
| filter detail.field-name != "field-value"   # replace field-name and field-value with actual values
| sort @timestamp desc
                    
                  
Filter Events by detail field value not equal to a given value

Get the EventBridge events by filtering on a detail field value that is not equal to a given value

fields @timestamp
| filter `detail-type` = "detail-type-value"    # replace detail-type-value with the actual value
| sort @timestamp desc
                    
                  
Events that match the value of detail-type

Get the EventBridge events that match the value of detail-type

fields @timestamp
| filter detail.array-field.n1 = "sample-value"  # replace array-field with the field name having values as array, n1 with array position and sample-value with value to filter. 
| sort @timestamp desc
                    
                  
Events that match a value in detail-field that has an array of values

Get the EventBridge events that match a value in detail-field that has an array of values

fields @timestamp
| filter ispresent(detail.field-name)    # replace field-name with the actual value
| sort @timestamp desc
                    
                  
Get Events if a given detail field is present

Get the EventBridge events if detail field is present

fields @timestamp
| filter detail.field-value IN ["value1", "value2", "value3"]  # replace field-value and value1, value2, value3 with actual values.
| sort @timestamp desc
                    
                  
Events with detail field that matches any value in a list

Get the EventBridge events with a specific detail field that matches any value in a list.

fields @timestamp
| filter detail.field-value NOT IN ["value1", "value2", "value3"]  # replace field-value and value1, value2, value3 with actual values.
| sort @timestamp desc
                    
                  
Events with detail field that does not match any value in a list

Get the EventBridge events with a specific detail field that does not match any value in a list.

fields @timestamp
| filter detail.field1.field2 = "sample-value"  # replace field1, field2, sample-value with appropriate values.
| sort @timestamp desc
                    
                  
Events that match a value in detail-nested-field

Get the EventBridge events that match a value in detail-nested-field

fields @timestamp
| filter isempty(detail.field-value)   # replace field-value with the actual value
| sort @timestamp desc
                    
                  
Events which have no value for a given detail field

Get the EventBridge events for a given detail field that has no value

filter @message like /Exception/ 
    | stats count(*) as exceptionCount by bin(1h)
    | sort exceptionCount desc
                    
                  
Number of exceptions per hour

Find and list the number of exceptions per hour