将 S3 设置为 post 创建新项目时通知 SQS

Setting S3 to post notifications to SQS when new item is created

我正在尝试做(应该做的)一项简单的任务。

我无法附加这两个。

我已经创建了队列,它运行良好。我已经创建了存储桶,它运行良好。

现在我正在尝试向队列添加一个策略,让存储桶发送通知。

遵循本指南:

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

我正在尝试调用此方法:

  public SetQueueAttributesResponse SetQueueAttributes(Dictionary<string, string> attributes)
    {
        var setQueueAttributesRequest = new SetQueueAttributesRequest()
        {
            QueueUrl = QueueUri.ToString(),
            Attributes = attributes
        };

        return SqsClient.SetQueueAttributes(setQueueAttributesRequest);
    }

属性 属性 有一个 key/value 对:

Policy

{
"Version" : "7/5/2017",
"Id"      : "S3-Post",
"Statement" : [
    {
        "Sid" : "S3-Post",
        "Effect" : "Allow",
        "Principal" : {
            "AWS" : "*"
        },
        "Action"    : [
            "sqs:SendMessage",
            "sqs:GetQueueUrl"
        ],
        "Resource"  : "arn:aws:sqs:us-west-2:[REDACTED]:testqueue2",
        "Condition" : {
            "ArnLike" : {
                "aws:SourceArn" : "arn:aws:s3:*:*:*"
            }
        }
    }
]

}

(是的,我稍微放宽了过滤条件,但在建立存储桶名称时遇到了同样的失败。)

我得到这个异常:

Amazon.SQS.AmazonSQSException was unhandled

ErrorCode=InvalidAttributeValue

HResult=-2146233088

Message=Invalid value for the parameter Policy.

RequestId=0ac6201a-17f5-5b63-a5ac-71cd42b10481

Source=AWSSDK.Core

任何人都可以看到我的错误,或者任何人都可以指出一个更实用的示例吗?

Version 指的是正在使用的 IAM 策略语言的版本,而不是您的策略的修订版。

您只想使用一个值:"2012-10-17"

http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#Version