DataDog / datadog-cloudformation-macro

CloudFormation Macros by Datadog
Apache License 2.0
14 stars 22 forks source link

Skip handling of container image lambda functions #119

Closed duncanpharvey closed 8 months ago

duncanpharvey commented 8 months ago

What does this PR do?

Skip handling of container image Lambda functions. Lambda functions packaged into container images are instrumented with Datadog differently than Lambda functions packaged into a zip. The CloudFormation Macro should not make any changes to these container image Lambda functions.

Motivation

https://github.com/DataDog/datadog-cloudformation-macro/issues/108

Testing Guidelines

Created a SAM template with a zip Lambda function and container image Lambda function. Verified that (1) the zip Lambda function is instrumented with the CloudFormation Macro and sends metrics, logs, and traces to Datadog and (2) the container image Lambda function is unaffected by the CloudFormation Macro and sends metrics, logs, and traces to Datadog.

template.yaml

AWSTemplateFormatVersion: "2010-09-09"
Transform:
  - AWS::Serverless-2016-10-31
  - Name: DatadogServerlessTest
    Parameters:
      stackName: !Ref "AWS::StackName"
      apiKey: <redacted>
      pythonLayerVersion: "87"
      extensionLayerVersion: "52"

Globals:
  Function:
    Timeout: 10
    MemorySize: 256
    Architectures:
      - x86_64

Resources:
  HelloWorldFunctionContainer:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      Environment:
        Variables:
          DD_LAMBDA_HANDLER: app.lambda_handler
          DD_API_KEY: <redacted>
          DD_SITE: datadoghq.com
          DD_TRACE_ENABLED: true
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./hello_world
      DockerTag: python3.9-v1
  HelloWorldFunctionZip:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.9

Dockerfile

FROM public.ecr.aws/lambda/python:3.9

COPY requirements.txt ./
RUN python3.9 -m pip install -r requirements.txt -t .

COPY app.py ./

COPY --from=public.ecr.aws/datadog/lambda-extension:latest /opt/extensions/ /opt/extensions

CMD ["datadog_lambda.handler.handler"]

Additional Notes

Types of changes

Check all that apply

codecov-commenter commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (443c298) 84.62% compared to head (fb7f505) 84.70%.

:exclamation: Current head fb7f505 differs from pull request most recent head cf9e13a. Consider uploading reports for the commit cf9e13a to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #119 +/- ## ========================================== + Coverage 84.62% 84.70% +0.07% ========================================== Files 8 8 Lines 631 634 +3 Branches 158 159 +1 ========================================== + Hits 534 537 +3 Misses 85 85 Partials 12 12 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.