示例#1
0
        protected override bool Execute(AmazonSQS client)
        {
            Log.LogMessage(MessageImportance.Normal, "Granting SendMessage rights to SQS Queue at {0}", QueueUrl);

            string queueArn = GetQueueArn(client, QueueUrl);

            Log.LogMessage(MessageImportance.Low, "Queue {0} Arn: {1}", QueueUrl, queueArn);

            var request = new SetQueueAttributesRequest {
                QueueUrl = QueueUrl
            };
            var attribute = new Attribute {
                Name = "Policy", Value = ConstructPolicy(queueArn, SourceArn)
            };

            request.Attribute = new List <Attribute> {
                attribute
            };

            client.SetQueueAttributes(request);

            Logger.LogMessage(MessageImportance.Normal, "Granted rights for source {0} to SendMessage to SQS at {1}", SourceArn, QueueUrl);

            return(true);
        }
示例#2
0
        private void setMaximumMessageSize(String queueUrl)
        {
            Amazon.SQS.Model.Attribute[] attrs = new Amazon.SQS.Model.Attribute[1];
            attrs[0] = new Amazon.SQS.Model.Attribute().WithName("MaximumMessageSize").WithValue("65536");
            SetQueueAttributesRequest request = new SetQueueAttributesRequest().WithQueueUrl(queueUrl).WithAttribute(attrs);

            sqs.SetQueueAttributes(request);
        }
        public Uri CreateOrRetrieveQueue(string name)
        {
            Validate.That(name).IsNotNullOrEmpty();

            var longPollAttribute = new Attribute().WithName(receiveMessageWaitTimeSecondsAttributeName)
                .WithValue(Convert.ToString(receiveMessageWaitTimeSeconds));
            var messageRetainAttribute = new Attribute().WithName(messageRetentionPeriodAttributeName)
                .WithValue(Convert.ToString(messageRetentionPeriodSeconds));
            var sqsRequest = new CreateQueueRequest().WithQueueName(name).WithAttribute(longPollAttribute, messageRetainAttribute);
            using (var sqs = amazonSqsFactory())
            {
                var createQueueResponse = sqs.CreateQueue(sqsRequest);
                return new Uri(createQueueResponse.CreateQueueResult.QueueUrl);
            }
        }
示例#4
0
        public Uri CreateOrRetrieveQueue(string name)
        {
            Validate.That(name).IsNotNullOrEmpty();

            var longPollAttribute = new Attribute().WithName(receiveMessageWaitTimeSecondsAttributeName)
                                    .WithValue(Convert.ToString(receiveMessageWaitTimeSeconds));
            var messageRetainAttribute = new Attribute().WithName(messageRetentionPeriodAttributeName)
                                         .WithValue(Convert.ToString(messageRetentionPeriodSeconds));
            var sqsRequest = new CreateQueueRequest().WithQueueName(name).WithAttribute(longPollAttribute, messageRetainAttribute);

            using (var sqs = amazonSqsFactory())
            {
                var createQueueResponse = sqs.CreateQueue(sqsRequest);
                return(new Uri(createQueueResponse.CreateQueueResult.QueueUrl));
            }
        }
        protected override bool Execute(AmazonSQS client)
        {
            Log.LogMessage(MessageImportance.Normal, "Granting SendMessage rights to SQS Queue at {0}", QueueUrl);

            string queueArn = GetQueueArn(client, QueueUrl);
            Log.LogMessage(MessageImportance.Low, "Queue {0} Arn: {1}", QueueUrl, queueArn);

            var request = new SetQueueAttributesRequest { QueueUrl = QueueUrl };
            var attribute = new Attribute { Name = "Policy", Value = ConstructPolicy(queueArn, SourceArn) };
            request.Attribute = new List<Attribute> { attribute };

            client.SetQueueAttributes(request);

            Logger.LogMessage(MessageImportance.Normal, "Granted rights for source {0} to SendMessage to SQS at {1}", SourceArn, QueueUrl);

            return true;
        }
示例#6
0
        public void create_sqs_queue()
        {
            GetUserNameAndPassword();
            var sqsClient = Amazon.AWSClientFactory.CreateAmazonSQSClient(_key, _secret);
            var snsTopic = Amazon.AWSClientFactory.CreateAmazonSNSClient(_key, _secret);
            var topicArn = "arn:aws:sns:us-east-1:451419498740:Elliott-has-an-awesome-blog";
            //Create a new SQS queue
            var createQueueRequest = new CreateQueueRequest().WithQueueName("elliotts-blog");
            var createQueueResponse = sqsClient.CreateQueue(createQueueRequest);
            // keep the queueUrl handy
            var queueUrl = createQueueResponse.CreateQueueResult.QueueUrl;
            // get the Access Resource Name so we can allow the SNS to put messages on it
            var getQueueArnRequest = new GetQueueAttributesRequest()
                .WithQueueUrl(queueUrl)
                .WithAttributeName("QueueArn");
            var getQueueArnResponse = sqsClient.GetQueueAttributes(getQueueArnRequest);
            var queueArn = getQueueArnResponse.GetQueueAttributesResult.Attribute[0].Value;

            //create a Policy for the SQS queue that allows SNS to publish to it
            var allowSnsStatement = new Statement(Statement.StatementEffect.Allow)
                .WithPrincipals(Principal.AllUsers)
                .WithResources(new Resource(queueArn))
                .WithConditions(ConditionFactory.NewSourceArnCondition(topicArn))
                .WithActionIdentifiers(SQSActionIdentifiers.SendMessage);
            var policy = new Policy("allow sns").WithStatements(new[] {allowSnsStatement});
            var attribute = new Attribute().WithName("Policy").WithValue(policy.ToJson());
            var setQueueAttributesRequest =
                new SetQueueAttributesRequest().WithQueueUrl(queueUrl).WithAttribute(attribute);
            sqsClient.SetQueueAttributes(setQueueAttributesRequest);

            // ok, now lets create the subscription for sqs with the queueArn we created
            var subscribeRequest = new SubscribeRequest()
                .WithEndpoint(queueArn)
                .WithTopicArn(topicArn)
                .WithProtocol("sqs");

            snsTopic.Subscribe(subscribeRequest);
        }
示例#7
0
        public static bool Add_Q_Premissions_Everybody(String Q_url)
        {
            String sid = "\"Sid\":\"" + Q_url + "\"";
            String effect = "\"Effect\":\"Allow\"";
            String pricipal = "\"Principal\":{\"AWS\":\"*\"}";
            String action = "\"Action\":\"SQS:*\"";
            String Q_arn;
            if (!Get_Q_arn(Q_url, out Q_arn)) return false;
            String resource = "\"Resource\":\"" + Q_arn + "\"";

            String myPolicy = "{\"Version\":\"2008-10-17\",\"Id\":\"" + Q_arn + "/SQSDefaultPolicy\",\"Statement\":[{" +
                sid + "," + effect + "," + pricipal + "," + action + "," + resource + "}]}";
            SetQueueAttributesRequest sqa_request = new SetQueueAttributesRequest();
            sqa_request.Attribute = new List<Amazon.SQS.Model.Attribute>();
            Amazon.SQS.Model.Attribute att = new Amazon.SQS.Model.Attribute();
            att.Name = "Policy";
            att.Value = myPolicy;

            sqa_request.Attribute.Add(att);
            sqa_request.QueueUrl = Q_url;
            SetQueueAttributesResponse sqa_response = sqs_client.SetQueueAttributes(sqa_request);
            return true;
        }
 private void setMaximumMessageSize(String queueUrl)
 {
     Amazon.SQS.Model.Attribute[] attrs = new Amazon.SQS.Model.Attribute[1];
     attrs[0] = new Amazon.SQS.Model.Attribute().WithName("MaximumMessageSize").WithValue("65536");
     SetQueueAttributesRequest request = new SetQueueAttributesRequest().WithQueueUrl(queueUrl).WithAttribute(attrs);
     sqs.SetQueueAttributes(request);
 }
示例#9
0
        /// <summary>
        /// Allow a Sns notification to publish to the queue
        /// </summary>
        /// <seealso cref="http://www.elastician.com/2010/04/subscribing-sqs-queue-to-sns-topic.html"/>
        public void GrantSendMessageRights(string queueUrl, string sourceArn)
        {
            string queueArn = GetQueueArn(queueUrl);

            var request = new SetQueueAttributesRequest { QueueUrl = queueUrl };
            var attribute = new Attribute { Name = "Policy", Value = ConstructPolicy(queueArn, sourceArn) };
            request.Attribute = new List<Attribute> { attribute };

            Client.SetQueueAttributes(request);
        }