Public Cloud/AWS
[AWS] AWS CLI를 이용한 S3 버킷 다루기
TTOII
2022. 3. 29. 15:55
728x90
실습에 앞서 AWS CLI 설치, IAM 생성 및 s3 동기화 방법은 아래 글을 참고하여 완료했다.
✔︎ AWS S3 CLI 주요 명령어
✔︎ 신규 버킷 생성
aws s3 mb <s3://버킷명>
ex) aws s3 mb s3://newbucket
✔︎ 버킷 및 객체 확인
버킷 확인
aws s3 ls
객체 확인
aws s3 ls <s3://버킷명>
# aws s3 ls s3://s3-linuxclitest
✔︎ 버킷 삭제
aws s3 rb <s3://버킷명>
# aws s3 rb s3://s3-linuxclitest
✔︎ 객체 삭제
aws s3 rm <s3://버킷명/객체명>
# aws s3 rm s3://s3-linuxclitest/test
✔︎ 객체 이동
aws s3 mv <source> <target>
# aws s3 mv /root/file.txt s3://testbuket
# aws s3 mv s3://newbucket/file.txt s3://s3-linuxclitest/
✔︎ 객체 복사
aws s3 cp <source> <taget>
# aws s3 cp /root/file.txt s3://s3-linuxclitest
# aws s3 cp s3://newbucket/file.txt s3://s3-linuxclitest/
✔︎ 객체 동기화
aws s3 sync <source> <target>
# aws s3 sync /root/ s3://s3-linuxclitest
# aws s3 sync s3://newbucket/ s3://s3-linuxclitest
--recursive 옵션
해당 옵션을 사용하면 지정된 디렉터리 또는 접두사 아래의 모든 객체에 대해 명령이 수행된다. (명령어 mv, cp, rm 적용)
# aws s3 mv /root s3://s3-linuxclitest/ --recursive
✔︎ AWS S3 CLI 명령어 실습
ubuntu@ip-172-31-29-48:~$ aws s3 ls
2022-03-29 05:39:51 ssh-desktop-backup
2022-03-29 05:36:01 ssh-test1
ubuntu@ip-172-31-29-48:~$ aws s3 mb s3://ssh-test2
make_bucket: ssh-test2
ubuntu@ip-172-31-29-48:~$ aws s3 ls
2022-03-29 05:39:51 ssh-desktop-backup
2022-03-29 05:36:01 ssh-test1
2022-03-29 07:04:59 ssh-test2
ubuntu@ip-172-31-29-48:~$ aws s3 ls s3://ssh-test2
ubuntu@ip-172-31-29-48:~$ aws s3 rb s3://ssh-test2
remove_bucket: ssh-test2
ubuntu@ip-172-31-29-48:~$ aws s3 ls
2022-03-29 05:39:51 ssh-desktop-backup
2022-03-29 05:36:01 ssh-test1
ubuntu@ip-172-31-29-48:~$ aws s3 ls s3://ssh-test1
2022-03-29 05:12:53 1346111 test.png
2022-03-29 06:33:11 7 test1.txt
2022-03-29 06:33:11 0 test2.txt
ubuntu@ip-172-31-29-48:~$ aws s3 rm s3://ssh-test1/test1.txt
delete: s3://ssh-test1/test1.txt
ubuntu@ip-172-31-29-48:~$ aws s3 ls s3://ssh-test1
2022-03-29 05:12:53 1346111 test.png
2022-03-29 06:33:11 0 test2.txt
ubuntu@ip-172-31-29-48:~$ aws s3 mv s3://ssh-test1/test.png s3://ssh-desktop-backup
move: s3://ssh-test1/test.png to s3://ssh-desktop-backup/test.png
ubuntu@ip-172-31-29-48:~$ aws s3 ls s3://ssh-desktop-backup
2022-03-29 07:10:18 1346111 test.png
ubuntu@ip-172-31-29-48:~$ aws s3 cp s3://ssh-test1/test2.txt s3://ssh-desktop-backup
copy: s3://ssh-test1/test2.txt to s3://ssh-desktop-backup/test2.txt
ubuntu@ip-172-31-29-48:~$ aws s3 ls s3://ssh-desktop-backup
2022-03-29 07:10:18 1346111 test.png
2022-03-29 07:11:41 0 test2.txt
ubuntu@ip-172-31-29-48:~$ aws s3 ls
2022-03-29 05:39:51 ssh-desktop-backup
2022-03-29 05:36:01 ssh-test1
ubuntu@ip-172-31-29-48:~$ aws s3 ls s3://ssh-test1
2022-03-29 05:12:53 1346111 test.png
ubuntu@ip-172-31-29-48:~$ mkdir backup
ubuntu@ip-172-31-29-48:~$ cd backup
ubuntu@ip-172-31-29-48:~/backup$ touch test1.txt
ubuntu@ip-172-31-29-48:~/backup$ touch test2.txt
ubuntu@ip-172-31-29-48:~/backup$ vi test1.txt
ubuntu@ip-172-31-29-48:~/backup$ pwd
/home/ubuntu/backup
ubuntu@ip-172-31-29-48:~/backup$ aws s3 sync /home/ubuntu/backup s3://ssh-test1
upload: ./test1.txt to s3://ssh-test1/test1.txt
upload: ./test2.txt to s3://ssh-test1/test2.txt
ubuntu@ip-172-31-29-48:~/backup$ aws s3 ls s3://ssh-test1/
2022-03-29 05:12:53 1346111 test.png
2022-03-29 06:33:11 7 test1.txt
2022-03-29 06:33:11 0 test2.txt
728x90