SQS Queue Access Policy

image-20220907012457381

SQS ๋Œ€๊ธฐ์—ด ์•ก์„ธ์Šค ์ •์ฑ…์— ๋Œ€ํ•œ ์ข‹์€ ์‚ฌ์šฉ์‚ฌ๋ก€๊ฐ€ ๋‘ ๊ฐœ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฆฌ์†Œ์Šค ์ •์ฑ…์ด๋ผ๋Š” ์ ์—์„œ S3 ๋ฒ„ํ‚ท์ •์ฑ…๊ณผ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰ JSON IAM์ •์ฑ…์„ SQS๋Œ€๊ธฐ์—ด์— ์ง์ ‘ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

  1. ๊ต์ฐจ ๊ณ„์ • ์•ก์„ธ์Šค๋ฅผ ํ—ˆ์šฉ

์–ด๋–ค ๊ณ„์ •์— ๋Œ€๊ธฐ์—ด์ด ์žˆ๊ณ  ๋‹ค๋ฅธ ๊ณ„์ฉก์ด ๊ทธ ๋Œ€๊ธฐ์—ด์— ์•ก์„ธ์Šค ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ํ•˜๊ณ , EC2 ์ธ์Šคํ„ด์Šค๊ฐ€ ํ•˜๋‚˜ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค. ๊ทธ EC2 Instance๊ฐ€ ๊ณ„์ • ๊ฐ„ ๋ฉ”์‹œ์ง€๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์œผ๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ƒ๊ธด ๋Œ€๊ธฐ์—ด ์•ก์„ธ์Šค ์ •์ฑ…์„ ์ƒ์„ฑํ•˜๊ณ  ์ด๋ฅผ ์ฒซ ๋ฒˆ์งธ ๊ณ„์ฉก์˜ SQS๋Œ€๊ธฐ์—ด์— ์ฒจ๋ถ€ํ•ด์•ผ ํ•œ๋‹ค.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": {"AWS": ["111122223333"]},
    "Action": ["sqs:ReceiveMessage"],
    "Resource": "arn:aws:sqs:us-east-1:444455556666:queue1"
  }]
}

์œ„์˜ Queue Access Policy ๋Š” AWS์˜ ๋ณด์•ˆ ์ฃผ์ฒด๊ฐ€ 11112222333์ด ๋  ์ˆ˜ ์žˆ๊ฒŒ ํ—ˆ์šฉํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์ด ์ •์ฑ…์€ EC2 ์ธ์Šคํ„ด์Šค๊ฐ€ ๋‹ค๋ฅธ ๊ณ„์ •์˜ SQS ๋Œ€๊ธฐ์—ด์—์„œ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

  1. S3 ์ด๋ฒคํŠธ ์•Œ๋ฆผ ๊ฒŒ์‹œ

S3 ๋ฒ„ํ‚ท์— ๊ฐ์ฒด๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด SQS๋Œ€๊ธฐ์—ด์— ์ž๋™์œผ๋กœ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋ƒ…๋‹ˆ๋‹ค. SQS๋Œ€๊ธฐ์—ด์€ S3๋ฒ„ํ‚ท์ด ๋ฉ”์‹œ์ง€๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ์ƒ๊ธด SQS Queue Access Policy ๋ฅผ ์ƒ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": {"AWS": "*"},
    "Action": ["sqs:SendMessage"],
    "Resource": "arn:aws:sqs:<region_name>:<bucket1_owner_account_id>:<queue_name>",
    "Condition": {
      "ArnLike": {"aws:SourceArn": "arn:aws:s3:*:*:<bucket_name>"},
      "StringEquals": {"aws:SourceAccount": "<bucket1_owner_account_id>"},
    }
  }]
}

์ž์„ธํžˆ ์‚ดํŽด๋ณด๋ฉด Action์€ sqs:SendMessage์ด๊ณ  Principal์€ ๋ชจ๋“ (*) ๊ณ„์ •์˜ AWS ์ž…๋‹ˆ๋‹ค. Condition์€ ๋ฒ„ํ‚ท์˜ ARN์†Œ์Šค๊ฐ€ โ€˜bucket1โ€™ ์ด๋ผ๋Š” ์ด๋ฆ„์˜ S3๋ฒ„ํ‚ท์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์†Œ์Šค ๊ณ„์ •์€ S3 ๋ฒ„ํ‚ท์˜ ๊ณ„์ • ์†Œ์œ ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด S3๋ฒ„ํ‚ท์€ SQS๋Œ€๊ธฐ์—ด์— ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

  • S3 ์— Object ๋“ค์„ ์ƒ์„ฑ/์ˆ˜์ •/์‚ญ์ œ ๋“ฑ๋“ฑ์˜ ์ž‘์—…์„ ํ•˜๊ฒŒ๋˜๋ฉด S3 => SQS Queue ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ „์†กํ•˜๊ฒŒ ํ•˜๋Š” ์ •์ฑ…์ด๋‹ค.
  • ์ด๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ƒํ™ฉ์— ๋งž๋Š” ๋กœ์ง์„ ์ž‘์„ฑํ•ด์„œ ์›ํ•˜๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋  ๊ฒƒ์ด๋‹ค.
  • ๊ตฌ๊ธ€๋ง ํ‚ค์›Œ๋“œ : How to send message S3 to SQS
  • ์•„๋ž˜ ๋™์˜์ƒ์„ ์ฐธ๊ณ ํ•ด๋„ ์ข‹์Œ

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ