
s3의 상위 개념이 ebs? -> XXX
efs는 파일시스템
s3는 오브젝트 스토리지
어떻게하면 고가용성을 보장하면서 스토리지 비용을 최적화하고 보안을 제공할 수 있습니까?
-> 이건 우리가 답 찾으세요 일단 보안을 위해서는 암호화, 비용과 trade-off 관계
오래된 이미지의 스토리지 비용을 절감하고 싶습니다.
어떻게하면 프로세스를 자동화할 수 있습니까?
-> 라이프사이클
-> 오래된 이미지 -- 라이프 사이클 
window와 linux 모두에 대해 아전하고 확장 가능한 스토리지를 구축하기 위해서 검토할 수 있는 몇가지 옵션은 무엇입니까?
-> 스토리지 게이트웨이
비교적 짧은 기간에 대규모 데이터를 클라우드로 이전해야 한다. 어떤 옵션이 있습니까?
-> 







-> 👻 버킷 정책 수정해야한다.
나뿐만 아니라 다른 사용자도 사용하는 웹 어플리케이션을 띄울려면 CORS를 반드시 정책으로 포함해야 한다.








-> 지금은 http, https 모두 접속가능
근데 여기서 보안팀이 http 쓰지마~ 하면 ?
정책 편집 !
{
    "Version": "2012-10-17",
    "Id": "Policy1666057094613",
    "Statement": [
        {
            "Sid": "Stmt1666057079173",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mymedia-5230/*"
        },
        {
            "Sid": "Stmt1666057079174", // 🐣 여긴 unique한 값이어야 한다. 
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mymedia-5230/*",
            "Condition": { // 🐣 https만 허용하는 
                "Bool": {
                    "aws:SecureTransport": "false"
                }
            }
        }
    ]
}


1) 스토리지 요금제
2) 요청 및 데이터 검색 요금제 (🐣 삭제는 돈 안 나가~)
3) 데이터 전송 및 Amazon S3 Transfer Acceleration 요금제
4) 데이터 관리 및 분석 요금제
똑같은 컨텐츠를 EC2에 올려도 ok, s3에 올려도 ok
무슨 차이임? 
s3에는 프로그램(APM: apache 등)을 깔 수가 없어서 정적인 리소스만 저장가능
https://mymedia-5230.s3.ap-northeast-2.amazonaws.com/index.html
https://[버킷 이름].s3.[리전 이름].amazonaws.com/index.html 



알 수 없거나 자주 변화하는 액세스 패턴이 있는 데이터를 위한 서비스
S3 standard ,S3 standard-IA 사이에 사용량을 분석해 스토리지 비용을 자동으로 최적화한다.

신속 / 표준 / 대량 이라는 세가지 표준을 가지고 있다.
라이프 사이클 관리 왜 해요 ? 비용 !










Cognito를 이용해야한다.



-> 역할 생성! 









-> 이제 생성하기 


{
    "Version": "2012-10-17",
    "Id": "Policy1666070801401",
    "Statement": [
        {
            "Sid": "Stmt1666070787541",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::photo-upload-s3-5230/*"
        }
    ]
}





[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "PUT",
            "POST",
            "HEAD"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": [
            "x-amz-server-side-encryption",
            "x-amz-request-id",
            "x-amz-id-2"
        ],
        "MaxAgeSeconds": 3000
    }
]
👻 aws CLI 다운로드 
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
[ec2-user@ip-172-31-35-155 LABs]$ aws --version
aws-cli/1.18.147 Python/2.7.18 Linux/5.10.144-127.601.amzn2.x86_64 botocore/1.18.6
 👻 confiure로 내가 만든 사용자의 access key와 secret key 넣어준다.
[ec2-user@ip-172-31-35-155 LABs]$ aws configure
AWS Access Key ID [None]: 
AWS Secret Access Key [None]: 
Default region name [None]: ap-northeast-2
Default output format [None]: json
 👻 내가 가진 S3 버킷 조회 
 -> how? 우리가 아까 S3 Full Access 권한을 줌 
[ec2-user@ip-172-31-35-155 LABs]$ aws s3 ls
2022-10-18 03:22:35 mymedia-5230
2022-10-18 05:28:56 photo-upload-s3-5230
 👻 버킷에 저장된 객체 조회
 [ec2-user@ip-172-31-35-155 ~]$ aws s3 ls s3://mymedia-5230
                           PRE assets/
                           PRE css/
                           PRE js/
2022-10-18 02:35:20   39782929 Humans_AI.mp4
2022-10-18 02:29:34      39106 index.html
👻 aws cli로 파일 한 개 업로드
[ec2-user@ip-172-31-35-155 LABs]$ aws s3 cp awscli-test1.txt s3://mymedia-5230/awscli-test1.txt
upload: ./awscli-test1.txt to s3://mymedia-5230/awscli-test1.txt 

👻 aws cli로 폴더 업로드! 아니고 여러 파일 업로드 
[ec2-user@ip-172-31-35-155 LABs]$ mkdir upload && cd $_
[ec2-user@ip-172-31-35-155 upload]$ echo 'hello~ korea~' > korea.txt
[ec2-user@ip-172-31-35-155 upload]$ echo 'hello~ usa~' > usa.txt
[ec2-user@ip-172-31-35-155 upload]$ echo 'hello~ japan~' > japan.txt
[ec2-user@ip-172-31-35-155 upload]$ cd ..
[ec2-user@ip-172-31-35-155 LABs]$ aws s3 sync upload s3://mymedia-5230
upload: upload/usa.txt to s3://mymedia-5230/usa.txt               
upload: upload/korea.txt to s3://mymedia-5230/korea.txt           
upload: upload/japan.txt to s3://mymedia-5230/japan.txt 
>> S3 버킷에는 korea.txt, usa.txt, japan.txt가 각각 저장된다. 

👻  스토리지 클래스 지정 
[ec2-user@ip-172-31-35-155 upload]$ mv korea.txt korea-IA.txt
[ec2-user@ip-172-31-35-155 upload]$ mv usa.txt usa-IA.txt
[ec2-user@ip-172-31-35-155 upload]$ mv japan.txt japan-IA.txt
[ec2-user@ip-172-31-35-155 upload]$ ls
japan-IA.txt  korea-IA.txt  usa-IA.txt
[ec2-user@ip-172-31-35-155 upload]$ cd ..
[ec2-user@ip-172-31-35-155 LABs]$ aws s3 sync upload s3://mymedia-5230 --storage-class STANDARD_IA
upload: upload/usa-IA.txt to s3://mymedia-5230/usa-IA.txt         
upload: upload/japan-IA.txt to s3://mymedia-5230/japan-IA.txt     
upload: upload/korea-IA.txt to s3://mymedia-5230/korea-IA.txt  

<[ec2-user@ip-172-31-35-155 LABs]$ git clone https://github.com/brayanlee/website.git
Cloning into 'website'...
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 28 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (28/28), 1.23 MiB | 3.16 MiB/s, done.
[ec2-user@ip-172-31-35-155 LABs]$ cd website/
[ec2-user@ip-172-31-35-155 website]$ tar xvzf webapp.tar.gz 
./
./css/
./css/bootstrap.css
./index.html
./pngs/
./pngs/docker.png
./pngs/docker_logo.png
[ec2-user@ip-172-31-35-155 website]$ ls
css  index.html  pngs  webapp.tar.gz
[ec2-user@ip-172-31-35-155 website]$ rm webapp.tar.gz 
👻 버킷 생성하기, region 생략 시 미국 오레곤으로 생성 
[ec2-user@ip-172-31-35-155 website]$ aws s3 mb s3://awscli-bucket-5230 --region ap-northeast-2
make_bucket: awscli-bucket-5230
👻 생성한 버킷 조회
[ec2-user@ip-172-31-35-155 website]$ aws s3 ls
2022-10-18 06:22:10 awscli-bucket-5230
2022-10-18 03:22:35 mymedia-5230
2022-10-18 05:28:56 photo-upload-s3-5230
👻 website directory 내의 모든 data를 생성한 버킷에 업로드
[ec2-user@ip-172-31-35-155 LABs]$ aws s3 website s3://awscli-bucket-5230 --acl public-read
## csv 파일 저장
[ec2-user@ip-172-31-35-155 query]$ vim s3_select_sample.csv
Name,PhoneNumber,City,Occupation
hylee,(010) 555-6701,Irvine,Solutions Architect
Vinod,(010) 555-6702,Los Angeles,Solutions Architect
Jeff,(010) 555-6703,Seattle,AWS Evangelist
Jane,(010) 555-6704,Chicago,Developer
kevin,(010) 555-6705,Seoul,Instructor
Mary,(010) 555-6706,Chicago,Developer
Kate,(010) 555-6707,Chicago,Developer
Alice,(010) 555-6708,Seattle,AWS Evangelist
Sunny,(010) 555-6709,Seoul,Instructor
Sam,(010) 555-6710,Los Angeles,Solutions Architect
[ec2-user@ip-172-31-35-155 query]$ aws s3 cp s3_select_sample.csv s3://mymedia-5230/s3-select_sample.csv
upload: ./s3_select_sample.csv to s3://mymedia-5230/s3-select_sample.csv

[ec2-user@ip-172-31-35-155 ~]$ python3 -m venv ~/s3select_demo/env
[ec2-user@ip-172-31-35-155 ~]$ source ~/s3select_demo/env/bin/activate
(env) [ec2-user@ip-172-31-35-155 ~]$ pip install boto3
vim employee_query.py
python3 employee_query.py 
Stats details bytesScanned: 
463
Stats details bytesProcessed: 
463
Stats details bytesReturned: 
0
import boto3
s3 = boto3.client('s3')
resp = s3.select_object_content(
    Bucket='mymedia-5230',
    Key='s3-select_sample.csv',
    ExpressionType='SQL',
    Expression="SELECT * FROM s3object s where s.\"Name\" = 'alice'",
    InputSerialization = {'CSV': {"FileHeaderInfo": "Use"}, 'CompressionType': 'NONE'},
    OutputSerialization = {'CSV': {}},
)
for event in resp['Payload']:
    if 'Records' in event:
        records = event['Records']['Payload'].decode('utf-8')
        print(records)
    elif 'Stats' in event:
        statsDetails = event['Stats']['Details']
        print("Stats details bytesScanned: ")
        print(statsDetails['BytesScanned'])
        print("Stats details bytesProcessed: ")
        print(statsDetails['BytesProcessed'])
        print("Stats details bytesReturned: ")
        print(statsDetails['BytesReturned'])
(env) [ec2-user@ip-172-31-35-155 query]$ ls
employee_query.py  s3_select_sample.csv
(env) [ec2-user@ip-172-31-35-155 query]$ gzip s3_select_sample.csv 
(env) [ec2-user@ip-172-31-35-155 query]$ ls 
employee_query.py  s3_select_sample.csv.gz
(env) [ec2-user@ip-172-31-35-155 query]$ aws s3 cp s3_select_sample.csv.gz s3://mymedia-5230/
upload: ./s3_select_sample.csv.gz to s3://mymedia-5230/s3_select_sample.csv.gz
⭐ 📘 📗 💭 🤔 📕 📔 🐳 ✍ 🥳 ⭐ 🐣 👻
SAN, DAN, NAS(파일시스템->클라우드로 이전했을시 EFS로 전환시킨다.) 정리해서 검사맡기(한줄정리, 사용사례)
API 통신이란...
sdk, cdk// cloud development kit
cidr
🤔 서울 - 서울 리전을 써도, 도쿄 - 서울 리전을 써도 비용이 있어
🤔 ACL을 비활성화 하면 소유자만 접근할 수 있게 된다. ?
오래된 파일(저장된 데이터가 축적되면 용량과 비용만 차지함)을 관리하기 위해 lifecycle 규칙 관리가 필요
ec2의 스냅샷도 S3에 저장
S3와 머신러닝 ec2 사이에 트리거를 놓는다.
즉, 특정 조건이 만족하면 머신러닝에게 보낼 수 있도록
Lambda를 설정한다.S3는 이벤트 알람 기능을 통해 Lambda가 전달한다.
그리고 머신러닝을 통한 결과 데이터를 또다른 S3에 저장한다.
네트워크 엑세스 포인트
분석

