在使用打包程序构建 AMI 时,我想从 CodeCommit 克隆我的 FreeTier git 存储库。这是非常具有挑战性的并且记录不充分。
问问题
418 次
1 回答
1
这最终对我有用。这是 Ubuntu 16.04 hvm:ebs 作为基础映像,因为它将安装现代且正常运行的 git 和 awscli。14.04 有很多问题,到最后都不值得整理。
{
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
"builders": [{
"type": "amazon-ebs",
"name": "aws",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"iam_instance_profile": "packer",
"region": "us-east-1",
"source_ami": "ami-840910ee",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "myproject {{timestamp}}"
}],
"provisioners": [{
"type": "shell",
"inline": [
"sleep 30",
"sudo apt-get update",
"sudo apt-get upgrade -y",
"sudo apt-get install -y git awscli python-virtualenv",
"sudo install -o ubuntu -g ubuntu -m 755 -d /opt/scratch",
"virtualenv /opt/scratch/venv",
"git config --global credential.helper '!aws codecommit credential-helper $@'",
"git config --global credential.UseHttpPath true",
"git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/myproject /opt/scratch/venv/src/myproject",
"/opt/scratch/venv/bin/pip install -r /opt/scratch/venv/src/myproject/requirements.txt"
]
}]
}
在 IAM 控制台中,打包程序将使用的用户需要iam:PassRole
策略才能使用该iam_instance_profile
指令。
同样在 IAM 控制台中,您需要为 EC2 创建一个角色,并为其提供AWSCodeCommitReadOnly
策略。
请注意,--profile default
credential.helper 中缺少该内容,这是故意的。使用角色没有~/.aws/credential
文件来保存默认配置文件。而是aws-cli
使用分配给实例的角色,这允许它从 CodeCommit 克隆
于 2016-05-07T03:12:19.127 回答