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?
-
I think, the answer will help to you stackoverflow.com/questions/10804744/…user5639219– user56392192017年05月04日 12:52:02 +00:00Commented May 4, 2017 at 12:52
-
It says the instance lacks git. If so, how can we install git in aws lambda?Neeraj– Neeraj2017年05月04日 13:02:23 +00:00Commented May 4, 2017 at 13:02
-
1I'm pretty sure this is bundling issue and not related to git not being installed but you can validate that by launching AMI amzn-ami-hvm-2016年03月3日.x86_64-gp2 which is what Lambda is using. If git is in that AMI then the problem is definitely not git, if it's not then you'll need to include git in your bundle or use pygit2. More into on the lambda execution environment here: docs.aws.amazon.com/lambda/latest/dg/…alanwill– alanwill2017年05月07日 17:15:00 +00:00Commented May 7, 2017 at 17:15
-
how can you clone private git repo using ssh in lambda?Ashish Sharma– Ashish Sharma2022年10月13日 16:51:07 +00:00Commented Oct 13, 2022 at 16:51
2 Answers 2
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
Comments
I faced this issue and finally got a very easy soultion. All you have to do is just add a layer in your lambda function. No need to change any thing in the code.
You can add the lambda layer by providing arn something like this where region will be changed to your region and for version you can refer this link.
https://github.com/lambci/git-lambda-layer
arn:aws:lambda:region:553035198032:layer:git:version
2 Comments
Explore related questions
See similar questions with these tags.