Search code examples
iosswiftamazon-web-servicesamazon-sqspolicy

Amazon SQS/SNS policy error


I'm trying to add a policy to Amazon SQS queue. The policy allows SNS topic to send messages to SQS queue. When i apply the policy through to SQS console, it works perfectly. But when i try to add the same policy through iOS SDK, the SDK returns an error saying "The specified queue does not exist for this wsdl version. Code=AWS.SimpleQueueService.NonExistentQueue" Any help will be appreciated. Following are the code and the policy im trying to apply.

    let request = AWSSQSSetQueueAttributesRequest();
    request.attributes = ["Policy":self.Policy(User.queue_arn, topicARN:User.topic_arn)]

    AWSSQS.defaultSQS().setQueueAttributes(request, completionHandler: { (error:NSError?) -> Void in

                    if error == nil
                    {
                        RegisterationManager.DefaultManager().SetStatus(RegisterationStatus.DYNAMODB_PENDINIG)
                        self.FinalizeDynamoDB()
                    }
                    else
                    {
                        print(error)
                        self.ShowLoggerView("Unknown Error !", error:error)
                    }
                })

//Policy

{
        "Version": "2012-10-17",
        "Id": "SNStoSQS",
        "Statement":
        {
        "Sid":"rule1",
        "Effect": "Allow",
        "Principal": "*",
        "Action": "sqs:*",
        "Resource": "queue-arn-here",
        "Condition" : {
        "ArnEquals" : {
        "aws:SourceArn":"topic-arn-here"
        }
        }
        }
        }

Solution

  • My mistake, i wasn't specifying the queue url in the request. The code should look like following.

    let request = AWSSQSSetQueueAttributesRequest();
    request.queueUrl = "your queue url"
    request.attributes = ["Policy":self.Policy(User.queue_arn, topicARN:User.topic_arn)]