This product is not supported for your selected Datadog site. ().
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Configuring App and API Protection for AWS Lambda involves:

  1. Identifying functions that are vulnerable or are under attack, which would most benefit from App and API Protection. Find them on the Security tab of your Software Catalog.
  2. 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.
  3. 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 to send feedback.

Get started

The Datadog Serverless Framework plugin can be used to automatically configure and deploy your lambda with App and API Protection.

To install and configure the Datadog Serverless Framework plugin:

  1. Install the Datadog Serverless Framework plugin:

    serverless plugin install --name serverless-plugin-datadog
    
  2. 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.

  3. 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:

  1. Install the Datadog CLI client:

    npm install -g @datadog/datadog-ci
    
  2. 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
    
  3. 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.

  4. 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).

  5. 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>"
    
  6. 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> -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. After the CLI completes, update your source code to depend on the latest datadog-lambda-go module release to enable App and API Protection.

    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.

  1. 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
    
  2. 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", {
        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.

  1. Update your function code to use the latest Go tracer:

    go get -u github.com/DataDog/datadog-lambda-go
    
  2. Install the Datadog Lambda Extension by configuring the layers for your Lambda function using the ARN in one of the following formats. Replace <AWS_REGION> with a valid AWS region such as us-east-1:

    # x86-based Lambda in AWS commercial regions
    arn:aws:lambda:<AWS_REGION>:464622532012:layer:Datadog-Extension:86
    # arm64-based Lambda in AWS commercial regions
    arn:aws:lambda:<AWS_REGION>:464622532012:layer:Datadog-Extension-ARM:86
    # x86-based Lambda in AWS GovCloud regions
    arn:aws-us-gov:lambda:<AWS_REGION>:002406178527:layer:Datadog-Extension:86
    # arm64-based Lambda in AWS GovCloud regions
    arn:aws-us-gov:lambda:<AWS_REGION>:002406178527:layer:Datadog-Extension-ARM:86
    
  3. 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
    
  4. Redeploy the function and invoke it. After a few minutes, it appears in [App and API protection views][1]. [1]: https://app.datadoghq.com/security/appsec?column=time&order=desc

Further reading