在AWS Lambda中运行'git' [英] Running 'git' in AWS lambda
问题描述
我正在尝试在AWS Lambda中运行git来签出存储库.
I am trying to run git in AWS lambda to make a checkout of a repository.
这是我的设置:
- 我正在使用nodejs 4.3
- 我没有使用 nodegit ,因为我想使用"--depth = 1"参数, nodegit不支持.
- 我已从正确的AWS AMI复制了git和ssh可执行文件,然后将其放置在我上传的zip的"bin"文件夹中.
- 我通过以下方式将它们添加到PATH:
- I am using nodejs 4.3
- I am not using nodegit because I want to use the "--depth=1" parameter, which is not supported by nodegit.
- I have copied the git and ssh executable from the correct AWS AMI and placed then in a "bin" folder in the zip I upload.
- I added them to PATH with this:
->
process.env['PATH'] = process.env['LAMBDA_TASK_ROOT'] + "/bin:" + process.env['PATH'];
输入变量设置如下:
"checkout_url": "git@...",
"branch":"master
现在我这样做(为简便起见,我在其中混入了一些伪代码):
Now I do this (for brevity, I mixed some pseudo-code in):
downloadDeploymentKeyFromS3Sync('/tmp/ssh_key');
fs.chmodSync("/tmp/ssh_key",0600);
process.env['GIT_SSH_COMMAND'] = 'ssh -o StrictHostKeyChecking=no -i /tmp/ssh_key';
execSync("git clone --depth=1 " + checkout_url + " --branch " + branch + " /tmp/checkout");
使用 lambda-local 在我的本地计算机上运行此程序,一切正常!但是,当我在lambda中对其进行测试时,我得到了:
Running this in my local computer using lambda-local everything works fine! But when I test it in lambda, I get:
warning: templates not found /usr/share/git-core/templates
PRIV_END: seteuid: Operation not permitted\r
fatal: Could not read from remote repository.
- 警告"当然是因为我没有安装git而是只复制了二进制文件.这是为什么它不起作用的原因吗?
- 为什么git需要"setuid"?我读到在某些shell中出于安全原因将其禁用.因此,它在lambda中不起作用是有道理的.可以以某种方式指示git不要需要"此命令吗?
推荐答案
Yep, this is definitely possible, I've created a Lambda Layer that achieves just this. No need to mess with any env variables, should work out of the box:
https://github.com/lambci/git-lambda-layer
如自述文件所述,您要做的就是添加具有以下ARN的图层:
As stated in the README, all you need to do is add a layer with the following ARN:
arn:aws:lambda:<region>:553035198032:layer:git:<version>
(替换<region>
和<version>
,检查自述文件以获取最新版本)
(replace <region>
and <version>
, check README for latest version)
这篇关于在AWS Lambda中运行'git'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!