|
| 1 | +{{ $language := .Get "language" }} |
| 2 | +{{ $layer := .Get "layer" }} |
| 3 | +{{ $layerParamPython := .Get "layerParamPython" }} |
| 4 | +{{ $layerParamTypescript := .Get "layerParamTypescript" }} |
| 5 | +{{ $layerParamGo := title $layerParamTypescript }} |
| 6 | +{{ $layerVersion := "" }} |
| 7 | +{{ if $layer }} |
| 8 | + {{ $layerVersion = trim ($.Page.RenderString (printf "{{< latest-lambda-layer-version layer=%q >}}" $layer)) "\n\r\t " }} |
| 9 | +{{ end }} |
| 10 | +{{ $layerExtensionVersion := trim ($.Page.RenderString "{{< latest-lambda-layer-version layer=\"extension\" >}}") "\n\r\t " }} |
| 11 | +{{ $site := $.Page.RenderString "{{< region-param key=\"dd_site\" code=\"true\" >}}" }} |
| 12 | + |
| 13 | +<div class="alert alert-info">Instrumenting {{ title $language }} functions through the Datadog CDK construct is only available for AWS CDK apps written in Typescript, Python, and Go.</div> |
| 14 | + |
| 15 | +The [Datadog CDK construct][1] automatically installs Datadog on your functions using Lambda layers. It configures your functions to send metrics, traces, and logs to Datadog through the Datadog Lambda Extension. |
| 16 | + |
| 17 | +### TypeScript |
| 18 | + |
| 19 | +1. Install the Datadog CDK constructs library |
| 20 | + |
| 21 | + For AWS CDK v1: |
| 22 | + ```sh |
| 23 | + npm install datadog-cdk-constructs --save-dev |
| 24 | + ``` |
| 25 | + For AWS CDK v2: |
| 26 | + ```sh |
| 27 | + npm install datadog-cdk-constructs-v2 --save-dev |
| 28 | + ``` |
| 29 | + |
| 30 | +2. Instrument your Lambda functions |
| 31 | + |
| 32 | + For AWS CDK v1: |
| 33 | + ```typescript |
| 34 | + import { Datadog } from "datadog-cdk-constructs"; |
| 35 | + |
| 36 | + const datadog = new Datadog(this, "Datadog", { |
| 37 | + {{ if $layerParamTypescript }}{{ $layerParamTypescript }}: {{ $layerVersion }}, |
| 38 | + {{ end }}extensionLayerVersion: {{ $layerExtensionVersion }}, |
| 39 | + site: "<DATADOG_SITE>", |
| 40 | + apiKeySecretArn: "<DATADOG_API_KEY_SECRET_ARN>" |
| 41 | + }); |
| 42 | + datadog.addLambdaFunctions([<LAMBDA_FUNCTIONS>]) |
| 43 | + ``` |
| 44 | + For AWS CDK v2: |
| 45 | + ```typescript |
| 46 | + import { DatadogLambda } from "datadog-cdk-constructs-v2"; |
| 47 | + |
| 48 | + const datadogLambda = new DatadogLambda(this, "datadogLambda", { |
| 49 | + {{ if $layerParamTypescript }}{{ $layerParamTypescript }}: {{ $layerVersion }}, |
| 50 | + {{ end }}extensionLayerVersion: {{ $layerExtensionVersion }}, |
| 51 | + site: "<DATADOG_SITE>", |
| 52 | + apiKeySecretArn: "<DATADOG_API_KEY_SECRET_ARN>" |
| 53 | + }); |
| 54 | + datadogLambda.addLambdaFunctions([<LAMBDA_FUNCTIONS>]) |
| 55 | + ``` |
| 56 | + |
| 57 | +### Python |
| 58 | + |
| 59 | +1. Install the Datadog CDK constructs library |
| 60 | + |
| 61 | + For AWS CDK v1: |
| 62 | + ```sh |
| 63 | + pip install datadog-cdk-constructs |
| 64 | + ``` |
| 65 | + For AWS CDK v2: |
| 66 | + ```sh |
| 67 | + pip install datadog-cdk-constructs-v2 |
| 68 | + ``` |
| 69 | + |
| 70 | +2. Instrument your Lambda functions |
| 71 | + |
| 72 | + For AWS CDK v1: |
| 73 | + ```python |
| 74 | + from datadog_cdk_constructs import Datadog |
| 75 | + datadog = Datadog(self, "Datadog", |
| 76 | + {{ if $layerParamPython }}{{ $layerParamPython }}={{ $layerVersion }}, |
| 77 | + {{ end }}extension_layer_version={{ $layerExtensionVersion }}, |
| 78 | + site="<DATADOG_SITE>", |
| 79 | + api_key_secret_arn="<DATADOG_API_KEY_SECRET_ARN>", |
| 80 | + ) |
| 81 | + datadog.add_lambda_functions([<LAMBDA_FUNCTIONS>]) |
| 82 | + ``` |
| 83 | + For AWS CDK v2: |
| 84 | + ```python |
| 85 | + from datadog_cdk_constructs_v2 import DatadogLambda |
| 86 | + |
| 87 | + datadog = DatadogLambda(self, "datadogLambda", |
| 88 | + {{ if $layerParamPython }}{{ $layerParamPython }}={{ $layerVersion }}, |
| 89 | + {{ end }}extension_layer_version={{ $layerExtensionVersion }}, |
| 90 | + site="<DATADOG_SITE>", |
| 91 | + api_key_secret_arn="<DATADOG_API_KEY_SECRET_ARN>", |
| 92 | + ) |
| 93 | + datadog.add_lambda_functions([<LAMBDA_FUNCTIONS>]) |
| 94 | + ``` |
| 95 | + |
| 96 | +### Go |
| 97 | + |
| 98 | +**Note**: Go CDK constructs are only available for AWS CDK v2. |
| 99 | + |
| 100 | +1. Install the Datadog CDK constructs library |
| 101 | + |
| 102 | + ```sh |
| 103 | + go get github.com/DataDog/datadog-cdk-constructs-go/ddcdkconstruct/v3 |
| 104 | + ``` |
| 105 | + |
| 106 | +2. Instrument your Lambda functions |
| 107 | + |
| 108 | + ```go |
| 109 | + import ( |
| 110 | + "github.com/DataDog/datadog-cdk-constructs-go/ddcdkconstruct/v3" |
| 111 | + ) |
| 112 | + |
| 113 | + datadogLambda := ddcdkconstruct.NewDatadogLambda( |
| 114 | + stack, |
| 115 | + jsii.String("Datadog"), |
| 116 | + &ddcdkconstruct.DatadogLambdaProps{ |
| 117 | + {{ if $layerParamGo }}{{ $layerParamGo }}: jsii.Number({{ $layerVersion }}), |
| 118 | + {{ end }}ExtensionLayerVersion: jsii.Number({{ $layerExtensionVersion }}), |
| 119 | + Site: jsii.String("<DATADOG_SITE>"), |
| 120 | + ApiKeySecretArn: jsii.String("<DATADOG_API_KEY_SECRET_ARN>"), |
| 121 | + }) |
| 122 | + datadogLambda.AddLambdaFunctions(&[]interface{}{<LAMBDA_FUNCTIONS>}, nil) |
| 123 | + ``` |
| 124 | + |
| 125 | +To fill in the placeholders: |
| 126 | +- Replace `<DATADOG_SITE>` with {{ $site }} (ensure the correct SITE is selected on the right). |
| 127 | +- Replace `<DATADOG_API_KEY_SECRET_ARN>` with the ARN of the AWS secret where your [Datadog API key][2] is securely stored. The key needs to be stored as a plaintext string (not a JSON blob). Ensure your Lambda execution role has the `secretsmanager:GetSecretValue` IAM permission in order to read the secret value. For quick testing, you can use `apiKey` instead and set the Datadog API key in plaintext. |
| 128 | + |
| 129 | +More information and additional parameters can be found on the [Datadog CDK documentation][1]. |
| 130 | + |
| 131 | +[1]: https://github.com/DataDog/datadog-cdk-constructs |
| 132 | +[2]: https://app.datadoghq.com/organization-settings/api-keys |
0 commit comments