Skip to content

Commit 4c204a1

Browse files
committed
Update Readme
1 parent b427c06 commit 4c204a1

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

README.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Dynamically adjust sampling rules in X-Ray
2-
This repo is used in the aws blog to showcase dynamic sampling rules on X-Ray
2+
This repo is used in the AWS blog (https://aws.amazon.com/blogs/mt/dynamically-adjusting-x-ray-sampling-rules/) to showcase dynamic sampling rules on X-Ray
33

44
## Security
55

@@ -9,3 +9,87 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform
99

1010
This library is licensed under the MIT-0 License. See the LICENSE file.
1111

12+
13+
## Architecture
14+
Generic pattern of dynamic sampling rule adjustment is shown below. The idea is to use CloudWatch alarm to trigger the X-Ray sampling rule
15+
adjustment process. The alarm can be configured based on applications needs, for example high CPU utilization, number of Lambda function failures,
16+
or rate of 5xx errors in API Gateway.
17+
18+
![Pattern](/doc/pattern.png)
19+
20+
This pattern can be applied to a number of architectures. This repository illustrates it using a simple web application that
21+
contains of API Gateway and backend Lambda function.
22+
23+
![Architecture](/doc/architecture.png)
24+
25+
1. Clients access API Gateway using HTTP requests
26+
2. API Gateway forwards requests to AWS Lambda function for processing
27+
3. Errors in lambda function trigger CloudWatch alarm state change
28+
4. Message about changed alarm state is posted in SNS topic
29+
5. Lambda function is triggered in response to SNS message
30+
6. Based on Alarm state, X-Ray sampling rules are adjusted
31+
7. Incoming requests are traced based on updated rules
32+
33+
## Build and deploy instructions
34+
Example template provided uses [AWS SAM](https://aws.amazon.com/serverless/sam/) to simplify the deployment.
35+
36+
To install lambda function dependencies and create a deployment package use the following command:
37+
```
38+
sam build
39+
```
40+
41+
Once the project is built, use [sam deploy](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html)
42+
to deploy the stack:
43+
44+
```
45+
sam deploy --guided
46+
```
47+
48+
or by providing all parameters in command line:
49+
50+
```
51+
sam deploy --stack-name <stack-name> --s3-bucket <deployment-bucket> --capabilities CAPABILITY_IAM
52+
```
53+
54+
Use the `WebApi` output value to access the deployed API:
55+
```
56+
CloudFormation outputs from deployed stack
57+
-----------------------------------------------------------------------------------
58+
Outputs
59+
-----------------------------------------------------------------------------------
60+
Key WebApi
61+
Description API Gateway endpoint URL for Prod stage for WebApi function
62+
Value https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/Prod/
63+
-----------------------------------------------------------------------------------
64+
```
65+
66+
## X-Ray sampling rule custom resource properties
67+
The repository demonstrates how to manage AWS X-Ray sampling rule resources
68+
using CloudFormation. At the time of writing there is no standard resource type
69+
you can use, so a custom implementation is needed.
70+
71+
The implementation relies on [Custom Resource Helper](https://github.com/aws-cloudformation/custom-resource-helper) package.
72+
73+
74+
| Name | Type | Required | Default | Description |
75+
| --- | ---| --- | ---| --- |
76+
| `Name` | string | yes | | Name of the sampling rule |
77+
| `Priority` | int | yes | | Must be from the range of 1-9999 |
78+
| `FixedRate` | float | yes | | Must be from the range of 0-1 |
79+
| `ReservoirSize` | int | yes | | Maximum number of request to sample per second |
80+
| `ResourceARN` | string | no | * | Resource ARN to match |
81+
| `ServiceName` | string | no | * | Name of the service to match |
82+
| `ServiceType` | string | no | * | Type of the service to match |
83+
| `Host` | string | no | * | The IP address or EC2 hostname to match |
84+
| `HTTPMethod` | string | no | * | HTTP method to match |
85+
| `URLPath` | string | no | * | URL path to match |
86+
87+
88+
## Custom Resource return values
89+
90+
Return values can be referenced in CloudFormation template using [Fn::GetAtt](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html)
91+
92+
| Name | Description |
93+
| --- | --- |
94+
| `Name` | Name of the sampling rule |
95+
| `Arn` | ARN of the sampling rule |

0 commit comments

Comments
 (0)