围绕这个话题似乎有很多讨论,但没有什么完全适合我的情况,到目前为止还没有为我解决。
我将我的代码放在 aws codecommit 中。
我已经为我在 AWS 中运行的一个 Ubuntu 实例创建了一个 AMI,并使用这个 AMI 和一个自动扩展组创建了一个启动配置。
我想每个月左右对我的启动配置 AMI 进行基础/修改,以确保 AMI 本身具有最近更新的代码,因此新启动的实例(通过自动缩放)可以在启动时从 codecommit 存储库中提取最新更改 - 从而减少启动时间。
为了实现这一点,我在用户数据 (cloud-init) 脚本中放置了以下代码,并选择了一个 IAM 角色,该角色对所有 EC2 和 codecommit 以及 IAM:Passrole 权限具有完全权限。但是在启动时,脚本总是会抛出错误并且不会拉动更改(我故意在 repo 中保留一个文件以进行测试)
选项1
#!/bin/bash
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
cd /path/to/my/folder/
git remote set-url origin https://git-codecommit.ap-southeast-2.amazonaws.com/v1/repos/reponame
git pull origin master
它抛出以下错误
Error
fatal: $HOME not set
fatal: $HOME not set
fatal: Not a git repository (or any of the parent directories): .git
fatal: could not read Username for 'https://git-codecommit.ap-southeast-2.amazonaws.com': No such device or address
选项 2 -
使用 SSH 也尝试过此选项(尽管尚未尝试对此进行任何进一步的修复)
#!/bin/bash
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
cd /path/to/my/folder/
git remote set-url origin ssh://git-codecommit.ap-southeast-2.amazonaws.com/v1/repos/reponame
git pull origin master
有一个不同的错误 -
Errpr:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
有人可以帮我理解我哪里出错了吗?
谢谢。