安裝 AWS CLI

https://docs.aws.amazon.com/zh_cn/cli/latest/userguide/installing.html

windows

  1. download python
  2. 設定 python 環境變數
1
2
python → C:\Users\Scott\AppData\Local\Programs\Python\Python37
pip → C:\Users\Scott\AppData\Local\Programs\Python\Python37\Scripts
  1. Install aws-cli
1
pip install --user --upgrade awscli

安裝完成時會顯示套件安裝路徑
將此路徑設定到環境變數

1
2
3
4
C:\Users\Scott>pip install --user --upgrade awscli
Requirement already up-to-date: awscli in c:\users\scott\appdata\roaming\python\python37\site-packages (1.15.66)
Requirement not upgraded as not directly required: botocore==1.10.65 in 
...
  1. 安裝成功訊息
1
2
C:\Users\Scott>aws --version
aws-cli/1.15.66 Python/3.7.0 Windows/10 botocore/1.10.65
  1. Uninstall aws-cli
1
pip uninstall awscli

Ubuntu

  1. Install aws-cli
1
2
3
# AWS CLI requires python-pip, python is installed by default
sudo apt-get install -y python3  python3-pip
pip3 install awscli
  1. run aws s3
1
2
3
4
5
6
7
aws configure set aws_access_key_id $ACCESS_KEY
aws configure set aws_secret_access_key $SECRET_KEY
aws configure set default.region ap-southeast-1
aws configure set default.outupt json

uname -a > ~/ec2-info.txt
aws s3 cp ~/ec2-info.txt s3://$BUCKET_NAME/ec2-info.txt

EC2機器需安裝 CodeDeploy agent 和設定 IAM

  1. https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-ubuntu.html

  2. IAM roles參考 : CodeDeploySampleStack

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
    "Statement": [
        {
            "Action": [
                "autoscaling:Describe*",
                "cloudformation:Describe*",
                "cloudformation:GetTemplate",
                "s3:Get*"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}