安裝 AWS CLI
1. 下載 AWS CLI
[ec2-user@ip-172-31-28-226 ~]$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 57.3M 100 57.3M 0 0 260M 0 --:--:-- --:--:-- --:--:-- 261M
2. 解壓縮下載檔案
[ec2-user@ip-172-31-28-226 ~]$ unzip awscliv2.zip
3. 安裝 AWS CLI
[ec2-user@ip-172-31-28-226 ~]$ sudo ./aws/install You can now run: /usr/local/bin/aws --version
4. 驗證安裝結果
[ec2-user@ip-172-31-28-226 ~]$ aws --version aws-cli/2.15.19 Python/3.11.6 Linux/6.1.75-99.163.amzn2023.x86_64 exe/x86_64.amzn.2023 prompt/off
5. 配置 AWS CLI
- AWS Access Key ID 和 AWS Secret Access Key:你可以在 AWS 管理控制台的 IAM 服務中建立一個新的使用者或使用現有的使用者憑證。- Default region name:輸入你想要操作的 AWS 區域的代碼,例如
us-east-1
。- Default output format:輸入你偏好的輸出格式,常見的選項包括
json
、text
和 table
。[ec2-user@ip-172-31-28-226 ~]$ aws configure AWS Access Key ID [None]: AKIASHY4YDRZJLQSTQNU AWS Secret Access Key [None]: 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 Default region name [None]: us-east-1 Default output format [None]: json
透過 AWS CLI 進行 S3 操作
1. Create S3 bucket
[ec2-user@ip-172-31-28-226 ~]$ aws s3 mb s3://albert-buckert-154142252146 --region us-east-1 make_bucket: albert-buckert-154142252146
2. List S3 bucket
[ec2-user@ip-172-31-28-226 ~]$ aws s3 ls 2024-02-13 10:02:24 albert-buckert-154142252146
3. Create a file and upload it to S3 bucket
[ec2-user@ip-172-31-28-226 ~]$ echo "Hello World" > hello.txt [ec2-user@ip-172-31-28-226 ~]$ cat hello.txt Hello World [ec2-user@ip-172-31-28-226 ~]$ aws s3 cp hello.txt s3://albert-buckert-154142252146 upload: ./hello.txt to s3://albert-buckert-154142252146/hello.txt
No comments:
Post a Comment