Skip to content

Commit 4eed1d2

Browse files
authored
Merge pull request DataDog#171 from DataDog/tian.chu/improved-installation-and-upgrade
Forwarder 3.0.0
2 parents eff0c51 + 7e78e70 commit 4eed1d2

File tree

7 files changed

+708
-231
lines changed

7 files changed

+708
-231
lines changed

.github/workflows/lambdachecks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
max-parallel: 4
1111
matrix:
12-
python-version: [2.7, 3.6, 3.7]
12+
python-version: [3.7]
1313
steps:
1414
- uses: actions/checkout@v1
1515
- name: Set up Python ${{ matrix.python-version }}

aws/logs_monitoring/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.zip

aws/logs_monitoring/README.md

Lines changed: 32 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,188 +1,49 @@
1-
**IMPORTANT NOTE: When upgrading, please ensure your forwarder Lambda function has [the latest Datadog Lambda Layer installed](https://github.com/DataDog/datadog-serverless-functions/tree/master/aws/logs_monitoring#3-add-the-datadog-lambda-layer).**
2-
31
# Datadog Forwarder
42

5-
AWS Lambda function to ship logs and metrics from ELB, S3, CloudTrail, VPC, CloudFront, and CloudWatch logs to Datadog
3+
AWS Lambda function to ship logs from S3 and CloudWatch, custom metrics and traces from Lambda functions to Datadog.
64

75
## Features
86

9-
- Forward logs through HTTPS (defaulted to port 443)
10-
- Use AWS Lambda to re-route triggered S3 events to Datadog
11-
- Use AWS Lambda to re-route triggered Kinesis data stream events to Datadog, only the Cloudwatch logs are supported
12-
- Cloudwatch, ELB, S3, CloudTrail, VPC and CloudFront logs can be forwarded
13-
- SSL Security
14-
- JSON events providing details about S3 documents forwarded
15-
- Structured meta-information can be attached to the events
16-
- Scrubbing / Redaction rules
17-
- Filtering rules (`INCLUDE_AT_MATCH` and `EXCLUDE_AT_MATCH`)
18-
- Multiline Log Support (S3 Only)
19-
- Forward custom metrics from logs
20-
- Submit `aws.lambda.enhanced.*` Lambda metrics parsed from the AWS REPORT log: duration, billed_duration, max_memory_used, estimated_cost
21-
22-
## Quick Start
23-
24-
The provided Python script must be deployed into your AWS Lambda service to collect your logs and send them to Datadog.
25-
26-
### 1. Create a new Lambda function
27-
28-
1. [Navigate to the Lambda console](https://console.aws.amazon.com/lambda/home) and create a new function.
29-
2. Select `Author from scratch` and give the function a unique name: `datadog-log-monitoring-function`
30-
3. For `Role`, select `Create new role from template(s)` and give the role a unique name: `datadog-log-monitoring-function-role`
31-
4. Under Policy templates, select `s3 object read-only permissions`.
32-
33-
### 2. Provide the code
34-
35-
1. Copy paste the code of the Lambda function from the `lambda_function.py` file.
36-
2. Set the runtime to `Python 2.7`, `Python 3.6`, or `Python 3.7`
37-
3. Set the handler to `lambda_function.lambda_handler`
38-
39-
### 3. Add the Datadog Lambda Layer
40-
The [Datadog Lambda Layer]((https://github.com/DataDog/datadog-lambda-layer-python)) **MUST** be added to the log forwarder Lambda function. Use the Lambda layer ARN below, and replace `<AWS_REGION>` with the actual region (e.g., `us-east-1`), `<PYTHON_RUNTIME>` with the runtime of your forwarder (e.g., `Python27`), and `<VERSION>` with the latest version from the [CHANGELOG](https://github.com/DataDog/datadog-lambda-layer-python/blob/master/CHANGELOG.md).
41-
42-
```
43-
arn:aws:lambda:<AWS_REGION>:464622532012:layer:Datadog-<PYTHON_RUNTIME>:<VERSION>
44-
```
45-
46-
For example:
47-
48-
```
49-
arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Python37:8
50-
```
51-
52-
53-
### 4. Set your Parameters
54-
55-
At the top of the script you'll find a section called `PARAMETERS`, that's where you want to edit your code, available paramters are:
56-
57-
#### DD_API_KEY
58-
59-
Set the Datadog API key for your Datadog platform, it can be found here:
60-
61-
* Datadog US Site: https://app.datadoghq.com/account/settings#api
62-
* Datadog EU Site: https://app.datadoghq.eu/account/settings#api
63-
64-
There are 3 possibilities to set your Datadog API key:
65-
66-
1. **KMS Encrypted key (recommended)**: Use the `DD_KMS_API_KEY` environment variable to use a KMS encrypted key. Make sure that the Lambda execution role is listed in the KMS Key user in https://console.aws.amazon.com/iam/home#encryptionKeys.
67-
2. **Environment Variable**: Use the `DD_API_KEY` environment variable for the Lambda function.
68-
3. **Manual**: Replace `<YOUR_DATADOG_API_KEY>` in the code:
69-
70-
```python
71-
## @param DD_API_KEY - String - required - default: none
72-
## The Datadog API key associated with your Datadog Account
73-
## It can be found here:
74-
##
75-
## * Datadog US Site: https://app.datadoghq.com/account/settings#api
76-
## * Datadog EU Site: https://app.datadoghq.eu/account/settings#api
77-
#
78-
DD_API_KEY = "<YOUR_DATADOG_API_KEY>"
79-
```
80-
81-
#### Custom Tags
82-
83-
Add custom tags to all data forwarded by your function, either:
84-
85-
* Use the `DD_TAGS` environment variable. Your tags must be a comma-separated list of strings with no trailing comma.
86-
* Edit the lambda code directly:
87-
88-
```python
89-
## @param DD_TAGS - list of comma separated strings - optional -default: none
90-
## Pass custom tags as environment variable or through this variable.
91-
## Ensure your tags are a comma separated list of strings with no trailing comma in the envvar!
92-
#
93-
DD_TAGS = os.environ.get("DD_TAGS", "")
94-
```
95-
96-
#### Datadog Site
97-
98-
Define your Datadog Site to send data to, `datadoghq.com` for Datadog US site or `datadoghq.eu` for Datadog EU site, either:
99-
100-
* Use the `DD_SITE` environment variable.
101-
* Edit the lambda code directly:
102-
103-
```python
104-
## @param DD_SITE - String - optional -default: datadoghq.com
105-
## Define the Datadog Site to send your logs and metrics to.
106-
## Set it to `datadoghq.eu` to send your logs and metrics to Datadog EU site.
107-
#
108-
DD_SITE = os.getenv("DD_SITE", default="datadoghq.com")
109-
```
110-
111-
#### Send logs through TCP or HTTP.
112-
113-
By default, the forwarder sends logs using HTTPS through the port `443`. To send logs over a SSL encrypted TCP connection either:
114-
115-
* Set the environment variable `DD_USE_TCP` to `true`.
116-
* Edit the lambda code directly:
117-
118-
```python
119-
## @param DD_USE_TCP - boolean - optional -default: false
120-
## Change this value to `true` to send your logs and metrics using the HTTP network client
121-
## By default, it use the TCP client.
122-
#
123-
DD_USE_TCP = os.getenv("DD_USE_TCP", default="false").lower() == "true"
124-
```
125-
126-
#### Proxy
127-
128-
Ensure that you disable SSL between the lambda and your proxy by setting `DD_NO_SSL` to `true`
129-
130-
Two environment variables can be used to forward logs through a proxy:
131-
132-
* `DD_URL`: Define the proxy endpoint to forward the logs to.
133-
* `DD_PORT`: Define the proxy port to forward the logs to.
134-
135-
#### DD_FETCH_LAMBDA_TAGS
136-
137-
If the `DD_FETCH_LAMBDA_TAGS` env variable is set to `true` then the log forwarder will fetch Lambda tags using [GetResources](https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_GetResources.html) API calls and apply them to the `aws.lambda.enhanced.*` metrics parsed from the REPORT log. For this to work the log forwarder function needs to be given the `tag:GetResources` permission. The tags are cached in memory so that they'll only be fetched when the function cold starts or when the TTL (1 hour) expires. The log forwarder increments the `aws.lambda.enhanced.get_resources_api_calls` metric for each API call made.
138-
139-
### 5. Configure your function
140-
141-
To configure your function:
142-
143-
1. Set the memory to 1024 MB.
144-
2. Also set the timeout limit. 120 seconds is recommended to deal with big files.
145-
3. Hit the `Save` button.
146-
147-
### 6. Test it
148-
149-
Hit the `Test` button, and select `CloudWatch Logs` as the sample event. If the test "succeeded", you are all set! The test log doesn't show up in the platform.
150-
151-
**Note**: For S3 logs, there may be some latency between the time a first S3 log file is posted and the Lambda function wakes up.
7+
- Forward CloudWatch, ELB, S3, CloudTrail, VPC and CloudFront logs to Datadog
8+
- Forward S3 events to Datadog
9+
- Forward Kinesis data stream events to Datadog, only CloudWatch logs are supported
10+
- Forward custom metrics from AWS Lambda functions via CloudWatch logs
11+
- Forward traces from AWS Lambda functions via CloudWatch logs
12+
- Generate and submit enhanced Lambda metrics (`aws.lambda.enhanced.*`) parsed from the AWS REPORT log: duration, billed_duration, max_memory_used, and estimated_cost
15213

153-
### 7. (optional) Scrubbing / Redaction rules
14+
## Install
15415

155-
Multiple scrubbing options are available. `REDACT_IP` and `REDACT_EMAIL` match against hard-coded patterns, while `DD_SCRUBBING_RULE` allows users to supply a regular expression.
156-
- To use `REDACT_IP`, add it as an environment variable and set the value to `true`.
157-
- Text matching `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}` is replaced with `xxx.xxx.xxx.xxx`.
158-
- To use `REDACT_EMAIL`, add it as an environment variable and set the value to `true`.
159-
- Text matching `[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+` is replaced with `xxxxx@xxxxx.com`.
160-
- To use `DD_SCRUBBING_RULE`, add it as a environment variable, and supply a regular expression as the value.
161-
- Text matching the user-supplied regular expression is replaced with `xxxxx`, by default.
162-
- Use the `DD_SCRUBBING_RULE_REPLACEMENT` environment variable to supply a replacement value instead of `xxxxx`.
163-
- Scrubbing rules are applied to the full JSON-formatted log, including any metadata that is automatically added by the Lambda function.
164-
- Each instance of a pattern match is replaced until no more matches are found in each log.
16+
1. Login AWS using a user/role with admin permissions.
17+
1. Deploy the [datadog-serverless](https://console.aws.amazon.com/cloudformation/home#/stacks/new?stackName=datadog-serverless&templateURL=https://dd-log-sam.s3.amazonaws.com/templates/3.0.0.yaml) CloudFormation stack.
18+
1. Fill in `DdApiKey` and select the appropriate `DdSite`.
19+
1. All other parameters are optional, leave them as default.
20+
1. You can find the installed Forwarder under the stack's "Resources" tab.
21+
1. Set up triggers to the installed Forwarder either [manually](https://docs.datadoghq.com/integrations/amazon_web_services/?tab=allpermissions#manually-setup-triggers) or [automatically](https://docs.datadoghq.com/integrations/amazon_web_services/?tab=allpermissions#automatically-setup-triggers).
22+
1. Repeat the above steps in another region if you operate in multiple AWS regions.
16523

166-
### 8. (optional) Filtering rules
24+
## Update
16725

168-
Use the `EXCLUDE_AT_MATCH` OR `INCLUDE_AT_MATCH` environment variables to filter logs based on a regular expression match:
26+
### Upgrade to a different version
16927

170-
- To use `EXCLUDE_AT_MATCH` add it as an environment variable and set its value to a regular expression. Logs matching the regular expression are excluded.
171-
- To use `INCLUDE_AT_MATCH` add it as an environment variable and set its value to a regular expression. If not excluded by `EXCLUDE_AT_MATCH`, logs matching the regular expression are included.
172-
- If a log matches both the inclusion and exclusion criteria, it is excluded.
173-
- Filtering rules are applied to the full JSON-formatted log, including any metadata that is automatically added by the function.
28+
1. Find the [datadog-serverless (if you didn't rename it)](https://console.aws.amazon.com/cloudformation/home#/stacks?filteringText=datadog) CloudFormation stack.
29+
1. Update the stack using template `https://dd-log-sam.s3.amazonaws.com/templates/<VERSION>.yaml`. The latest version can be found in the [template.yaml](template.yaml).
17430

175-
### 9. (optional) Multiline Log support for s3
31+
### Adjust forwarder settings
17632

177-
If there are multiline logs in s3, set `DD_MULTILINE_LOG_REGEX_PATTERN` environment variable to the specified regex pattern to detect for a new log line.
33+
1. Find the [datadog-serverless (if you didn't rename it)](https://console.aws.amazon.com/cloudformation/home#/stacks?filteringText=datadog) CloudFormation stack.
34+
1. Update the stack using the current template.
35+
1. Adjust parameter values.
17836

179-
- Example: for multiline logs beginning with pattern `11/10/2014`: `DD_MULTILINE_LOG_REGEX_PATTERN="\d{2}\/\d{2}\/\d{4}"`
37+
Note: It's recommended to adjust forwarder settings through CloudFormation rather than directly editing the Lambda function. The description of settings can be found in the [template.yaml](template.yaml) and the CloudFormation stack creation user interface when you launch the stack. Feel free to submit a pull request to make additional settings adjustable through the template.
18038

181-
### 10. (optional) Disable log forwarding
39+
## Troubleshoot
18240

183-
The datadog forwarder **ALWAYS** forwards logs by default. If you do NOT use the Datadog log management product, you **MUST** set environment variable `DD_FORWARD_LOG` to `False`, to avoid sending logs to Datadog. The forwarder will then only forward other observability data, such as metrics.
41+
Set the environment variable `DD_LOG_LEVEL` to `debug` on the Forwarder Lambda function to enable detailed logging temporarily (don't forget to remove it). If the debug logs don't help, please contact [Datadog support](https://www.datadoghq.com/support/).
18442

185-
### 11. (optional) Disable SSL validation
43+
## Notes
18644

187-
If you need to ignore SSL certificate validation when forwarding logs using HTTPS, you can set the environment variable `DD_SKIP_SSL_VALIDATION` to `True`.
188-
This will still encrypt the traffic between the forwarder and the endpoint provided with `DD_URL` but will not check if the destination SSL certificate is valid.
45+
* For S3 logs, there may be some latency between the time a first S3 log file is posted and the Lambda function wakes up.
46+
* Currently, the forwarder has to be deployed manually to GovCloud and China, and supports only log forwarding.
47+
1. Create a Lambda function using `aws-dd-forwarder-<VERSION>.zip` from the latest [releases](https://github.com/DataDog/datadog-serverless-functions/releases).
48+
1. Save your Datadog API key in AWS Secrets Manager, and set environment variable `DD_API_KEY_SECRET_ARN` with the secret ARN on the Lambda function.
49+
1. Configure [triggers](https://docs.datadoghq.com/integrations/amazon_web_services/?tab=allpermissions#send-aws-service-logs-to-datadog).

0 commit comments

Comments
 (0)