首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法用AWS SAM构建python应用程序

无法用AWS SAM构建python应用程序
EN

Stack Overflow用户
提问于 2021-07-19 10:03:11
回答 2查看 2K关注 0票数 0

我正在尝试从AWS构建和运行示例python应用程序。我刚刚安装了python,下面是命令行提供的..。

代码语言:javascript
复制
D:\Udemy Work>python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

D:\Udemy Work>pip -V
pip 21.1.3 from c:\users\user\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)

当我运行sam build时,会得到以下错误

代码语言:javascript
复制
Build Failed
Error: PythonPipBuilder:Validation - Binary validation failed for python, searched for python in following locations  : ['C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python39\\python.EXE', 'C:\\Users\\User\\AppData\\Local\\Microsoft\\WindowsApps\\python.EXE'] which did not satisfy constraints for runtime: python3.8. Do you have python for runtime: python3.8 on your PATH?

下面是我的代码

template.yaml

代码语言:javascript
复制
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  python-test

  Sample SAM Template for python-test

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.8
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get

app.py

代码语言:javascript
复制
AWSTemplateFormatVersion: '2010-09-09'
    Transform: AWS::Serverless-2016-10-31
    Description: >
      python-test
    
      Sample SAM Template for python-test
    
    # More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
    Globals:
      Function:
        Timeout: 3
    
    Resources:
      HelloWorldFunction:
        Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
        Properties:
          CodeUri: hello_world/
          Handler: app.lambda_handler
          Runtime: python3.9
          Events:
            HelloWorld:
              Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
              Properties:
                Path: /hello
                Method: get

如果在yaml中更改运行时,则会得到以下错误

代码语言:javascript
复制
PS D:\Udemy Work\awslambda\python-test> sam build
Building codeuri: D:\Udemy Work\awslambda\python-test\hello_world runtime: python3.9 metadata: {} functions: ['HelloWorldFunction']

Build Failed
Error: 'python3.9' runtime is not supported

这里的解决方案是什么?

EN

回答 2

Stack Overflow用户

发布于 2021-07-19 10:05:59

python3.9不支持的。支持的运行时列出了这里,您可以使用的最新的python是python3.8

山姆支座码头通过--use-container标志。因此,您可以为您想要的SAM版本使用它来构建您的包。

票数 1
EN

Stack Overflow用户

发布于 2022-02-01 19:50:00

还要确保将SAM更新为支持Python3.9运行时的最新版本。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68438620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档