안녕하세요 쿤드입니다. 🍀

S3 버킷에서 어떤 object가 생성되면 그에 대한 이벤트를 SQS로 받아서 처리할 필요가 생겼습니다.

설정대로 맞춰놓고 생성을 했는데 

  • [버킷] - [Properties] - Advenced settings [Events] 

에러가 발생합니다.

S3 이벤트 세팅

에러메시지

Unable to validate the following destination configurations. Permissions on the destination queue do not allow S3 to publish notifications from this bucket. (arn:aws:sqs:REGION:AWS계정ID:세팅하려던_SQS_QUEUE_NAME)

 

최초 생성은 IAM role로 접근에 제한을 둔 account로 생성하다가 실패해서 단순히 account에 권한이 없어서 안되는줄 알았습니다.

그래서 ADMIN 권한 (* 접근)을 가진 account로 다시 생성을 했는데 

마찬가지로 에러가 발생합니다.

 

이제서야 AWS 문서를 찾아서 읽어봤습니다.

https://docs.aws.amazon.com/AmazonS3/latest/dev/ways-to-add-notification-config-to-bucket.html 

 

Walkthrough: Configure a bucket for notifications (SNS topic and SQS queue) - Amazon Simple Storage Service

Walkthrough: Configure a bucket for notifications (SNS topic and SQS queue) Walkthrough summary In this example, you add a notification configuration on a bucket requesting Amazon S3 to do the following: Publish events of the s3:ObjectCreated:* type to an

docs.aws.amazon.com

읽어보니

SNS를 추가하면 SNS topic에 권한을 설정해주고

SQS를 추가하는 거라면 마찬가지로 SQS Queue에 권한을 추가하라는 말이었습니다.

 

남은 작업은

이제 정확하게 권한을 추가해주면 되는데 

{
 "Version": "2012-10-17",
 "Id": "example-ID",
 "Statement": [
  {
   "Sid": "example-statement-ID",
   "Effect": "Allow",
   "Principal": {
    "AWS":"*"  
   },
   "Action": [
    "SQS:SendMessage"
   ],
   "Resource": "SQS-queue-ARN",
   "Condition": {
      "ArnLike": { "aws:SourceArn": "arn:aws:s3:*:*:bucket-name" },
      "StringEquals": { "aws:SourceAccount": "bucket-owner-account-id" }
   }
  }
 ]
}

이게 뭐지? (라고 처음엔 느껴졌지만 작업을 마무리하고 다시 읽어보니 이해가 갑니다.)

 

일단 stackoverflow에서 비슷한 문제를 찾았습니다.

 stackoverflow.com/q/54791704/8163714

 

Unable to configure SQS queue notification in S3

I created an SQS queue and added policy under permission tab allowing only my account users to configure the configure the notification Policy Document { "Version": "2012-10-17", "Id": "arn:...

stackoverflow.com

들여쓰기의 차이일 뿐인데 이것을 보니 이해가 갑니다.

https://gist.github.com/marcelog/7b0224b63c90802996ab2dee7d7082e4

 

SQS Policy to allow an S3 bucket to publish messages

SQS Policy to allow an S3 bucket to publish messages - aws-sqs.policy

gist.github.com

이 설정은 SQS에서 QUEUE를 선택하고 

아래 화면에서 볼 수 있었습니다.

여기에 위의 gist에 있는 내용에서 나와 관련된 내용을 추가하고

S3에서 접근할테니 관련 bucket 정보를 추가하면 됩니다.

 

Bucket이 1개만 추가되지 않을 수도 있는데 2개 이상 추가도 됩니다. 

2개의 bucket을 [   ] 배열로 묶으면 더 보기 좋을텐데 방법을 못 찾았습니다.

Principals는 Everybody(*)로 두었는데, 

account로 제한을 더 두는게 나을 것 같은데 방법을 못 찾겠다. 제한을 좀 더 두고 싶은데..

  • arn:aws:iam::계정의ID:root 로만 되는것 같고 *을 줄 수가 없다. 내가 못 찾은걸지도 모르겠지만... 

 

S3에서 event 생성 잘 됩니다.

 

반응형

'Infra' 카테고리의 다른 글

AWS EKS Service Role 생성 (IAM)  (454) 2020.07.23
AWS EKS Cluster 세팅  (159) 2020.07.23
AWS의 Cloudwatch와 CloudTrail의 차이  (14) 2020.06.01
Route53 DNS health check (for Nginx)  (8) 2019.12.20
Setting Logstash amazon_es output  (648) 2019.11.04

+ Recent posts