With the following code, I can add a permission using my AWS account number but the queue does not receive any messages from SNS.
AddPermissionRequest addPermissionRequest = new AddPermissionRequest();
addPermissionRequest.QueueUrl = queueUrl;
addPermissionRequest.Label = General.IpAddressAWSFriendly;
Fortunately, I figured it out myself since I received no responses here. I really wish Amazon would provide better documentation for C# developers on the .Net framework and not just for script kiddies.
Anyways, I ended up creating a full blown Policy object and passed that to the SQS. I used the AWS SDK v1.5 version and not the newer 2.0 (in beta right now) simply because it works for now and I was too lazy to change it to the newer 2.0 version.
Here is the bit of code you will need to programmatically create a policy in C# for an SQS Queue with a condition to only use that queue with an SNS topic:
// 4. Set the queue policy to allow SNS to publish messages ActionIdentifier actions = new ActionIdentifier; actions = SQSActionIdentifiers.SendMessage; actions = SQSActionIdentifiers.ReceiveMessage; Policy sqsPolicy = new Policy() .WithStatements(new Statement(Statement.StatementEffect.Allow) .WithPrincipals(Principal.AllUsers) .WithResources(new Resource(queueArn)) .WithConditions(ConditionFactory.NewSourceArnCondition(_AWSSNSArn)) .WithActionIdentifiers(actions)); SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest(); List<Amazon.SQS.Model.Attribute> attributes = new List<Amazon.SQS.Model.Attribute>(); Amazon.SQS.Model.Attribute attribute = new Amazon.SQS.Model.Attribute(); attribute.Name = "Policy"; attribute.Value = sqsPolicy.ToJson(); attributes.Add(attribute); setQueueAttributesRequest.QueueUrl = queueUrl; setQueueAttributesRequest.Attribute = attributes; sqs.SetQueueAttributes(setQueueAttributesRequest);
I hope this helps someone.