简体   繁体   English

AWS SAM Lambda - 无法导入模块“main”:没有名为“requests”、“msal”的模块。 使用 Azure CI/CD 的管道

[英]AWS SAM Lambda - Unable to import module 'main': No module named 'requests', 'msal' . pipeline using Azure CI/CD

I created a python project using AWS lambda using SAM template.我使用 SAM 模板使用 AWS lambda 创建了一个 python 项目。 Created virtual environment and installed all required modules.创建虚拟环境并安装所有必需的模块。 for example, requests, msal etc. module names mentioned in requirements.txt file and installed.例如,requests、msal 等。 requirements.txt 文件中提及并安装的模块名称。 I am able to build, debug and deploy using sam command from my vscode.我能够使用我的 vscode 中的 sam 命令进行构建、调试和部署。 for example.例如。 sam build, sam local invoke, sam deploy --guided command. sam 构建、sam 本地调用、sam 部署 --guided 命令。

As a project repo uses Azure devOps.作为项目回购使用 Azure devOps。 Now, I created project pipeline and deployed to AWS successfully.现在,我创建了项目管道并成功部署到 AWS。

part of pipeline script -(install dependencies)管道脚本的一部分-(安装依赖项)

  • script: |脚本: | python -m pip install --upgrade pip python -m pip 安装--升级 pip
    pip install -r src/requirements.txt displayName: 'Install dependencies' pip install -r src/requirements.txt displayName: '安装依赖项'

When I tested lambda function from AWS console or call url, It show the following error as per cloud watch log.当我从 AWS 控制台测试 lambda function 或调用 url 时,根据云监视日志显示以下错误。 It shows module not found "request" and "msal".它显示模块未找到“请求”和“msal”。 for example.例如。 ERROR: Function Logs [ERROR] Runtime.ImportModuleError: Unable to import module 'main': No module named 'requests'错误:Function 日志 [错误] Runtime.ImportModuleError:无法导入模块“main”:没有名为“requests”的模块

python 3.9 python 3.9

AWS SAM AWS SAM

Azure devOps repo Azure 开发运营回购

VScode VScode

I am unable to figure out the issue.我无法弄清楚这个问题。 I spent time but did not find the cause.我花了时间但没有找到原因。 I am stuck.我卡住了。 Please give me hints/ideas/solution.请给我提示/想法/解决方案。

Lambda dependencies have to be installed at the root folder. Lambda 必须在根文件夹中安装依赖项。 See the "Deployment package with dependencies" Section, Step 5 in this guide .请参阅本指南中的“使用依赖项部署 package”部分的第 5 步。

Create a deployment package with the installed library at the root.在根目录下使用已安装的库创建部署 package。

You can do so by going to the root directory, then issue a pip install with a -t (target) flag and specifying the current directory with a dot .为此,您可以转到根目录,然后使用-t (目标)标志发出pip install并使用点指定当前目录. . .

pip install -r src/requirements.txt -t.

This is the following answer.这是下面的答案。 It might help someone.它可能会帮助某人。

- task: AWSShellScript@1
  displayName: 'Build'
  inputs:
    awsCredentials: AwsServiceConnection
    regionName: 'us-east-1'
    scriptType: 'inline'
    inlineScript: |
      sam build --debug \
      --template-file template.yaml

- task: AWSShellScript@1
  displayName: 'Package'
  inputs:
    awsCredentials: AwsServiceConnection
    regionName: us-east-1
    scriptType: 'inline'
    inlineScript: |
      sam package  --resolve-s3  --output-template-file packaged.yaml

- task: AWSShellScript@1
  displayName: 'Deploy Infrastructure'
  inputs:
      awsCredentials: AwsServiceConnection
      regionName: 'us-east-1'
      scriptType: "inline"
      inlineScript: |
        sam deploy \
        --template-file packaged.yaml \
        --no-confirm-changeset \
        --no-fail-on-empty-changeset \
        --capabilities CAPABILITY_IAM  \
        --stack-name sam-test-stack \
        --resolve-s3 \
        --s3-prefix sam-test-stack

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何构建、package 和部署 AWS SAM lambda function 从 azure Devops CI/CD 管道到 AWS - how to build, package and deploy AWS SAM lambda function of python from azure Devops CI/CD pipeline to AWS aws lambda 无法导入模块“lambda_function”:没有名为“requests”的模块 - aws lambda Unable to import module 'lambda_function': No module named 'requests' 无法导入模块“app”:使用 Chalice 在 Aws Lambda 中没有名为“app”的模块 - Unable to import module 'app': No module named 'app' in Aws Lambda using Chalice AWS Lambda 层无法导入模块“lambda_function”:没有名为“pyarrow.lib”的模块 - AWS Lambda Layer Unable to import module 'lambda_function': No module named 'pyarrow.lib' AWS Lambda 导入错误:无法导入模块“lambda_function”:没有名为“confluent_kafka.cimpl”的模块 - AWS Lambda importError: Unable to import module 'lambda_function': No module named 'confluent_kafka.cimpl 无法导入模块“lambda_function”:没有名为“psycopg2._psycopg aws lambda 函数”的模块 - Unable to import module 'lambda_function': No module named 'psycopg2._psycopg aws lambda function AWS Lambda 导入 psycopg2 - 无法导入模块“app”:没有名为“psycopg2._psycopg”的模块 - AWS Lambda Importing psycopg2 - Unable to import module 'app': No module named 'psycopg2._psycopg 无法导入模块“lambda_function”:没有名为“aws_xray_sdk”的模块 - Unable to import module 'lambda_function': No module named 'aws_xray_sdk' 无法导入模块“lambda_function”:没有名为“pymongo”的模块 - Unable to import module 'lambda_function': No module named 'pymongo' 无法在 AWS Lambda 中导入 numpy 1.19.1 没有名为“numpy.core._multiarray_umath”的模块 - Unable to import numpy 1.19.1 in AWS Lambda No module named 'numpy.core._multiarray_umath'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM