
※ 내가 생각했을때 편한 생성(개발) 순서
S3 버킷 > IAM 정책 > IAM 역할 > EC2 인스턴스
S3 (Simple Storage Service) : 파일을 저장하는 AWS의 클라우드 저장소 서비스
Bucket : S3에 저장되는 데이터의 컨테이너
EC2 (Elastic Compute Cloud) : AWS에서 제공하는 가상컴퓨터(서버)
인스턴스 : EC2를 실제로 실행한 개별 서버 한 대
IAM (Identity and Access Management) : AWS 리소스에 대해 누가, 무엇을 할 수 있는지를 정의하는 서비스











0.0.0.0/0










sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential curl wget git vim unzip zip htop tree net-tools
nginx 설치sudo apt update && sudo apt install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx


curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
mkdir temp
cd temp
sudo chown -R ubuntu:ubuntu /home/ubuntu/temp
uv venv --python 3.11
streamlit
jupyterlab
source .venv/bin/activate
uv pip install -r requirements.txt
import streamlit as st
st.title("Hello AWS-Streamlit")



⬇️ 해결방법






jupyter lab --ip=0.0.0.0 --port=8888 --allow-root


퍼블릭IPv4:8888 접속

탄력적 IP 할당 이유
네트워크 및 보안 > 탄력적 IP > 탄력적 IP 주소 할당









.ssh/config > HostName 수정 - 변경된 DNS로 변경





arn:aws:s3:::lgu6th-streamlit-s3-kang





/* 추가 > 변경 사항 저장




























{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::lgu6th-streamlit-s3-kang"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject"
],
"Resource": "arn:aws:s3:::lgu6th-streamlit-s3-kang/*"
}
]
}

streamlit
jupyterlab
pandas
boto3
awscli
import streamlit as st
import boto3
import pandas as pd
import io
import random
from datetime import datetime
st.title("Hello AWS-Streamlit")
# S3 설정
bucket = 'lgu6th-streamlit-s3-kang' # S3 버킷 이름
key = 'dataset/random_scores.csv'
s3 = boto3.client('s3')
def load_data():
try:
obj = s3.get_object(Bucket=bucket, Key=key)
return pd.read_csv(io.BytesIO(obj['Body'].read()))
except s3.exceptions.NoSuchKey:
return pd.DataFrame(columns=['timestamp', 'name', 'score'])
def save_data(df):
buffer = io.StringIO()
df.to_csv(buffer, index=False)
s3.put_object(Bucket=bucket, Key=key, Body=buffer.getvalue())
def generate_row():
return {
'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'name': random.choice(['Alice', 'Bob', 'Charlie', 'David']),
'score': random.randint(60, 100)
}
# 앱 UI
st.title("📦 EC2 ↔ S3 데이터 관리 앱")
# 1️⃣ 데이터 추가 버튼
if st.button("➕ 새 데이터 추가"):
df = load_data()
new_row = generate_row()
df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
save_data(df)
st.success(f"S3에 {new_row['name']} 점수 {new_row['score']} 저장됨")
# 2️⃣ 데이터 가져오기 버튼
if st.button("📥 데이터 가져오기"):
df = load_data()
if df.empty:
st.warning("S3에 저장된 데이터가 없습니다.")
else:
st.subheader("📋 저장된 데이터")
st.dataframe(df)
st.subheader("📊 평균 점수 그래프")
st.bar_chart(df.groupby("name")["score"].mean())



요금이 발생하는 이유
퍼블릭 IP를 EC2에 할당해두었지만, 실제 인스턴스가 꺼져 있는 상태(비활성)인 경우 (AWS에서는 2024년부터 IPv4 주소 부족 문제로 인해, 사용 중이 아닌 퍼블릭 IP에 시간당 요금이 부과됨)
연결 안 된 상태로 남아 있을 경우, 시간당 $0.005 발생
Asia/Seoul > Elastic IP 릴리즈

