I've been trying to use the gitpython package in aws lambda. I've used python2.7 environment. I bundled up gitpython using this along with my python code into a zip file and uploaded.
import json
import git
def lambda_function(event, context):
repo="https://github.com/abc/xyz.git"
git.Git().clone(repo)
It says
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
I think this error is caused because the lambda machine dosen't have git in it! How can I use this?
There is a special lambda layer that brings in git
to lambda functions.
Check this and this reference. Basically,
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