Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ terraform.rc
.terraform.lock.hcl

build
target
bin
obj
.DS_Store

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also add .DS_Store to your global git ignore file at ~/.gitignore. Here's what's in mine

storage
compile-cache
dev
.npm
.node-gyp
coverage.out

node_modules/

.bundle

.vim/.netrwhist

# Suggested from atom's gitignore
# https://github.com/atom/atom/blob/17a31e3a3729070768f31bbce7ce9bcc09f5a2b8/dot-atom/.gitignore
.atom/blob-store
.atom/compile-cache
.atom/dev
.atom/storage
.atom/.apm
.atom/.node-gyp
.atom/.npm
.atom/.atom-socket-secret-*

# https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

.tmux/resurrect/

# kernprof output
*.lprof

# copilot
.vim/pack/github/start/copilot.vim

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, funny that I don't have .DS_Store in there....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL you can configure global .gitignore files!

65 changes: 63 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,58 @@ module "lambda-datadog" {
}
```

### .NET
```
module "lambda-datadog" {
source = "DataDog/lambda-datadog/aws"
version = "1.1.0"

filename = "example.zip"
function_name = "example-function"
role = aws_iam_role.lambda_role.arn
handler = "Example::Example.Function::Handler"
runtime = "dotnet8"
memory_size = 256

environment_variables = {
"DD_API_KEY_SECRET_ARN" : "arn:aws:secretsmanager:us-east-1:000000000000:secret:example-secret"
"DD_ENV" : "dev"
"DD_SERVICE" : "example-service"
"DD_SITE": "datadoghq.com"
"DD_VERSION" : "1.0.0"
}

datadog_extension_layer_version = 58
datadog_dotnet_layer_version = 15
}
```

### Java
```
module "lambda-datadog" {
source = "DataDog/lambda-datadog/aws"
version = "1.1.0"

filename = "example.jar"
function_name = "example-function"
role = aws_iam_role.lambda_role.arn
handler = "com.example.Handler"
runtime = "java21"
memory_size = 1024

environment_variables = {
"DD_API_KEY_SECRET_ARN" : "arn:aws:secretsmanager:us-east-1:000000000000:secret:example-secret"
"DD_ENV" : "dev"
"DD_SERVICE" : "example-service"
"DD_SITE": "datadoghq.com"
"DD_VERSION" : "1.0.0"
}

datadog_extension_layer_version = 58
datadog_java_layer_version = 14
}
```

## Configuration

### Lambda Function
Expand All @@ -84,6 +136,7 @@ resource "aws_lambda_function" "example_lambda_function" {
variables = {
"DD_API_KEY_SECRET_ARN" : "arn:aws:secretsmanager:us-east-1:000000000000:secret:example-secret"
"DD_ENV" : "dev"
"DD_SITE": "datadoghq.com"
"DD_SERVICE" : "example-service"
"DD_VERSION" : "1.0.0"
}
Expand All @@ -94,15 +147,17 @@ resource "aws_lambda_function" "example_lambda_function" {

#### Datadog Terraform module for AWS Lambda
```
module "example_lambda_function" {
source = "Datadog/lambda-datadog/aws"
module "lambda-datadog" {
source = "DataDog/lambda-datadog/aws"
version = "1.1.0"

function_name = "example-function"
...

environment_variables = {
"DD_API_KEY_SECRET_ARN" : "arn:aws:secretsmanager:us-east-1:000000000000:secret:example-secret"
"DD_ENV" : "dev"
"DD_SITE": "datadoghq.com"
"DD_SERVICE" : "example-service"
"DD_VERSION" : "1.0.0"
}
Expand All @@ -119,6 +174,8 @@ Use the following variables to select the versions of the Datadog Lambda layers
| Variable | Description |
| -------- | ----------- |
| `datadog_extension_layer_version` | Version of the [Datadog Lambda Extension layer](https://github.com/DataDog/datadog-lambda-extension/releases) to install |
| `datadog_dotnet_layer_version` | Version of the [Datadog .NET Lambda layer](https://github.com/DataDog/dd-trace-dotnet-aws-lambda-layer/releases) to install |
| `datadog_java_layer_version` | Version of the [Datadog Java Lambda layer](https://github.com/DataDog/datadog-lambda-java/releases) to install |
| `datadog_node_layer_version` | Version of the [Datadog Node Lambda layer](https://github.com/DataDog/datadog-lambda-js/releases) to install |
| `datadog_python_layer_version` | Version of the [Datadog Python Lambda layer](https://github.com/DataDog/datadog-lambda-python/releases) to install |

Expand All @@ -132,6 +189,8 @@ Use Environment variables to configure Datadog Serverless Monitoring. Refer to t

* [Serverless Agent Configuration](https://docs.datadoghq.com/serverless/guide/agent_configuration/)
* Tracer Configuration
- [.NET](https://docs.datadoghq.com/tracing/trace_collection/library_config/dotnet-framework/?tab=environmentvariables)
- [Java](https://docs.datadoghq.com/tracing/trace_collection/library_config/java/)
- [Node](https://github.com/DataDog/datadog-lambda-js?tab=readme-ov-file#configuration)
- [Python](https://github.com/DataDog/datadog-lambda-python?tab=readme-ov-file#configuration)

Expand Down Expand Up @@ -167,6 +226,8 @@ No modules.
| <a name="input_architectures"></a> [architectures](#input\_architectures) | Instruction set architecture for your Lambda function. Valid values are ["x86\_64"] and ["arm64"]. | `list(string)` | <pre>["x86_64"]</pre> | no |
| <a name="input_code_signing_config_arn"></a> [code\_signing\_config\_arn](#input\_code\_signing\_config\_arn) | To enable code signing for this function, specify the ARN of a code-signing configuration. A code-signing configuration includes a set of signing profiles, which define the trusted publishers for this function. | `string` | `null` | no |
| <a name="input_datadog_extension_layer_version"></a> [datadog\_extension\_layer\_version](#input\_datadog\_extension\_layer\_version) | Version for the Datadog Extension Layer | `number` | `58` | no |
| <a name="input_datadog_dotnet_layer_version"></a> [datadog\_dotnet\_layer\_version](#input\_datadog\_dotnet\_layer\_version) | Version for the Datadog .NET Layer | `number` | `15` | no |
| <a name="input_datadog_java_layer_version"></a> [datadog\_java\_layer\_version](#input\_datadog\_java\_layer\_version) | Version for the Datadog Java Layer | `number` | `14` | no |
| <a name="input_datadog_node_layer_version"></a> [datadog\_node\_layer\_version](#input\_datadog\_node\_layer\_version) | Version for the Datadog Node Layer | `number` | `112` | no |
| <a name="input_datadog_python_layer_version"></a> [datadog\_python\_layer\_version](#input\_datadog\_python\_layer\_version) | Version for the Datadog Python Layer | `number` | `95` | no |
| <a name="input_dead_letter_config_target_arn"></a> [dead\_letter\_config\_target\_arn](#input\_dead\_letter\_config\_target\_arn) | ARN of an SNS topic or SQS queue to notify when an invocation fails. | `string` | `null` | no |
Expand Down
71 changes: 71 additions & 0 deletions examples/dotnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# .NET Example

A simple .NET Lambda function with out of the box Datadog instrumentation.

## Usage

* Create a [Datadog API Key](https://app.datadoghq.com/organization-settings/api-keys)
* Create a secret in [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) and add the Datadog API Key as the secret value in plaintext
* Create a `terraform.tfvars` file
- Set the `datadog_secret_arn` to the arn of the secret you just created
- Set the `datadog_service_name` to the name of the service you want to use to filter for the resource in Datadog
- Set the `datadog_site` to the [Datadog destination site](https://docs.datadoghq.com/getting_started/site/) for your metrics, traces, and logs
* Run the following commands

```
dotnet restore ./src/HelloWorld
dotnet lambda package --configuration Debug --framework net8.0 --output-package src/HelloWorld/bin/release/net8.0/hello-dotnet.zip --project-location ./src/HelloWorld
terraform init
terraform plan
terraform apply
```

If using `arm64` architecture then build the lambda package with the `-farch arm64` argument.

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.32.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_archive"></a> [archive](#provider\_archive) | 2.4.2 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.32.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_lambda-datadog"></a> [lambda-datadog](#module\_lambda-datadog) | ../../ | n/a |

## Resources

| Name | Type |
|------|------|
| [aws_iam_policy.secrets_manager_read_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_iam_role.lambda_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role_policy_attachment.attach_iam_policy_to_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_iam_role_policy_attachment.attach_secrets_manager_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [archive_file.zip_code](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_datadog_secret_arn"></a> [datadog\_secret\_arn](#input\_datadog\_secret\_arn) | Secret for Datadog API Key | `string` | n/a | yes |
| <a name="input_datadog_service_name"></a> [datadog\_service\_name](#input\_datadog\_service\_name) | Service used to filter for resources in Datadog | `string` | n/a | yes |
| <a name="input_datadog_site"></a> [datadog\_site](#input\_datadog\_site) | Destination site for your metrics, traces, and logs | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_arn"></a> [arn](#output\_arn) | Amazon Resource Name (ARN) identifying your Lambda Function. |
| <a name="output_function_name"></a> [function\_name](#output\_function\_name) | Unique name for your Lambda Function |
| <a name="output_invoke_arn"></a> [invoke\_arn](#output\_invoke\_arn) | ARN to be used for invoking Lambda Function from API Gateway. |
<!-- END_TF_DOCS -->
63 changes: 63 additions & 0 deletions examples/dotnet/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
resource "aws_iam_role" "lambda_role" {
name = "terraform-example-dotnet-${var.datadog_service_name}-role"
assume_role_policy = jsonencode(
{
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "",
"Effect" : "Allow",
"Action" : "sts:AssumeRole",
"Principal" : {
"Service" : "lambda.amazonaws.com"
}
}
]
})
}

resource "aws_iam_policy" "secrets_manager_read_policy" {
name = "terraform-example-dotnet-${var.datadog_service_name}-secrets-manager-policy"
description = "Policy to allow read access to Secrets Manager"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "ReadSecret"
Effect = "Allow"
Action = "secretsmanager:GetSecretValue"
Resource = var.datadog_secret_arn
}
]
})
}

resource "aws_iam_role_policy_attachment" "attach_iam_policy_to_iam_role" {
role = aws_iam_role.lambda_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_iam_role_policy_attachment" "attach_secrets_manager_policy" {
role = aws_iam_role.lambda_role.name
policy_arn = aws_iam_policy.secrets_manager_read_policy.arn
}

module "lambda-datadog" {
source = "../../"

filename = "${path.module}/src/HelloWorld/bin/release/net8.0/hello-dotnet.zip"
source_code_hash = filebase64sha256("${path.module}/src/HelloWorld/bin/release/net8.0/hello-dotnet.zip")
function_name = "terraform-example-dotnet-${var.datadog_service_name}-function"
role = aws_iam_role.lambda_role.arn
handler = "HelloWorld::HelloWorld.Function::Handler"
runtime = "dotnet8"
memory_size = 256

environment_variables = {
"DD_API_KEY_SECRET_ARN" : var.datadog_secret_arn
"DD_ENV" : "dev"
"DD_SERVICE" : var.datadog_service_name
"DD_SITE" : var.datadog_site
"DD_VERSION" : "1.0.0"
}
}
14 changes: 14 additions & 0 deletions examples/dotnet/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "arn" {
description = "Amazon Resource Name (ARN) identifying your Lambda Function."
value = module.lambda-datadog.arn
}

output "invoke_arn" {
description = "ARN to be used for invoking Lambda Function from API Gateway."
value = module.lambda-datadog.invoke_arn
}

output "function_name" {
description = "Unique name for your Lambda Function"
value = module.lambda-datadog.function_name
}
14 changes: 14 additions & 0 deletions examples/dotnet/src/HelloWorld/Function.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Amazon.Lambda.Core;

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace HelloWorld
{
public class Function
{
public string Handler(object input, ILambdaContext context)
{
return "Hello!";
}
}
}
12 changes: 12 additions & 0 deletions examples/dotnet/src/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="2.2.1" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions examples/dotnet/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "datadog_secret_arn" {
description = "Secret for Datadog API Key"
type = string
}

variable "datadog_service_name" {
description = "Service used to filter for resources in Datadog"
type = string
}

variable "datadog_site" {
description = "Destination site for your metrics, traces, and logs"
type = string
}
10 changes: 10 additions & 0 deletions examples/dotnet/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.3"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.32.0"
}
}
}
68 changes: 68 additions & 0 deletions examples/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Java Example

A simple Java Lambda function with out of the box Datadog instrumentation.

## Usage

* Create a [Datadog API Key](https://app.datadoghq.com/organization-settings/api-keys)
* Create a secret in [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) and add the Datadog API Key as the secret value in plaintext
* Create a `terraform.tfvars` file
- Set the `datadog_secret_arn` to the arn of the secret you just created
- Set the `datadog_service_name` to the name of the service you want to use to filter for the resource in Datadog
- Set the `datadog_site` to the [Datadog destination site](https://docs.datadoghq.com/getting_started/site/) for your metrics, traces, and logs
* Run the following commands

```
mvn clean package shade:shade
terraform init
terraform plan
terraform apply
```

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.32.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_archive"></a> [archive](#provider\_archive) | 2.4.2 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.32.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_lambda-datadog"></a> [lambda-datadog](#module\_lambda-datadog) | ../../ | n/a |

## Resources

| Name | Type |
|------|------|
| [aws_iam_policy.secrets_manager_read_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_iam_role.lambda_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role_policy_attachment.attach_iam_policy_to_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_iam_role_policy_attachment.attach_secrets_manager_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [archive_file.zip_code](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_datadog_secret_arn"></a> [datadog\_secret\_arn](#input\_datadog\_secret\_arn) | Secret for Datadog API Key | `string` | n/a | yes |
| <a name="input_datadog_service_name"></a> [datadog\_service\_name](#input\_datadog\_service\_name) | Service used to filter for resources in Datadog | `string` | n/a | yes |
| <a name="input_datadog_site"></a> [datadog\_site](#input\_datadog\_site) | Destination site for your metrics, traces, and logs | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_arn"></a> [arn](#output\_arn) | Amazon Resource Name (ARN) identifying your Lambda Function. |
| <a name="output_function_name"></a> [function\_name](#output\_function\_name) | Unique name for your Lambda Function |
| <a name="output_invoke_arn"></a> [invoke\_arn](#output\_invoke\_arn) | ARN to be used for invoking Lambda Function from API Gateway. |
<!-- END_TF_DOCS -->
Loading