-
Notifications
You must be signed in to change notification settings - Fork 10
Add Java and .NET Support #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
13885c5
add support for java and .net lambda functions
duncanpharvey 4c21e84
adds java example
duncanpharvey d946af2
adds .net example
duncanpharvey 5def469
formatting
duncanpharvey cdeb063
update documentation for .net and java
duncanpharvey d5e3f44
minor updates to documentation
duncanpharvey a07bce6
add comment with option for building dotnet example with arm64 archit…
duncanpharvey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,7 @@ terraform.rc | |
| .terraform.lock.hcl | ||
|
|
||
| build | ||
| target | ||
| bin | ||
| obj | ||
| .DS_Store | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!"; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 --> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_Storeto your global git ignore file at~/.gitignore. Here's what's in mineThere was a problem hiding this comment.
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....
There was a problem hiding this comment.
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
.gitignorefiles!