2013-10-12 7 views
5

निम्नलिखित कोड के साथ, मैं अपने एडब्ल्यूएस खाता संख्या का उपयोग कर अनुमति जोड़ सकता हूं लेकिन कतार को एसएनएस से कोई संदेश नहीं मिलता है।मैं एडब्ल्यूएस एसक्यूएस कतार पर अनुमति कैसे जोड़ूं?

AddPermissionRequest addPermissionRequest = new AddPermissionRequest(); 
addPermissionRequest.ActionName.Add("SendMessage"); 
addPermissionRequest.ActionName.Add("ReceiveMessage"); 
addPermissionRequest.QueueUrl = queueUrl; 
addPermissionRequest.Label = General.IpAddressAWSFriendly; 
addPermissionRequest.AWSAccountId.Add(AWS_ACCOUNT_ID); 
sqs.AddPermission(addPermissionRequest); 

लेकिन, जब मैं हर किसी के लिए एक वाइल्डकार्ड (*) के माध्यम से अनुमति सेट करने का प्रयास करें:

addPermissionRequest.AWSAccountId.Add("*"); 

यह मुझे एक त्रुटि देता है। मैं मैन्युअल रूप से एडब्ल्यूएस SQS कंसोल में अनुमति जोड़ सकते हैं और

SendMessage 
ReceiveMessage 
अनुमति कार्यों के लिए और सिद्धांत के लिए

निर्दिष्ट करते हैं, मैं इसे सेट "हर कोई", कतार मेरी एसएनएस विषय से संदेश प्राप्त करता है। तो, जाहिर है, मैं कुछ गलत कर रहा हूं लेकिन अब मैं इसे नहीं देख रहा हूं।

कोई भी मदद महान होगी! मेरी इच्छा है कि अमेज़ॅन के उदाहरण होंगे, उदाहरण के लिए एसडीके के साथ आता है नीतियों या अनुमतियों को सेट करने के बारे में कुछ भी नहीं दिखाता है। ऑनलाइन दस्तावेज में कुछ भी नहीं दिखाया गया है, या तो। निराशा होती।

उत्तर

10

सौभाग्य से, मैंने इसे खुद से समझ लिया क्योंकि मुझे यहां कोई प्रतिक्रिया नहीं मिली है। मैं वास्तव में चाहता हूं कि अमेज़ॅन सी # डेवलपर्स के लिए नेट फ्रेमवर्क पर बेहतर दस्तावेज प्रदान करेगी न केवल स्क्रिप्ट किड्स के लिए।

वैसे भी, मैंने एक पूर्ण उड़ा नीति वस्तु तैयार की और एसक्यूएस को पास कर दिया। मैंने एडब्ल्यूएस एसडीके v1.5 संस्करण का उपयोग किया और न कि नया 2.0 (अभी बीटा में) क्योंकि यह अभी काम करता है और मैं इसे नए 2.0 संस्करण में बदलने के लिए बहुत आलसी था।

 // 4. Set the queue policy to allow SNS to publish messages 
     ActionIdentifier[] actions = new ActionIdentifier[2]; 
     actions[0] = SQSActionIdentifiers.SendMessage; 
     actions[1] = 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); 

मुझे आशा है कि यह किसी को मदद मिलती है:

यहाँ कोड का सा आप प्रोग्राम के लिए एक शर्त के साथ एक SQS कतार के लिए सी # में एक नीति बनाने की आवश्यकता होगी केवल एक एसएनएस विषय के साथ कि कतार का उपयोग करें।

+0

सिर्फ मैं तुम्हारे साथ नहीं एक बड़ी राशि इस बात से सहमत है, जब यह उदाहरण के लिए आता है कहने के लिए - मैं कैसे स्थापित करने के लिए जांच कर रहे किया गया है - ReceiveMessageWaitTimeSeconds और मैं सिर्फ एक ईंट की दीवार से टकराने रखने - मैं इसे कंसोल में कर सकता हूं लेकिन इसे सेट करने के तरीके पर कोड उदाहरण नहीं मिल सकता - मैंने सोचा कि यह सीधे आगे होगा! – anna

+0

@anna लगता है जैसे आप एसक्यूएस कतारों पर लंबे मतदान करने की कोशिश कर रहे हैं। आप किस विशिष्ट मुद्दे में भागते हैं? क्या आपने एक एसओ सवाल पोस्ट किया था? शायद मैं मदद कर सकता हूँ। –

+0

मैं लंबे मतदान करने की कोशिश कर रहा हूं, मुझे पता है कि इसे मैन्युअल रूप से कैसे सेट किया जाए, लेकिन जब मैं कोड में कतार बना रहा हूं तो मुझे इसे सेट करने की आवश्यकता है, मेरे पास यह है जो कतार var sqsRequest = new CreateQueueRequest() बनाता है; sqsRequest.QueueName = "Bin2AutomationQ"; var createQueueResponse = sqs.CreateQueue (sqsRequest); myQueueUrl = createQueueResponse.CreateQueueResult।QueueUrl; लेकिन यह सुनिश्चित नहीं है कि ReceiveMessageWaitTimeSeconds को 20 – anna

1

यहाँ कैसे amazonica साथ Clojure में यह करना है:

(require '[amazonica.aws.sqs :as sqs] 
     '[amazonica.core :as aws) 
(import '(com.amazonaws.auth.policy Statement Statement$Effect 
            Principal 
            Policy 
            Resource 
            Condition 
            Action) 
     '(com.amazonaws.auth.policy.actions SQSActions) 
     '(com.amazonaws.auth.policy.conditions ConditionFactory)) 

(aws/defcredential "access-key" "secret-key" "us-east-1") 

(def topic-arn "arn:aws:sns:us-east-1:123:foo") 
(def queue-url "https://sqs.us-east-1.amazonaws.com/123/bar") 
(def queue-arn (-> queue-url sqs/get-queue-attributes :QueueArn)) 

(def policy (Policy. 
        (str queue-arn "/SQSDefaultPolicy") 
        [(doto (Statement. Statement$Effect/Allow) 
         (.setPrincipals [Principal/AllUsers]) 
         (.setResources [(Resource. queue-arn)]) 
         (.setConditions [(ConditionFactory/newSourceArnCondition topic-arn)]) 
         (.setActions [SQSActions/SendMessage]))])) 

(sqs/set-queue-attributes queue-url {"Policy" (.toJson policy)}) 
0

यहाँ कैसे मैं गुमनाम फिरते एक कतार बना पढ़ने की पहुंच है। बस जरूरत के रूप में अतिरिक्त ActionIdentifiers जोड़ें:

public static String TestQueueCreate(String name) { 

     AmazonSQSClient sqs = new AmazonSQSClient(region: Amazon.RegionEndpoint.USEast1); 
     CreateQueueResponse create = sqs.CreateQueue(name); 

     Policy policy = new Policy() { 
      Statements = new List<Statement>() { 
       new Statement(StatementEffect.Allow) { 
        Principals = new List<Principal>() { Principal.AllUsers }, 
        Actions = new List<ActionIdentifier>() { SQSActionIdentifiers.ReceiveMessage } 
       } 
      } 
     }; 

     Dictionary<String,String> queueAttributes = new Dictionary<String, String>(); 
     queueAttributes.Add(QueueAttributeName.Policy.ToString(), policy.ToJson()); 
     sqs.SetQueueAttributes(new SetQueueAttributesRequest(create.QueueUrl, queueAttributes)); 

     return create.QueueUrl; 
    } 
1

पिछला संसाधन जो अपेक्षा के अनुरूप काम नहीं किया था बिना अनुमति बनाया। यहाँ एक सुधार अर्न प्राप्त करने के लिए है:

public static String TestQueueCreate(String name) { 

     AmazonSQSClient sqs = new AmazonSQSClient(region: Amazon.RegionEndpoint.USEast1); 
     CreateQueueResponse create = sqs.CreateQueue(name); 

     String arn = sqs.GetQueueAttributes(create.QueueUrl, new List<String>() { "QueueArn" }).Attributes["QueueArn"]; 

     Policy policy = new Policy() { 
      Statements = new List<Statement>() { 
       new Statement(StatementEffect.Allow) { 
        Principals = new List<Principal>() { new Principal("*") }, 
        Actions = new List<ActionIdentifier>() { 
         new ActionIdentifier("SQS:ReceiveMessage"), 
         new ActionIdentifier("SQS:SendMessage") 
        }, 
        Resources = new List<Resource>() { new Resource(arn) } 
       } 
      }, 

     }; 

     Dictionary<String,String> queueAttributes = new Dictionary<String, String>(); 
     queueAttributes.Add(QueueAttributeName.Policy.ToString(), policy.ToJson()); 
     sqs.SetQueueAttributes(new SetQueueAttributesRequest(create.QueueUrl, queueAttributes)); 

     return create.QueueUrl; 
    } 
संबंधित मुद्दे