Use PYTHONPATH=/var/task to prioritize bundled boto3 in Lambda for new AWS services
Tried calling the DevOps Agent API from Lambda and got UnknownServiceError: Unknown service: 'devops-agent'.
Lambda's managed Python runtime ships with an older boto3 that may not include service models for newly launched services. Even if you bundle a newer boto3 in your deployment package, the managed runtime version takes precedence.
The fix is setting the environment variable PYTHONPATH=/var/task. This puts /var/task (where your deployment package is extracted) at the front of the import path, so your bundled boto3 wins.
# Bundle boto3 in deployment package
pip install boto3 -t .
zip -r function.zip .
# Add environment variable
aws lambda update-function-configuration \
--function-name my-function \
--environment "Variables={PYTHONPATH=/var/task}" \
--region ap-northeast-1This applies to any newly GA'd service, not just DevOps Agent.
