2017-10-10 75 views
0

我是GIT的新手,是否有辦法拉取保存用戶數據的GIT腳本以通過CLI配置AWS EC2實例?aws用戶數據的git bash腳本

aws ec2 run-instances --image-id ami-cd0f5cb6 --count 1 --instance-type t2.micro 
--key-name ciServer --subnet-id subnet-2f31275b --associate-public-ip-address 
--security-group-ids sg-762a5006 --block-device-mappings '[{"DeviceName":"/dev/sda1","Ebs":{"VolumeSize":20}}]' 
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=My New Server}]' 
--user-data [email protected]/myUserDatarepo.git 
+0

什麼是AMI的基礎操作系統? Windows還是Linux? – strongjz

+0

這是一個Ubuntu服務器16.04。如果您有任何問題,請告訴我! – Lgalan90

回答

0

創建一個安裝git的bash腳本,然後將repo下載到您需要的地方。使這個腳本成爲你的用戶數據腳本。您必須獲得git repo到userdata腳本/服務器的憑據。你可以install the AWS cli並從一個受保護的s3存儲桶中取得憑證,或者使用類似consul or Hashicorp vault的東西來提取祕密。我通常使用有權訪問的git倉庫一個ssh key file,一個S3存儲是唯一的IAM instance role你要置備服務器訪問,是encrypted with Server side encryption.

其他問題,討論這個問題,以及

Is it secure to store EC2 User-Data shell scripts in a private S3 bucket?

How can I (securely) download a private S3 asset onto a new EC2 instance with cloudinit?

通過AWS系統管理器參數存儲新服務

https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-paramstore-about.html

+0

這太好了。我想現在你提到它,去S3航線可能會更安全,因爲它似乎目前最有意義。感謝您的迴應! – Lgalan90