Use serverless snippets to quickly find community shared code. Filter by type and copy the code directly into your application.
{ "partitionkey": "item123", "timestamp": "2015-12-21T17:42:34Z", "binary": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk", "boolean": "true", "null": "null", "number": "1437136300" }
![]()
REST Direct integration with DynamoDB
#set( $pageKey = $input.params('pageKey')) { "TableName": "myTable", "IndexName":"OwnerIndex", "KeyConditionExpression": "#n_owner = :v_owner", "ExpressionAttributeValues": { ":v_owner": {"S": "$context.authorizer.claims.email"} }, "ExpressionAttributeNames": {"#n_owner": "owner"} }
![]()
Limits the returned data to the authorized user
#set( $pageKey = $input.params('pageKey')) { "TableName": "myTable", "IndexName":"OwnerIndex", "KeyConditionExpression": "#n_owner = :v_owner", "FilterExpression": "contains(#n_id, :v_searchString)", "ExpressionAttributeValues": { ":v_owner": {"S": "$context.authorizer.claims.email"}, ":v_searchString":{"S":"$input.params().path.searchString"} }, "ExpressionAttributeNames": {"#n_owner": "owner", "#n_id":"id"} }
![]()
Direct integration search on DynamoDB
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::<account-id>:role/<iam-role-arn>" }, "Action": "execute-api:Invoke", "Resource": "arn:aws:execute-api:us-east-1:<account-id>:<api-id>/*" }, { "Effect": "Deny", "Principal": { "AWS": "arn:aws:iam::<account-id>:role/<iam-role-arn>" }, "Action": "execute-api:Invoke", "Resource": "arn:aws:execute-api:us-east-1:<account-id>:<api-id>/*", "Condition": { "StringNotEquals": { "aws:SourceVpce": "<vpce-id>" } } }, { "Effect": "Deny", "Principal": { "AWS": "*" }, "Action": "execute-api:Invoke", "Resource": "arn:aws:execute-api:us-east-1:<account-id>:<api-id>/*", "Condition": { "StringNotEquals": { "aws:PrincipalArn": "arn:aws:iam::<account-id>:role/<iam-role-arn>" } } } ] }
![]()
Using this resource policy a private API Gateway can be restricted to be invoked by both an IAM role and a VPC endpoint.
aws lambda list-functions --function-version ALL --output text --query "Functions[?Runtime=='python2.7'].FunctionArn"
![]()
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}"
![]()
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}"
![]()
An AWS CLI command to list all CloudFormation Stacks and a query to show how to only show StackId and StackName
aws cloudformation list-stack-resources --stack-name (stack id) --query "StackResourceSummaries[?ResourceType=='AWS::Lambda::Function'].{LogicalResourceId: LogicalResourceId, PhysicalResourceId: PhysicalResourceId, LastUpdate: LastUpdatedTimestamp}"
![]()
An AWS CLI command to retrieve all AWS Lambda function resources in a named CloudFormation Stack
aws logs tail {LogGroupName} --follow --format json
An AWS CLI command to tail a CloudWatch log group
sudo yum update -y wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip unzip aws-sam-cli-linux-x86_64.zip -d sam-installation sudo ./sam-installation/install --update sam --version
![]()
Updates AWS SAM on an AWS Cloud9 instance
filter status=200 | stats avg(integrationLatency), max(integrationLatency), min(integrationLatency) by bin(1m)
![]()
Create API Gateway integration latency report for your API Gateway access log group.
fields @timestamp, status, ip, path, httpMethod | sort @timestamp desc | limit 10
![]()
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
![]()
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
![]()
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
![]()
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
![]()
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
![]()
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
![]()
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
![]()
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
![]()
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
![]()
Get list of most active IPs in your API Gateway access log group
filter (eventName="StartInstances" or eventName="StopInstances") and awsRegion="us-east-2"
![]()
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 the AWS Regions, user names, and ARNs of newly created IAM users.
stats count(*) by eventSource, eventName, awsRegion
![]()
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)
![]()
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
![]()
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
![]()
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
![]()
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
![]()
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
![]()
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
![]()
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
![]()
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 the EventBridge events if detail field is present
fields @timestamp | filter ispresent(`detail-type`) | stats count(*) as CountOfEventsPerHour by bin(1h) | sort @timestamp desc
![]()
Get the EventBridge events per hour
fields @timestamp | filter ispresent(`detail-type`) | stats count(*) as CountOfEventsPerMinute by bin(1m) | sort @timestamp desc
![]()
Get the EventBridge events per minute
fields @timestamp | filter detail.field-value IN ["value1", "value2", "value3"] # replace field-value and value1, value2, value3 with actual values. | sort @timestamp desc
![]()
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
![]()
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
![]()
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
![]()
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
Find and list the number of exceptions per hour