Enabling App and API Protection for AWS Lambda functions in .NET
Este producto no es compatible con el
sitio Datadog seleccionado. (
).
Configuring App and API Protection for AWS Lambda involves:
- Identifying functions that are vulnerable or are under attack and would most benefit from App and API Protection. Find them on the Security tab of your Software Catalog.
- Setting up App and API Protection instrumentation by using either the Datadog CLI, AWS CDK, Datadog Serverless Framework plugin, or manually by using the Datadog tracing layers.
- Triggering security signals in your application and seeing how Datadog displays the resulting information.
Supported trigger types
Threat Detection supports HTTP requests as function input only, as that channel has the highest likelihood of attackers exploiting a serverless application. HTTP requests typically come from AWS services such as:
- Application Load Balancer (ALB)
- API Gateway v1 (Rest API)
- API Gateway v2 (HTTP API)
- Function URL
If you would like to see support added for any of the unsupported capabilities, fill out this
form and send feedback.
Get started
The Datadog Serverless Framework plugin can be used to automatically configure and deploy your Lambda functions with App and API Protection.
To install and configure the Datadog Serverless Framework plugin:
Install the Datadog Serverless Framework plugin:
serverless plugin install --name serverless-plugin-datadog
Enable App and API Protection by updating your serverless.yml
with the enableASM
configuration parameter:
custom:
datadog:
enableASM: true
Overall, your new serverless.yml
file should contain at least:
custom:
datadog:
apiKeySecretArn: "{Datadog_API_Key_Secret_ARN}" # or apiKey
enableDDTracing: true
enableASM: true
See also the complete list of plugin parameters to further configure your Lambda settings.
Redeploy the function and invoke it. After a few minutes, it appears in App and API Protection views.
The Datadog CLI modifies existing Lambda function configurations to enable instrumentation without requiring a new deployment. It is the quickest way to get started with Datadog’s serverless monitoring.
If you are configuring initial tracing for your functions, perform the following steps:
Install the Datadog CLI client:
npm install -g @datadog/datadog-ci
If you are new to Datadog serverless monitoring, launch the Datadog CLI in interactive mode to guide your first installation for a quick start, and you can ignore the remaining steps. To permanently install Datadog for your production applications, skip this step and follow the remaining ones to run the Datadog CLI command in your CI/CD pipelines after your normal deployment.
datadog-ci lambda instrument -i --appsec
Configure the AWS credentials:
Datadog CLI requires access to the AWS Lambda service, and depends on the AWS JavaScript SDK to resolve the credentials. Ensure your AWS credentials are configured using the same method you would use when invoking the AWS CLI.
Configure the Datadog site:
export DATADOG_SITE="<DATADOG_SITE>"
Replace <DATADOG_SITE>
with
(ensure the correct Datadog site is selected on the right-hand side of this page).
Configure the Datadog API key:
Datadog recommends saving the Datadog API key in AWS Secrets Manager for security. The key needs to be stored as a plaintext string (not a JSON blob). Ensure your Lambda functions have the required secretsmanager:GetSecretValue
IAM permission.
export DATADOG_API_KEY_SECRET_ARN="<DATADOG_API_KEY_SECRET_ARN>"
For testing purposes, you can also set the Datadog API key in plaintext:
export DATADOG_API_KEY="<DATADOG_API_KEY>"
Instrument your Lambda functions:
To instrument your Lambda functions, run the following command.
datadog-ci lambda instrument --appsec -f <functionname> -f <another_functionname> -r <aws_region> -v 20 -e 86
To fill in the placeholders:
- Replace
<functionname>
and <another_functionname>
with your Lambda function names. - Alternatively, you can use
--functions-regex
to automatically instrument multiple functions whose names match the given regular expression. - Replace
<aws_region>
with the AWS region name.
Note: Instrument your Lambda functions in a development or staging environment first. If the instrumentation result is unsatisfactory, run uninstrument
with the same arguments to revert the changes.
Additional parameters can be found in the CLI documentation.
The Datadog CDK Construct automatically installs Datadog on your functions using Lambda Layers, and configures your functions to send metrics, traces, and logs to Datadog through the Datadog Lambda Extension.
Install the Datadog CDK constructs library:
# For AWS CDK v1
npm install datadog-cdk-constructs --save-dev
# For AWS CDK v2
npm install datadog-cdk-constructs-v2 --save-dev
Instrument your Lambda functions
// For AWS CDK v1
import { Datadog } from "datadog-cdk-constructs";
// NOT SUPPORTED IN V1
// For AWS CDK v2
import { Datadog } from "datadog-cdk-constructs-v2";
const datadog = new Datadog(this, "Datadog", {
dotnet_layer_version: 20,
extension_layer_version: 86,
site: "<DATADOG_SITE>",
api_key_secret_arn: "<DATADOG_API_KEY_SECRET_ARN>", // or api_key
enable_asm: true,
});
datadog.add_lambda_functions([<LAMBDA_FUNCTIONS>]);
To fill in the placeholders:
- Replace
<DATADOG_SITE>
with
(ensure the correct SITE is selected on the right). - Replace
<DATADOG_API_KEY_SECRET_ARN>
with the ARN of the AWS secret where your Datadog API key is securely stored. The key needs to be stored as a plaintext string (not a JSON blob). The secretsmanager:GetSecretValue
permission is required. For quick testing, you can use apiKey
instead and set the Datadog API key in plaintext.
More information and additional parameters can be found on the Datadog CDK documentation.
Install the Datadog Tracer
Configure the layers for your Lambda function using the ARN in the following format:
# Use this format for x86-based Lambda deployed in AWS commercial regions
arn:aws:lambda:<AWS_REGION>:464622532012:layer:dd-trace-dotnet:20
# Use this format for arm64-based Lambda deployed in AWS commercial regions
arn:aws:lambda:<AWS_REGION>:464622532012:layer:dd-trace-dotnet-ARM:20
# Use this format for x86-based Lambda deployed in AWS GovCloud regions
arn:aws-us-gov:lambda:<AWS_REGION>:002406178527:layer:dd-trace-dotnet:20
# Use this format for arm64-based Lambda deployed in AWS GovCloud regions
arn:aws-us-gov:lambda:<AWS_REGION>:002406178527:layer:dd-trace-dotnet-ARM:20
Replace <AWS_REGION>
with a valid AWS region, such as us-east-1
.
Install the Datadog Lambda Extension
Configure the layers for your Lambda function using the ARN in the following format:
# Use this format for x86-based Lambda deployed in AWS commercial regions
arn:aws:lambda:<AWS_REGION>:464622532012:layer:Datadog-Extension:86
# Use this format for arm64-based Lambda deployed in AWS commercial regions
arn:aws:lambda:<AWS_REGION>:464622532012:layer:Datadog-Extension-ARM:86
# Use this format for x86-based Lambda deployed in AWS GovCloud regions
arn:aws-us-gov:lambda:<AWS_REGION>:002406178527:layer:Datadog-Extension:86
# Use this format for arm64-based Lambda deployed in AWS GovCloud regions
arn:aws-us-gov:lambda:<AWS_REGION>:002406178527:layer:Datadog-Extension-ARM:86
Replace <AWS_REGION>
with a valid AWS region, such as us-east-1
.
Set the required environment variables
- Set
AWS_LAMBDA_EXEC_WRAPPER
to /opt/datadog_wrapper
. - Set
DD_SITE
to
(ensure the correct SITE is selected on the right). - Set
DD_API_KEY_SECRET_ARN
to the ARN of the AWS secret where your Datadog API key is securely stored. The key needs to be stored as a plaintext string (not a JSON blob). The secretsmanager:GetSecretValue
permission is required. For quick testing, you can use DD_API_KEY
instead and set the Datadog API key in plaintext.
Enable App and API Protection by adding the following environment variables on your function deployment:
environment:
AWS_LAMBDA_EXEC_WRAPPER: /opt/datadog_wrapper
DD_SERVERLESS_APPSEC_ENABLED: true
Redeploy the function and invoke it. After a few minutes, it appears in App and API Protection views.
Further reading
Más enlaces, artículos y documentación útiles: