# EC2 檔案遷移到 S3 ###### tags: `aws` `s3` `ec2-migrate-s3` 1. 安裝 <a href="https://docs.aws.amazon.com/zh_tw/cli/latest/userguide/install-cliv2.html">AWS CLI</a>,建議安裝 v2 版本 <br /> 2. 設定 aws-cli <a href="https://docs.aws.amazon.com/zh_tw/cli/latest/userguide/cli-configure-quickstart.html">官方文件</a> (<b>若執行個體已經指派 IAM Role 可以略過以下操作</b>)<br /> 若要刪除AWS-CLI設定檔案:<br /> <a href="https://stackoverflow.com/questions/46319880/how-do-i-clear-the-credentials-in-aws-configure">Linux 說明</a><br /> <a href="https://stackoverflow.com/questions/40098377/aws-configure-delete-access-key-profile">Windows 說明</a> <br /> 3. 進行遷移動作 依照情境決定你要輸入的指令 <p></p> <b>複製本機目錄 到 S3指定位置並設定公開讀取(這指令會將本地指定內的資料夾檔案一併上傳)</b><br /> ``` aws s3 cp [本機目錄] s3://[bucket-name]/[後面接著你想要放置的位置] --recursive --acl public-read ``` <b>複製本機目錄 到 S3指定位置並設定私有權限(這指令會將本地指定內的資料夾檔案一併上傳)</b><br /> ``` aws s3 cp [本機目錄] s3://[bucket-name]/[後面接著你想要放置的位置] --recursive --acl private ``` <b>刪除S3指定資料夾與檔案(這指令會將指定S3路徑內的檔案一併刪除)</b><br /> ``` aws s3 rm s3://[bucket-name]/[後面接著你想要放置的位置] --recursive ``` <b>刪除S3指定檔案</b><br /> ``` aws s3 rm s3://[bucket-name]/[後面接著你想要放置的位置] ``` ### 參考文件: <a href="https://docs.aws.amazon.com/zh_tw/AmazonS3/latest/dev/acl-overview.html#canned-acl">AWS S3 ACL 權限列表</a> <a href="https://docs.aws.amazon.com/cli/latest/reference/s3/">S3 CLI Document</a> <a href="https://stackoverflow.com/questions/7042993/moving-many-files-in-the-same-bucket">Moving many files in the same bucket</a> <a href="https://docs.aws.amazon.com/zh_tw/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-precedence">AWS CLI 組態設定和優先順序-組態設定和優先順序</a>