๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
DevOps/AWS

AWS Amazon S3 ๋ฒ„ํ‚ท ์ƒ์„ฑํ•˜๊ธฐ

by ์ฃผ๋ฐœ2 2021. 7. 9.
๋ฐ˜์‘ํ˜•

๐Ÿ“Ž  AWS Amazon S3 ๋ฒ„ํ‚ท ์ƒ์„ฑํ•˜๊ธฐ(Sipmle Storage Service)

 

์•ˆ๋…•ํ•˜์„ธ์š”~ ์ด๋ฒˆ์—๋Š” AWS์—์„œ Amazon S3 ๋ฒ„ํ‚ท์„ ์ƒ์„ฑํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :)

๋จผ์ € S3์„ ์ƒ์„ฑํ•˜๊ธฐ ์ „์—, S3๋ž€ ๋ฌด์—‡์ธ์ง€ ๊ฐ„๋žตํžˆ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

๐ŸŽฏ  Amazon S3

Amazon S3๋ž€, Simple Storage Service์˜ ์•ฝ์ž๋กœ ์ธํ„ฐ๋„ท์šฉ ์Šคํ† ๋ฆฌ์ง€ ์ž…๋‹ˆ๋‹ค.

Amazon S3๋Š” ์›น์ƒ์—์„œ, ์–ธ์ œ ์–ด๋””๋“ ์ง€ ์›ํ•˜๋Š” ์–‘์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๊ณ  ๊ฒ€์ƒ‰ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ„๋‹จํ•œ ์›น ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Amazon S3์˜ ํŠน์ง•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • REST ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์ €์žฅ / ์‚ญ์ œ / ์กฐํšŒ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • ์ฃผ๋กœ ์ด๋ฏธ์ง€ ํŒŒ์ผ, ์ •์  ๋ฆฌ์†Œ์Šค ๋“ฑ์„ S3์— ์˜ฌ๋ ค๋†“๊ณ  ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • ๋‚ด๊ตฌ์„ฑ์ด ์ข‹์Šต๋‹ˆ๋‹ค.(๋ฐ์ดํ„ฐ ์œ ์‹ค ๊ฐ€๋Šฅ์„ฑ์˜ ๊ฑฐ์˜ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค)

 

 

๐ŸŽฏ  Amazon S3 ์šฉ์–ด

Amazon S3์˜ ์šฉ์–ด๋ฅผ ๊ฐ„๋žตํžˆ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

Buckets

  • Amazon S3์—์„œ ์ƒ์„ฑ๋˜๋Š” ์ตœ์ƒ์œ„์˜ ๋””๋ ‰ํ† ๋ฆฌ์ด๋ฉฐ, Amazon S3์— ์ €์žฅ๋œ ๊ฐ์ฒด์˜ ์ปจํ…Œ์ด๋„ˆ ์ž…๋‹ˆ๋‹ค.
  • S3์ƒ์˜ ๋ชจ๋“  ๊ฐ์ฒด๋Š” ๋ฒ„ํ‚ท์— ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.
  • ๋ฒ„ํ‚ท์˜ ์ด๋ฆ„์€ S3์—์„œ ์œ ์ผํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Objects

  • S3์— ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๋Š” ์ตœ์†Œ ๋‹จ์œ„์ž…๋‹ˆ๋‹ค.
  • Objects๋Š” ์ตœ๋Œ€ 5TB๊นŒ์ง€ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค.

Keys

  • ๋ฒ„ํ‚ท ๋‚ด ๊ฐ์ฒด์˜ ๊ณ ์œ  ์‹๋ณ„์ž์ž…๋‹ˆ๋‹ค.
  • ๋ฒ„ํ‚ท์˜ ๋ชจ๋“  ๊ฐ์ฒด์—๋Š” ์ •ํ™•ํžˆ ํ•˜๋‚˜์˜ ํ‚ค๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.
  • ๋ณดํ†ต "๋””๋ ‰ํ† ๋ฆฌ + ํŒŒ์ผ๋ช…" ์œผ๋กœ ๋ช…๋ช…๋ฉ๋‹ˆ๋‹ค.

Regions

  • S3๊ฐ€ ์ƒ์„ฑํ•œ ๋ฒ„ํ‚ท์„ ์ €์žฅํ•  ์œ„์น˜๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ฆฌ์ „ ๊ฐ„ ๊ฐ์ฒด ๊ณต์œ ๋Š” ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • ๋ฒ„ํ‚ท ์œ„์น˜(๋ฆฌ์ „)์„ ์–ด๋””์— ์ง€์ •ํ•˜๋ƒ์— ๋”ฐ๋ผ ์ง€์—ฐ ์‹œ๊ฐ„, ๋น„์šฉ ๋“ฑ์ด ๊ฒฐ์ •๋ฉ๋‹ˆ๋‹ค.

 

 

 

๐ŸŽฏ  Amazon S3 ์ƒ์„ฑํ•˜๊ธฐ

์ด์ œ S3์„ ์ƒ์„ฑํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

AWS ๋กœ๊ทธ์ธ์„ ํ•˜๊ณ  ์•„๋ž˜ ๋งํฌ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

 

https://console.aws.amazon.com/s3/home?region=ap-northeast-2 

 

https://console.aws.amazon.com/s3/home?region=ap-northeast-2

 

console.aws.amazon.com

 

 

S3์—์„œ ๋ฒ„ํ‚ท ๋งŒ๋“ค๊ธฐ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

 

 

 

1) ๋ฒ„ํ‚ท ์ด๋ฆ„๊ณผ ๋ฆฌ์ „์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  • ๋ฒ„ํ‚ท ์ด๋ฆ„์€ ๊ณ ์œ ๊ฐ’์œผ๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

2) ํผ๋ธ”๋ฆญ ์•ก์„ธ์Šค ์„ค์ •

S3์˜ ํผ๋ธ”๋ฆญ ์•ก์„ธ์Šค ๊ถŒํ•œ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

 

โ€ป ์™ธ๋ถ€์— S3์„ ๊ณต๊ฐœํ•  ๊ฒฝ์šฐ ๋ชจ๋“  ํผ๋ธ”๋ฆญ ์•ก์„ธ์Šค ์ฐจ๋‹จ์„ ์ฒดํฌ ํ•ด์ œํ•˜๊ณ , ๊ณต๊ฐœํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์ฒดํฌ๋ฅผ ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

ํผ๋ธ”๋ฆญ ์•ก์„ธ์Šค๋ฅผ ์ฐจ๋‹จํ• ๊ฒฝ์šฐ, IAM์—์„œ AWSAccessKeyId, AWSSecretKey๋ฅผ ๋ฐœ๊ธ‰๋ฐ›๊ณ 

ํ‚ค๋ฅผ ์ด์šฉํ•ด์„œ S3 ๊ฐ์ฒด์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ €๋Š” ์™ธ๋ถ€์— S3์„ ๊ณต๊ฐœํ•  ์˜ˆ์ •์ด๋ฏ€๋กœ, ์ฒดํฌ๋ฅผ ํ•ด์ œํ•ฉ๋‹ˆ๋‹ค.

(์ฒดํฌํ•˜๊ณ  ์ •์ฑ… ์„ค์ •ํ•˜๋Š๋ผ ์‚ฝ์งˆ์„ ์ข€ ํ–ˆ์Šต๋‹ˆ๋‹ค ๐Ÿ˜ญ๐Ÿ˜ญ)

 

 

 

3) ๋ฒ„ํ‚ท ๋ฒ„์ „ ๊ด€๋ฆฌ & ๊ธฐ๋ณธ ์•”ํ˜ธํ™”

๋ฒ„ํ‚ท ๋ฒ„์ „ ๊ด€๋ฆฌ ๋ฐ ๊ธฐ๋ณธ ์•”ํ˜ธํ™”๋Š” ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ  ๋ฒ„ํ‚ท์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

 

 

4) ํผ๋ธ”๋ฆฟ ์ •์ฑ… ํ™œ์„ฑํ™”

์œ„ ๊ณผ์ •์ด ๋๋‚ฌ์œผ๋ฉด ๋ฒ„ํ‚ท์€ ์ƒ์„ฑ๋˜์—ˆ์ง€๋งŒ, '๋ฒ„ํ‚ท ๋ฐ ๊ฐ์ฒด๊ฐ€ ํผ๋ธ”๋ฆญ์ด ์•„๋‹˜'์ด๋ผ๋Š” ๋ฌธ๊ตฌ์™€ ํ•จ๊ป˜ ์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์—†๋Š”๋ฐ์š”,

๋ฒ„ํ‚ท ์ •์ฑ…์„ ์ƒ์„ฑํ•ด์ฃผ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

5) ๋ฒ„ํ‚ท ์ •์ฑ… ์ƒ์„ฑ

http://awspolicygen.s3.amazonaws.com/policygen.html

 

AWS Policy Generator

Click below to edit. To save the policy, copy the text below to a text editor. Changes made below will not be reflected in the policy generator tool.

awspolicygen.s3.amazonaws.com

 

 

์œ„ ์‚ฌ์ดํŠธ๋กœ ๋“ค์–ด๊ฐ€์„œ ์•„๋ž˜ ๋นจ๊ฐ„์ƒ‰ ํ‘œ์‹œ ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

  • Select Type of Policy: S3 Buckey Policy
  • Effect: Allow
  • Principal: *
  • Actions: GetObject (์กฐํšŒ๋งŒ ๊ฐ€๋Šฅํ•˜๋„๋ก getObject ๊ถŒํ•œ๋งŒ ์ฒดํฌํ–ˆ์Šต๋‹ˆ๋‹ค.)
  • Amazon Resource Name (ARN): arn:aws:s3:::{๋ฒ„ํ‚ท์ด๋ฆ„}/*

๋‹ค ์ˆ˜์ •ํ•˜์…จ์œผ๋ฉด Add Statement ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด์ฃผ์„ธ์š”.

 

์ƒ์„ฑ๋œ ์ •์ฑ…์„ ํ™•์ธํ•˜๊ณ  Generate Policy ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

 

 

์ƒ์„ฑ๋œ ์ •์ฑ…์˜ JSON ๊ฐ’์„ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

 

 

 

6) ๋ฒ„ํ‚ท ์ •์ฑ… ์ ์šฉ

  • ๋ฒ„ํ‚ท ์ •์ฑ… ์ ์šฉ์„ ์œ„ํ•ด AWS์—์„œ ์ƒ์„ฑํ•œ ๋ฒ„ํ‚ท์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

 

 

๋ฒ„ํ‚ท์—์„œ ๊ถŒํ•œ > ๋ฒ„ํ‚ท ์ •์ฑ… ํŽธ์ง‘ ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

 

 

์œ„์—์„œ ๋ณต์‚ฌํ•œ JSON ๊ฐ’์„ ๋ถ™์—ฌ๋„ฃ๊ณ  ๋ณ€๊ฒฝ ์‚ฌํ•ญ ์ €์žฅ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

 

 

์‚ฌ์ง„๊ณผ ๊ฐ™์ด ์•ก์„ธ์Šค์— ํผ๋ธ”๋ฆญ์œผ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค๋ฉด ์™ธ๋ถ€์—์„œ S3์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•œ ์ƒํƒœ์ž…๋‹ˆ๋‹ค.

  • ์œ„์—์„œ ์ •์ฑ…์„ getObject(์กฐํšŒ) ๋งŒ ๊ฐ€๋Šฅํ•˜๋„๋ก ์„ค์ •ํ–ˆ์œผ๋ฏ€๋กœ, ํ˜„์žฌ S3์— ์กฐํšŒ๋งŒ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

 

 

7) S3 ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ

๋ฒ„ํ‚ท์— ์ด๋ฏธ์ง€๋ฅผ ๋“ฑ๋กํ•œ ํ›„ ๊ฐ์ฒด URL์„ ์ž…๋ ฅํ•˜๋ฉด ์ •์ƒ์ ์œผ๋กœ ์ด๋ฏธ์ง€์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

๋‹ค์Œ ์‹œ๊ฐ„์—๋Š” Java๋ฅผ ์ด์šฉํ•ด ๊ฐ„๋‹จํ•˜๊ฒŒ S3์— ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :)

 

 

 

References

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€