Closed cscetbon closed 1 year ago
Hi @cscetbon, thanks for opening the issue. Reading the newer posts in your thread on the Datadog Slack with AJ, it appears that because CFN macros operate on stacks in AWS there's not a straightforward way to apply a macro transform locally for aws sam invoke. It looks like the workarounds AJ mentioned in the thread are currently the best option for this
Expected Behavior
sam local invoke
should work and not raise an exception about not finding ddtrace moduleActual Behavior
sam local invoke
fails because the lambda cannot find ddtrace moduleSteps to Reproduce the Problem
sam init
template.yaml
content:Parameters: StageName: Type: String Default: dev
Resources: MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: src/ Handler: app.lambda_handler Runtime: python3.8
from ddtrace import tracer
@tracer.wrap() def lambda_handler(event, context): print('Hello')
$ sam build Building codeuri: /Users/cscetbon/Downloads/test/src runtime: python3.8 metadata: {} architecture: x86_64 functions: MyFunction requirements.txt file not found. Continuing the build without dependencies. Running PythonPipBuilder:CopySource
Build Succeeded
Built Artifacts : .aws-sam/build Built Template : .aws-sam/build/template.yaml
Commands you can use next
[] Validate SAM template: sam validate [] Invoke Function: sam local invoke [] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch [] Deploy: sam deploy --guided
$ sam local invoke MyFunction Invoking app.lambda_handler (python3.8) Local image is up-to-date Using local image: public.ecr.aws/lambda/python:3.8-rapid-x86_64.
Mounting /Users/cscetbon/Downloads/test/.aws-sam/build/MyFunction as /var/task:ro,delegated, inside runtime container START RequestId: 02b5c265-97ca-46bf-ae62-7791b34ad305 Version: $LATEST Traceback (most recent call last): Unable to import module 'app': No module named 'ddtrace' END RequestId: 02b5c265-97ca-46bf-ae62-7791b34ad305 REPORT RequestId: 02b5c265-97ca-46bf-ae62-7791b34ad305 Init Duration: 1.09 ms Duration: 601.14 ms Billed Duration: 602 ms Memory Size: 128 MB Max Memory Used: 128 MB {"errorMessage": "Unable to import module 'app': No module named 'ddtrace'", "errorType": "Runtime.ImportModuleError", "stackTrace": []}%