[AWS] AWS CLI를 이용한 S3 버킷 다루기Public Cloud/AWS2022. 3. 29. 15:55
Table of Contents
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
'Public Cloud > AWS' 카테고리의 다른 글
[AWS] VPC 네트워크 수동으로 설정하기 (0) | 2022.03.30 |
---|---|
[AWS] Ubuntu Crontab 설정을 통한 S3 버킷 자동 백업 설정하기 (s3cmd 패키지) (0) | 2022.03.30 |
[AWS] AWS의 컨테이너 사용/배포 서비스 (0) | 2022.03.18 |
AWS EKS로 웹 앱을 배포해보자 ! - 2. Application 배포하기 (0) | 2022.03.16 |
AWS EKS로 웹 앱을 배포해보자 ! - 1. EKS 구성하기 (0) | 2022.03.16 |
@TTOII :: 뭉게뭉게 클라우드
영차영차 성장 블로그
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!