๊ฐœ์š”

๐Ÿ’ก
Pre-signed URL์ด๋ž€ AWS ์ž์›์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉ๋˜๋Š” ์ด๋ฆ„ ๊ทธ๋Œ€๋กœ ์‚ฌ์ „์— ์ ์ ˆํ•œ ๊ถŒํ•œ์„ ๊ฐ€์ง„ ์ž๊ฒฉ์ฆ๋ช…์— ์˜ํ•˜์—ฌ Signed ๋œ URL์ž…๋‹ˆ๋‹ค. CloudFront์˜ signed URL๊ณผ์˜ ๋น„์Šทํ•œ ๊ฐœ๋…์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค
      • ์‚ฌ์šฉ ๋„๊ตฌ
        RestAPI, AWS CLI,AWS CDK๋ฅผ ํ†ตํ•ด์„œ java,Net,Ruby,PHP,Node.js,python๋“ฑ์„ ํ†ตํ•ด ์ƒ์„ฑ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
      • CLI :https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/install-cliv2-windows.html 

         

        ํ…Œ์ŠคํŠธ

        <AWS CLI๋ฅผ ํ†ตํ•˜์—ฌ Presigned URL์„ ์ƒ์„ฑ>

        • ๋ฒ„ํ‚ท ์ƒ์„ฑ
          • ํ•ด๋‹น index.html ํŒŒ์ผ์„ ์—…๋กœ๋“œ ํ•˜์—ฌ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

           

        • CLI๋ฅผ ํ†ตํ•œ Presigned URL ์ƒ์„ฑ
          aws s3 presign s3://s3 object path –expires-in “๋งŒ๋ฃŒ์‹œ๊ฐ„” –region “๋Œ€์ƒ๋ฆฌ์ „”
          1. CLI๋ฅผ ํ†ตํ•œ URL ์ •๋ณด ํš๋“
            • ํ•ด๋‹น URL์€ S3 ํŠน์ • Object๋ฅผ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์ด ์ ์šฉ๋˜์–ด ์žˆ๋Š” URL์ž…๋‹ˆ๋‹ค.
            • ํ•ด๋‹น expires ์‹œ๊ฐ„์€ 120 : 2๋ถ„์ž…๋‹ˆ๋‹ค.
          1. Presigned URL TEST
            1. ๊ธฐ์กด bucket url์„ ํ†ตํ•œ ์ ‘์†
              • ์ฐจ๋‹จ ํ™•์ธ - ๊ธฐ๋ณธ์ ์œผ๋กœ ํ”„๋ผ์ด๋น— ์ด๊ธฐ ๋•Œ๋ฌธ
            1. Presigned-URL ์ ‘์†
            1. Time over
        • ์ถ”๊ฐ€

          Bucket Policy๋ฅผ ์ด์šฉํ•˜์—ฌ Presinged URL์˜ ์ง€์ •๋œ ๊ถŒํ•œ์„ ๋ฌด์‹œํ•˜์—ฌ ๋ฐฉ์ง€

          ์ง€์ •๋œ VPC์™ธ๋ถ€๋กœ S3์— ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

          1. ์ •์ฑ… ํŽธ์ง‘
            {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Sid": "Allow Bucket Access From specified VPC only",
                        "Effect": "Deny",
                        "Principal": {
                            "AWS": "arn:aws:iam::123456789012:user/username"
                        },
                        "Action": "s3:GetObject",
                        "Resource": "arn:aws:s3:::bucketname/*",
                        "Condition": {
                            "StringNotEquals": {
                                "aws:sourceVpce": "vpce-xxxxxxxx"
                            }
                        }
                    }
                ]
            }
          1. Presigned URL ์ƒ์„ฑ
          1. ์ ‘์† test
            • ์ ‘๊ทผ ์ฐจ๋‹จ ํ™•์ธ
          • boto 3 ์ด์šฉ์‹œ
            import boto
            conn = boto.connect_s3()
            url = conn.generate_url(120, 'GET', bucket='presignedurl-sample-bucket', key='test.txt')
            print url

         

        ๊ฒฐ๋ก 

        ๋”ฐ๋ผ์„œ, Presigned URL ์€ S3 Bucket์„ ๊ณต์œ ํ•  ๋•Œ(๋‹ค์šด๋กœ๋“œ or ์—…๋กœ๋“œ) ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์ง€๋งŒ S3 Bucket์— ๋Œ€ํ•œ ๊ถŒํ•œ์ด ์—†๋Š” ํ™˜๊ฒฝ์—์„œ๋„ Bucket ์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ์ค„ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์—์„œ ์กฐ์‹ฌ์Šค๋Ÿฝ๊ฒŒ ์‚ฌ์šฉ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.๋˜ํ•œ, ๋ˆ„๊ตฌ๋‚˜ Presigned URL์„ ์ƒ์„ฑ๊ฐ€๋Šฅํ•˜๋ฉฐ permission์ด ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ณต์œ  ๋Œ€์ƒ์ด ๋˜๋Š” S3 Bucket ๋„ ๋ณ„๋„์˜ ์ œํ•œ์—†์ด ์ง€์ •์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด S3 Presigned URL ์€ ๊ณต์œ  ๋Œ€์ƒ์ด ๋˜๋Š” S3 Bucket ๊ณผ Object ๋ฅผ ์ง€์ •ํ•˜๊ณ  ๊ณต์œ ๋ฅผ ํ•˜๋Š” IAM ์ž๊ฒฉ์ฆ๋ช…์˜ ๊ถŒํ•œ์„ ํ•จ๊ป˜ ์ง€์ •ํ•จ์œผ๋กœ์จ ์ตœ์ข…์ ์œผ๋กœ ๋ˆ„๊ตฐ๊ฐ€๊ฐ€ Presigned URL ๋กœ ์ ‘๊ทผํ–ˆ์„ ๋•Œ Presigned URL ์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๊ถŒํ•œ์„ ๊ฒ€์‚ฌํ•˜์—ฌ ํ•ด๋‹น ์š”์ฒญ์„ ํ—ˆ์šฉ/์ฐจ๋‹จํ•˜๋„๋ก ๋™์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์ฆ‰, ์ตœ์ข…์ ์ธ ๊ถŒํ•œ ๊ฒ€์‚ฌ๋Š” Presigned URL ์„ ์ด์šฉํ•œ ์š”์ฒญ์ด ์œ ์ž…๋˜์—ˆ์„ ๋•Œ ์ด๋ฃจ์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์— Presigned URL ์„ ์ƒ์„ฑํ•˜๋Š” ๋‹จ๊ณ„์—์„œ ์–ด๋–ค ์ œํ•œ์„ ์ ์šฉํ•  ์ˆ˜๋Š” ์—†์Šต๋‹ˆ๋‹ค.๋”ฐ๋ผ์„œ, Bucket Policy๋‚˜ IAM Policy์— ๋‹ค์–‘ํ•œ Condition์„ ์ ์šฉํ•˜์—ฌ ๊ถŒํ•œ์„ ์ ์ ˆํ•˜๊ฒŒ ์ œํ•œํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

         

         

 

 

 

 

'aws' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

RDS โ†’ s3 ๋ฐฑ์—…  (0) 2021.03.29
Elastisearch ๋ฅผ ์‚ฌ์šฉ VPC FLOWLOGS  (0) 2021.03.29
CloudWatch / SSM Agent  (0) 2021.03.29
lb -acm ์ธ์ฆ์„œ๋ฅผ ์ด์šฉํ•œ ์ ‘์†  (0) 2021.02.09
route 53 ๋„๋ฉ”์ธ ์—ฐ๊ฒฐ  (0) 2021.02.09

+ Recent posts