python - 无法在AWS lambda中使用gitpython

标签 python python-2.7 amazon-web-services aws-lambda gitpython

我一直在尝试在 aws lambda 中使用 gitpython 包。我使用的是python2.7环境。我使用 this 捆绑了 gitpython连同我的 python 代码一起打包成 zip 文件并上传。

import json
import git

def lambda_function(event, context):
    repo="https://github.com/abc/xyz.git"
    git.Git().clone(repo)

它说

Cmd('git') not found due to: OSError('[Errno 2] No such file or directory')
  cmdline: git clone https://github.com/abc/xyz.git: GitCommandNotFound
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 13, in lambda_function
    git.Git().clone("https://github.com/abc/xyz.git")
  File "/var/task/git/cmd.py", line 425, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/var/task/git/cmd.py", line 877, in _call_process
    return self.execute(call, **exec_kwargs)
  File "/var/task/git/cmd.py", line 602, in execute
    raise GitCommandNotFound(command, err)
GitCommandNotFound: Cmd('git') not found due to: OSError('[Errno 2] No such file or directory')
  cmdline: git clone https://github.com/abc/xyz.git

我认为这个错误是因为 lambda 机器中没有 git 造成的!我该如何使用这个?

最佳答案

有一个特殊的 lambda 层,它将 git 引入 lambda 函数。 检查thisthis引用。基本上,

Click on Layers and choose "Add a layer", and "Provide a layer version ARN" and enter the following ARN (replace us-east-1 with the region of your Lambda):

arn:aws:lambda:us-east-1:553035198032:layer:git:6

关于python - 无法在AWS lambda中使用gitpython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43783270/

相关文章:

python - 比较将 numpy 数组写入磁盘的两种方法

python - 如何在 Python 中对数据数组执行我的函数?

python - Python 中的常用日志记录模块

python - 从 A 点到 B 点的 Pygame 子弹运动

python - 如何防止 AWS EC2 服务器无限期运行?

Python 数据包嗅探/数据包捕获 - pcapy 不捕获数据包

python - 将字典存储在文件中供以后检索

python - Python 中的列表和迭代器有什么区别?

amazon-web-services - 是否可以有 "no-op"IAM 策略?

amazon-web-services - 当您的实例位于 ELB 后面时,您如何为 AWS 建立维护页面?