Reputation: 11
I am trying to debug a Lambda locally in PyCharm with SAM-cli.
For this Lambda to work, I have a layer linked to it which works fine. Now, if I set a breakpoint in the Lambda code, everything is fine, the execution is stopped at the breakpoint. However, if I set a breakpoint in the layer code, it is not taken into account.
I think the problem came from the mapping of the files from the layer cause when the command sam local invoke xxxx
is called, I get a warning saying pydev debugger: warning: trying to add breakpoint to file that does not exist: /home/arobin/Documents/projects/edfred-distributed-cicd/shared/services/publishers/sensorbox_publisher.py (will have no effect)
.
Here is my template.yml file :
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
shared:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: ./shared
Metadata:
BuildMethod: python3.6
lamdistributeddatapublishersceptreprd:
Type: AWS::Serverless::Function
Properties:
Handler: publisher/index.run
Runtime: python3.6
CodeUri: ./data-pipe
Layers:
- !Ref shared
Description: ''
MemorySize: 1024
Timeout: 900
Role: >-
arn:aws:iam::045217667925:role/edfred-platformdev-distributeddata-role-lambda-sceptre-prd
VpcConfig:
SecurityGroupIds:
- sg-0aa5f8f912ce37ff3
SubnetIds:
- subnet-e2b569aa
- subnet-2f3b3374
Environment:
Variables:
SENSORBOX_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-sensorbox-publisher-queue-sceptre-prd
IO_MEASURE_ON_DEMAND_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-io-measure-on-demand-publisher-queue-sceptre-prd
MIP_FTP_FOLDER_WEBBOX: webbox-prd
ACK_BUCKET: edfred-edfre-prd-s3-eu-west-1-distributed-acknowledgment
ALARM_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-alarm-publisher-queue-sceptre-prd
HARVEST_BUCKET: edfred-edfre-prd-s3-eu-west-1-distributed-harvest
RDS_DB_PORT: '5432'
METER_ON_DEMAND_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-meter-on-demand-publisher-queue-sceptre-prd
INI_BUCKET: edfred-edfre-prd-s3-eu-west-1-distributed-ini
TOR_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-tor-publisher-queue-sceptre-prd
MIP_FTP_URL: mip.photon-tec.fr
MIP_FTP_DONE_PREFIX: done
LOG_LEVEL: '20'
ADM_DB_PASSWORD_SSM_PARAMETER_NAME: /Distributed/Aurora/Password
RDS_DB_HOST: >-
edfred-sceptre-prd-eu-west-1-distributedapi-instance.ccpyauuephzf.eu-west-1.rds.amazonaws.com
MAPPING_VARS_BUCKET: edfred-edfre-prd-s3-eu-west-1-distributed-mapping-vars
SENSORBOX_ON_DEMAND_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-sensorbox-on-demand-publisher-queue-sceptre-prd
GATEWAY_COMMUNICATION_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-gateway-communication-queue-sceptre-prd
ADM_DB_PORT: '5432'
MIP_FTP_DOWNLOAD_MAX_FILES: '100'
RDS_DB_USER: enrs
MIP_FTP_FOLDER_WEBDYN: webdyn-prd
RDS_DB_NAME: distributedapi_db
INVERTER_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-inverter-publisher-queue-sceptre-prd
MIP_FTP_USER: admin-mip2-prd
RDS_DB_PASSWORD_SSM_PARAMETER_NAME: /Aurora/Enrs/Password
ADM_DB_HOST: >-
edfred-sceptre-prd-eu-west-1-distributedadm-instance.ccpyauuephzf.eu-west-1.rds.amazonaws.com
IO_MEASURE_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-io-measure-publisher-queue-sceptre-prd
ADM_DB_USER: db_adm_user
CURATED_BUCKET: edfred-edfre-prd-s3-eu-west-1-distributed-curated
ADM_DB_NAME: distributedadm_db
METER_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-meter-publisher-queue-sceptre-prd
SOLAREDGE_API_KEY_SSM_PARAMETER_NAME: solaredge
GATEWAYS_BUCKET: edfred-edfre-prd-s3-eu-west-1-distributed-gateways
PRECURATED_BUCKET: edfred-edfre-prd-s3-eu-west-1-distributed-pre-curated
MIP_FTP_PASSWORD_SSM_PARAMETER: /distributed/ftp/password
MIP_FTP_TOP_DIR: /
STAGE: sceptre-prd
INVERTER_ON_DEMAND_PUBLISHER_QUEUE: >-
https://sqs.eu-west-1.amazonaws.com/045217667925/sqs-inverter-on-demand-publisher-queue-sceptre-prd
Upvotes: 1
Views: 1699
Reputation: 11
Here are the logs when building with SAM :
docker ps
/home/arobin/.pyenv/shims/sam build lamdistributeddatapublishersceptreprd --template /home/arobin/Documents/projects/edfred-distributed-cicd/template.yaml --build-dir /home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build --use-container
Starting Build inside a container
Building layer 'shared'
Fetching public.ecr.aws/sam/build-python3.6:latest-x86_64 Docker container image......
Mounting /home/arobin/Documents/projects/edfred-distributed-cicd/shared as /tmp/samcli/source:ro,delegated inside runtime container
requirements.txt file not found. Continuing the build without dependencies.
Running PythonPipBuilder:CopySource
Building codeuri: /home/arobin/Documents/projects/edfred-distributed-cicd/data-pipe runtime: python3.6 metadata: {} architecture: x86_64 functions: ['lamdistributeddatapublishersceptreprd']
Fetching public.ecr.aws/sam/build-python3.6:latest-x86_64 Docker container image...
Mounting /home/arobin/Documents/projects/edfred-distributed-cicd/data-pipe as /tmp/samcli/source:ro,delegated inside runtime container
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch
[*] Deploy: sam deploy --guided
Running PythonPipBuilder:ResolveDependencies
Running PythonPipBuilder:CopySource
And here when invoking :
/home/arobin/.pyenv/shims/sam local invoke lamdistributeddatapublishersceptreprd --template /home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/template.yaml --event "/tmp/[Local] publisher-event4.json" --debugger-path /home/arobin/pycharm/pycharm-2021.3.1/plugins/python/helpers/pydev --debug-args "-u /tmp/lambci_debug_files/pydevd.py --multiprocess --port 41557 --file" --debug-port 41557 --debug
2022-03-03 17:59:53,208 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-03-03 17:59:53,208 | Using config file: samconfig.toml, config environment: default
2022-03-03 17:59:53,208 | Expand command line arguments to:
2022-03-03 17:59:53,209 | --template_file=/home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/template.yaml --event=/tmp/[Local] publisher-event4.json --debugger_path=/home/arobin/pycharm/pycharm-2021.3.1/plugins/python/helpers/pydev --debug_args=-u /tmp/lambci_debug_files/pydevd.py --multiprocess --port 41557 --file --debug_port=(41557,) --function_logical_id=lamdistributeddatapublishersceptreprd --no_event --layer_cache_basedir=/home/arobin/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2022-03-03 17:59:53,209 | local invoke command is called
2022-03-03 17:59:53,220 | No Parameters detected in the template
2022-03-03 17:59:53,236 | Sam customer defined id is more priority than other IDs. Customer defined id for resource shared is shared
2022-03-03 17:59:53,236 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lamdistributeddatapublishersceptreprd is lamdistributeddatapublishersceptreprd
2022-03-03 17:59:53,237 | 2 stacks found in the template
2022-03-03 17:59:53,237 | No Parameters detected in the template
2022-03-03 17:59:53,249 | Sam customer defined id is more priority than other IDs. Customer defined id for resource shared is shared
2022-03-03 17:59:53,249 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lamdistributeddatapublishersceptreprd is lamdistributeddatapublishersceptreprd
2022-03-03 17:59:53,249 | 2 resources found in the stack
2022-03-03 17:59:53,250 | No Parameters detected in the template
2022-03-03 17:59:53,263 | Sam customer defined id is more priority than other IDs. Customer defined id for resource shared is shared
2022-03-03 17:59:53,263 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lamdistributeddatapublishersceptreprd is lamdistributeddatapublishersceptreprd
2022-03-03 17:59:53,264 | No Parameters detected in the template
2022-03-03 17:59:53,276 | Sam customer defined id is more priority than other IDs. Customer defined id for resource shared is shared
2022-03-03 17:59:53,276 | Sam customer defined id is more priority than other IDs. Customer defined id for resource lamdistributeddatapublishersceptreprd is lamdistributeddatapublishersceptreprd
2022-03-03 17:59:53,276 | --base-dir is not presented, adjusting uri shared relative to /home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/template.yaml
2022-03-03 17:59:53,276 | Found Serverless function with name='lamdistributeddatapublishersceptreprd' and CodeUri='lamdistributeddatapublishersceptreprd'
2022-03-03 17:59:53,276 | --base-dir is not presented, adjusting uri lamdistributeddatapublishersceptreprd relative to /home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/template.yaml
2022-03-03 17:59:53,284 | Found one Lambda function with name 'lamdistributeddatapublishersceptreprd'
2022-03-03 17:59:53,284 | Invoking publisher/index.run (python3.6)
2022-03-03 17:59:53,284 | Environment variables overrides data is standard format
2022-03-03 17:59:53,284 | Loading AWS credentials from session with profile 'None'
2022-03-03 17:59:53,297 | Resolving code path. Cwd=/home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build, CodeUri=/home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/lamdistributeddatapublishersceptreprd
2022-03-03 17:59:53,297 | Resolved absolute path to code is /home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/lamdistributeddatapublishersceptreprd
2022-03-03 17:59:53,298 | Code /home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/lamdistributeddatapublishersceptreprd is not a zip/jar file
2022-03-03 17:59:53,298 | Code /home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/shared is not a zip/jar file
2022-03-03 17:59:53,298 | shared is a local Layer in the template
2022-03-03 17:59:53,298 | Resolving code path. Cwd=/home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build, CodeUri=/home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/shared
Building image........................
2022-03-03 17:59:55,007 | Skip pulling image and use local one: samcli/lambda:python3.6-x86_64-a4d26868017c0ccffe2efe509.
2022-03-03 17:59:55,008 | Mounting /home/arobin/Documents/projects/edfred-distributed-cicd/.aws-sam/build/lamdistributeddatapublishersceptreprd as /var/task:ro,delegated inside runtime container
2022-03-03 17:59:55,799 | Setting up SIGTERM interrupt handler
START RequestId: 10cbdd7e-2878-4fb8-b548-4aa8f0426b29 Version: $LATEST
pydev debugger: warning: trying to add breakpoint to file that does not exist: /home/arobin/Documents/projects/edfred-distributed-cicd/shared/services/publishers/sensorbox_publisher.py (will have no effect)
Upvotes: 0