For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/logs/guide/send-aws-services-logs-with-the-datadog-lambda-function.md. A documentation index is available at /llms.txt.

Send AWS Services Logs With The Datadog Lambda Function

AWS service logs can be collected with the Datadog Forwarder Lambda function. This Lambda—which triggers on S3 Buckets, CloudWatch log groups, and EventBridge events—forwards logs to Datadog.

To start collecting logs from your AWS services:

  1. Set up the Datadog Forwarder Lambda function in your AWS account.
  2. Enable logging for your AWS service. Find your service in Supported AWS services to see its setup instructions. Most AWS services can log to a S3 bucket or a CloudWatch log group.
  3. Set up the triggers that cause the Forwarder Lambda to execute when there are new logs to be forwarded. There are two ways to configure the triggers.

Notes:

  • You can use AWS PrivateLink to send your logs over a private connection.
  • CloudFormation creates an IAM policy which includes KMS:Decrypt for all resources, and does not align with AWS Security Hub’s best practice. This permission is used to decrypt objects from KMS-encrypted S3 buckets to set up the Lambda function, and the KMS key used to encrypt the S3 buckets cannot be predicted. You can safely delete this permission after the installation finishes successfully.

Supported AWS services

The Datadog Forwarder Lambda function supports any AWS service that generates logs into a S3 bucket or a CloudWatch log group. The following table lists the services it can collect:

  • AWS service: The AWS service that generates the logs. Each service name links to its log collection setup instructions. Services without a link require no service-side setup.
  • Log source: The source tag Datadog applies to the logs. Use it to find your logs in the Log Explorer.
  • Storage: Where the AWS service can write logs that the Forwarder collects.
  • Automatic collection: Whether Datadog can automatically set up the triggers for that log source. If not, set up the triggers manually.
AWS serviceLog sourceStorageAutomatic collection
API Gatewaysource:apigatewayCloudWatch, S3Yes
AppSyncsource:appsyncCloudWatchYes
Batchsource:batchCloudWatchYes
Bedrocksource:bedrockCloudWatch, S3No
Bedrock Agentcoresource:bedrock-agentcoreCloudWatch, S3Yes
CloudFrontsource:cloudfrontCloudWatch, S3Yes
CloudTrailsource:cloudtrailCloudWatch, S3Yes
CodeBuildsource:codebuildCloudWatch, S3Yes
DMSsource:dmsCloudWatch, S3Yes
DocumentDBsource:docdbCloudWatch, S3Yes
ECSsource:ecsCloudWatchYes
EKSsource:eks 1CloudWatchYes
Elastic Beanstalk- 2CloudWatchYes
Elastic Load Balancing (ELB)source:elbCloudWatch, S3Yes
FSxsource:aws.fsxCloudWatch, S3No
Gluesource:glueCloudWatch, S3Yes
IoTsource:iotCloudWatchPartial 3
Lambdasource:lambdaCloudWatchYes
Lambda@Edgesource:lambdaCloudWatchYes
Lambda MicroVMssource:lambdaCloudWatchYes
MWAAsource:mwaaCloudWatchYes
Network Firewallsource:network-firewallCloudWatch, S3Yes
OpenSearchsource:opensearchCloudWatchNo
PCS- 2CloudWatchPartial 4
RDSsource:rds 5CloudWatchYes
Redshiftsource:redshiftCloudWatch, S3Yes
Redshift Serverlesssource:redshift-serverlessCloudWatchYes
Route 53source:route53 6CloudWatchYes
S3source:s3S3Yes
SSMsource:ssmCloudWatchYes
Step Functionssource:stepfunctionCloudWatchYes
Transit Gatewaysource:transitgatewayCloudWatch, S3No
Verified Accesssource:verified-accessCloudWatch, S3Yes
VPCsource:vpcCloudWatch, S3Yes
VPN- 2CloudWatch, S3Yes 7
Web Application Firewallsource:wafS3Yes

1 EKS control plane logs also use the kubernetes.audit, kube-scheduler, kube-apiserver, kube-controller-manager, and aws-iam-authenticator sources.
2 Datadog does not apply a service-specific source tag to these logs.
3 Automatic collection for IoT is available at the account level only.
4 Automatic collection for PCS is available for CloudWatch log groups only.
5 RDS engine logs also use the postgresql, mariadb, and mysql sources.
6 Covers both DNS query logs and Resolver query logs.
7 Automatic collection is available for CloudWatch log groups. For S3 buckets, set up the trigger manually.

Note: The Datadog Forwarder automatically creates subscription filters on CloudWatch log groups. Each filter is named in the format DD_LOG_SUBSCRIPTION_FILTER_<LOG_GROUP_NAME>.

Services collected through another method

The following AWS services are supported for log collection, but do not use the Datadog Forwarder Lambda function in the same way:

AWS serviceHow logs are collected
DynamoDBDynamoDB does not generate its own logs. API activity is captured through CloudTrail. See Send logs to Datadog.
EC2Use the Datadog Agent to send your logs to Datadog.
SNSSNS does not provide logs, but you can process logs and events that are transiting through to the SNS service. See Send logs to Datadog.

Set up triggers

There are two options when configuring triggers on the Datadog Forwarder Lambda function:

  • Automatically: Datadog automatically retrieves the log locations for the selected AWS services and adds them as triggers on the Datadog Forwarder Lambda function. Datadog also keeps the list up to date.
  • Manually: Set up each trigger yourself.

Automatically set up triggers

Datadog can automatically configure triggers on the Datadog Forwarder Lambda function to collect AWS logs. However, automatic subscription does not support creating triggers across different AWS accounts or regions. For scenarios where logs are published to S3 buckets in a separate account, we recommend manually creating a trigger in the same account as the bucket to work around this limitation.

To see which services support automatic collection, and the storage locations they support, see Supported AWS services.

  1. If you haven’t already, set up the Datadog log collection AWS Lambda function.

  2. Ensure the policy of the IAM role used for Datadog-AWS integration has the following permissions. Information on how these permissions are used can be found in the descriptions below:

    "airflow:GetEnvironment",
    "airflow:ListEnvironments",
    "appsync:ListGraphqlApis",
    "batch:DescribeJobDefinitions",
    "cloudfront:GetDistributionConfig",
    "cloudfront:ListDistributions",
    "cloudtrail:GetTrail",
    "cloudtrail:ListTrails",
    "codebuild:BatchGetProjects",
    "codebuild:ListProjects",
    "dms:DescribeReplicationInstances",
    "ec2:DescribeFlowLogs",
    "ec2:DescribeVerifiedAccessInstanceLoggingConfigurations",
    "ec2:DescribeVpnConnections",
    "ecs:DescribeTaskDefinition",
    "ecs:ListTaskDefinitionFamilies",
    "eks:DescribeCluster",
    "eks:ListClusters",
    "elasticbeanstalk:DescribeEnvironments",
    "elasticloadbalancing:DescribeLoadBalancerAttributes",
    "elasticloadbalancing:DescribeLoadBalancers",
    "glue:BatchGetJobs",
    "glue:GetJobs",
    "glue:GetJob",
    "glue:ListJobs",
    "iot:GetV2LoggingOptions",
    "lambda:GetMicrovmImageVersion",
    "lambda:GetPolicy",
    "lambda:InvokeFunction",
    "lambda:List*",
    "logs:DeleteSubscriptionFilter",
    "logs:DescribeDeliveries",
    "logs:DescribeDeliverySources",
    "logs:DescribeLogGroups",
    "logs:DescribeSubscriptionFilters",
    "logs:GetDeliveryDestination",
    "logs:PutSubscriptionFilter",
    "network-firewall:DescribeLoggingConfiguration",
    "network-firewall:ListFirewalls",
    "rds:DescribeDBClusters",
    "rds:DescribeDBInstances",
    "redshift-serverless:ListNamespaces",
    "redshift:DescribeClusters",
    "redshift:DescribeLoggingStatus",
    "route53:ListQueryLoggingConfigs",
    "route53resolver:ListResolverQueryLogConfigs",
    "s3:GetBucketLocation",
    "s3:GetBucketLogging",
    "s3:GetBucketNotification",
    "s3:ListAllMyBuckets",
    "s3:PutBucketNotification",
    "ssm:GetServiceSetting",
    "ssm:ListCommands",
    "states:DescribeStateMachine",
    "states:ListStateMachines",
    "wafv2:ListLoggingConfigurations"
    
    AWS PermissionDescription
    airflow:ListEnvironmentsList all MWAA environment names.
    airflow:GetEnvironmentGet information about a MWAA environment.
    appsync:ListGraphqlApisList all GraphQL Apis.
    batch:DescribeJobDefinitionsList all Batch job definitions.
    cloudfront:GetDistributionConfigGet the name of the S3 bucket containing CloudFront access logs.
    cloudfront:ListDistributionsList all CloudFront distributions.
    cloudtrail:GetTrailGet Trail logging information.
    cloudtrail:ListTrailsList all Cloudtrail trails.
    codebuild:BatchGetProjectsList all CodeBuild projects.
    codebuild:ListProjectsGet information on CodeBuild projects.
    dms:DescribeReplicationInstancesList all replication instances for DMS.
    ec2:DescribeFlowLogsList all Flow log configurations.
    ec2:DescribeVerifiedAccessInstanceLoggingConfigurationsList all Verified Access instance logging configurations.
    ec2:DescribeVpnConnectionsList all VPN connections.
    ecs:DescribeTaskDefinitionDescribe ECS task definition.
    ecs:ListTaskDefinitionFamiliesList all task definition families.
    elasticloadbalancing:
    DescribeLoadBalancers
    List all load balancers.
    elasticloadbalancing:
    DescribeLoadBalancerAttributes
    Get the name of the S3 bucket containing ELB access logs.
    glue:BatchGetJobsGet information about multiple Glue jobs.
    glue:GetJobGet information about a Glue job.
    glue:GetJobsList all Glue jobs.
    glue:ListJobsList all Glue job names.
    eks:DescribeClusterDescribe an EKS cluster.
    eks:ListClustersList all EKS clusters.
    elasticbeanstalk:DescribeEnvironmentsList all Elastic Beanstalk environments.
    iot:GetV2LoggingOptionsGet IoT V2 logging options.
    lambda:InvokeFunctionInvoke a Lambda function.
    lambda:List*List all Lambda functions.
    lambda:GetPolicyGet the Lambda policy when triggers are to be removed.
    lambda:GetMicrovmImageVersionGet information about a Lambda MicroVM image version.
    logs:PutSubscriptionFilterAdd a Lambda trigger based on CloudWatch Log events.
    logs:DeleteSubscriptionFilterRemove a Lambda trigger based on CloudWatch Log events.
    logs:DescribeLogGroupsDescribe CloudWatch log groups.
    logs:DescribeDeliveriesDescribe CloudWatch log deliveries.
    logs:DescribeDeliverySourcesDescribe CloudWatch log delivery sources.
    logs:DescribeSubscriptionFiltersList the subscription filters for the specified log group.
    logs:GetDeliveryDestinationGet a CloudWatch log delivery destination.
    network-firewall:DescribeLoggingConfigurationGet the logging configuration of a firewall.
    network-firewall:ListFirewallsList all Network Firewall firewalls.
    rds:DescribeDBClustersList all RDS clusters.
    rds:DescribeDBInstancesList all RDS instances.
    redshift:DescribeClustersList all Redshift clusters.
    redshift:DescribeLoggingStatusGet the name of the S3 bucket containing Redshift Logs.
    redshift-serverless:ListNamespacesList all Redshift Serverless namespaces.
    route53:ListQueryLoggingConfigsList all DNS query logging configurations for Route 53.
    route53resolver:ListResolverQueryLogConfigsList all Resolver query logging configurations for Route 53.
    s3:GetBucketLoggingGet the name of the S3 bucket containing S3 access logs.
    s3:GetBucketLocationGet the region of the S3 bucket containing S3 access logs.
    s3:GetBucketNotificationGet existing Lambda trigger configurations.
    s3:ListAllMyBucketsList all S3 buckets.
    s3:PutBucketNotificationAdd or remove a Lambda trigger based on S3 bucket events.
    ssm:GetServiceSettingGet the SSM service setting for customer script log group name.
    ssm:ListCommandsList all SSM commands.
    states:ListStateMachinesList all Step Functions.
    states:DescribeStateMachineGet logging details about a Step Function.
    wafv2:ListLoggingConfigurationsList all logging configurations of the Web Application Firewall.
  3. In the AWS Integration page, select the AWS Account to collect logs from and click on the Log Collection tab.

  4. In the Datadog Forwarder Lambda section, enter the ARN of the Lambda created in the previous section and click Add. The Lambda function appears in the table below with its name, version, and region.

  5. In the Log Autosubscription section, under Log Sources, enable the services from which you’d like to collect logs by toggling them on. To stop collecting logs from a particular service, toggle the log source off.

  6. (Optional) In the Log Source Tag Filters section, you can filter log collection by resource tags for each log source. Select a log source from the dropdown menu and add tags in key:value format to limit which resources’ logs are collected. Note: Resource tags are automatically lowercased to match Datadog platform conventions. Define your tag filters in lowercase to avoid mismatches.

  7. If you have logs across multiple regions, you must create additional Lambda functions in those regions and add them in the Datadog Forwarder Lambda section.

  8. To stop collecting all AWS logs from a specific Lambda function, hover over the Lambda in the table and click the delete icon. All triggers for that function are removed.

  9. Within a few minutes of this initial setup, your AWS Logs appear in the Datadog Log Explorer.

Manually set up triggers

Collecting logs from CloudWatch log group

If you are collecting logs from a CloudWatch log group, configure the trigger to the Datadog Forwarder Lambda function using one of the following methods:

  1. In the AWS console, go to Lambda.
  2. Click Functions and select the Datadog Forwarder.
  3. Click Add trigger and select CloudWatch Logs.
  4. Select the log group from the dropdown menu.
  5. Enter a name for your filter, and optionally specify a filter pattern.
  6. Click Add.
  7. Go to the Datadog Log section to explore any new log events sent to your log group.

For Terraform users, you can provision and manage your triggers using the aws_cloudwatch_log_subscription_filter resource. See sample code below.

data "aws_cloudwatch_log_group" "some_log_group" {
  name = "/some/log/group"
}

resource "aws_lambda_permission" "lambda_permission" {
  action        = "lambda:InvokeFunction"
  function_name = "datadog-forwarder" # this is the default but may be different in your case
  principal     = "logs.amazonaws.com" # or logs.amazonaws.com.cn for China*
  source_arn    = data.aws_cloudwatch_log_group.some_log_group.arn
}

resource "aws_cloudwatch_log_subscription_filter" "datadog_log_subscription_filter" {
  name            = "datadog_log_subscription_filter"
  log_group_name  = <CLOUDWATCH_LOG_GROUP_NAME> # for example, /some/log/group
  destination_arn = <DATADOG_FORWARDER_ARN> # for example,  arn:aws:lambda:us-east-1:123:function:datadog-forwarder
  filter_pattern  = ""
}

* All use of Datadog Services in (or in connection with environments within) mainland China is subject to the disclaimer published in the Restricted Service Locations section on our website.

For AWS CloudFormation users, you can provision and manage your triggers using the CloudFormation AWS::Logs::SubscriptionFilter resource. See sample code below.

The sample code also work for AWS SAM and Serverless Framework. For Serverless Framework, put the code under the resources section within your serverless.yml.

Resources:
  MyLogSubscriptionFilter:
    Type: "AWS::Logs::SubscriptionFilter"
    Properties:
      DestinationArn: "<DATADOG_FORWARDER_ARN>"
      LogGroupName: "<CLOUDWATCH_LOG_GROUP_NAME>"
      FilterPattern: ""

Collecting logs from S3 buckets

If you are collecting logs from an S3 bucket, configure the trigger to the Datadog Forwarder Lambda function using one of the following methods:

  1. Once the Lambda function is installed, manually add a trigger on the S3 bucket that contains your logs in the AWS console:

    Adding trigger
  2. Select the bucket and then follow the AWS instructions:

    Integration Lambda
  3. Set the correct event type on S3 buckets:

    Object Created

Once done, go into your Datadog Log section to start exploring your logs!

For Terraform users, you can provision and manage your triggers using the aws_s3_bucket_notification resource. See the sample code below.

resource "aws_s3_bucket_notification" "my_bucket_notification" {
  bucket = my_bucket
  lambda_function {
    lambda_function_arn = "<DATADOG_FORWARDER_ARN>"
    events              = ["s3:ObjectCreated:*"]
    filter_prefix       = "AWSLogs/"
    filter_suffix       = ".log"
  }
}

For CloudFormation users, you can configure triggers using the CloudFormation NotificationConfiguration for your S3 bucket. See the sample code below.

Resources:
  Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: "<MY_BUCKET>"
      NotificationConfiguration:
        LambdaConfigurations:
        - Event: 's3:ObjectCreated:*'
          Function: "<DATADOG_FORWARDER_ARN>"

Scrubbing and filtering

You can scrub emails or IP address from logs sent by the Lambda function, or define a custom scrubbing rule in the Lambda parameters. You can also exclude or send only those logs that match a specific pattern by using the filtering option.

Further reading