AWS put-bucket-notification-configuration for SQS throws "Failed to check the following destination configurations"

I want to send s3: CreateObject: * events to the SQS queue. But setting up the results of setting up notifications inA client error (InvalidArgument) occurred when calling the PutBucketNotificationConfiguration operation: Unable to validate the following destination configurations

This is how I created the bucket:

aws s3api create-bucket --profile default --bucket my-bucket --create-bucket-configuration LocationConstraint=eu-west-1

This is how I created the SQS queue

aws sqs create-queue --profile default --queue-name my-queue --attributes file://attributes.json

with attributes.json file

{
  "DelaySeconds":"0",
  "MessageRetentionPeriod":"3600",
  "Policy":"{\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"sqs:SendMessage\",\"sqs:ReceiveMessage\"],\"Condition\":{\"ArnLike\": {\"aws:SourceArn\": \"arn:aws:s3:*:*:my-bucket\"}}}]}"
}

Finally, try setting up a notification that displays the error message above:

aws s3api put-bucket-notification-configuration --profile default --bucket my-bucket --notification-configuration file://notification.json`

with notification.json file

{
  "TopicConfigurations": [
  ],
  "QueueConfigurations": [
    {
      "QueueArn": "arn:aws:sqs:eu-west-1:123456789012:my-queue",
      "Events": [
        "s3:ObjectCreated:*"
      ],
      "Filter": {
        "Key": {
          "FilterRules": [
            {
              "Name": "prefix",
              "Value": "my-filter"
            }
          ]
        }
      }
    }
  ],
  "LambdaFunctionConfigurations": [
  ]
}

I really don't know where the error is. Thanks for any help!

+4
source share
3 answers

, SQS . Id Resource . - :

{ "DelaySeconds":"0", "MessageRetentionPeriod":"3600", "Policy":"{\"Id\":\"someid\",\"Statement\":[{\"Effect\":\"Allow\",\"Resource\": \"arn:aws:sqs:eu-west-1:123456789012:my-queue\",\"Principal\":\"*\",\"Action\":[\"sqs:SendMessage\",\"sqs:ReceiveMessage\"],\"Condition\":{\"ArnLike\": {\"aws:SourceArn\": \"arn:aws:s3:*:*:my-bucket\"}}}]}" }

:

http://docs.aws.amazon.com/AmazonS3/latest/dev/ways-to-add-notification-config-to-bucket.html#step1-create-sqs-queue-for-notification

API --debug. :

aws --debug s3api ...

+1

script, . , : -)

#!/usr/bin/env python

import boto3
import json

bucket_name='spike-bucket-000'
queue_name='spike_queue_000'
region='eu-west-1'

s3 = boto3.client('s3', region)
sqs = boto3.client('sqs', region)

def check_if_bucket_exists(name):
    s3.head_bucket(Bucket=bucket_name)


try:
    check_if_bucket_exists(bucket_name)
    print('Bucket {} exists'.format(bucket_name))
except botocore.exceptions.ClientError:
    print('Creating bucket {}'.format(bucket_name))
    s3.create_bucket(Bucket=bucket_name, CreateBucketConfiguration={'LocationConstraint': region})

print('Ensuring queue {} exists'.format(queue_name))

response = sqs.create_queue(QueueName=queue_name)
queue_url = response['QueueUrl']
response = sqs.get_queue_attributes(QueueUrl=queue_url, AttributeNames=['QueueArn'])
queue_arn = response['Attributes']['QueueArn']

print('Granting bucket permission to post messages to queue')

queue_policy={
         "Version": "2008-10-17",
         "Id": "example-ID",
         "Statement": [
          {
           "Sid": "example-statement-ID",
           "Effect": "Allow",
           "Principal": {
            "AWS":"*"
           },
           "Action": [
            "SQS:SendMessage"
           ],
           "Resource": queue_arn,
           "Condition": {
              "ArnLike": {
              "aws:SourceArn": "arn:aws:s3:*:*:" + bucket_name
            }
           }
          }
         ]
        }

sqs.set_queue_attributes(QueueUrl=queue_url, Attributes={'Policy': json.dumps(queue_policy)})

print('Configuring bucket to notify object creation to queue')

response = s3.put_bucket_notification_configuration(
    Bucket=bucket_name,
    NotificationConfiguration={
        'QueueConfigurations': [
            {
                'Id': 'Notify-ObjectCreated-To-Queue',
                'QueueArn': queue_arn,
                'Events': [
                    's3:ObjectCreated:*',
                ]
#               ,
#                 'Filter': {
#                     'Key': {
#                         'FilterRules': [
#                             {
#                                 'Name': 'prefix'|'suffix',
#                                 'Value': 'string'
#                             },
#                         ]
#                     }
#}
            },
        ]
    }
)
0

: ; , ( , - Invoke: )

0

Source: https://habr.com/ru/post/1622110/


All Articles