public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.S3.Model.PutBucketNotificationRequest(); if (cmdletContext.BucketName != null) { request.BucketName = cmdletContext.BucketName; } if (cmdletContext.TopicConfiguration != null) { request.TopicConfigurations = cmdletContext.TopicConfiguration; } if (cmdletContext.QueueConfiguration != null) { request.QueueConfigurations = cmdletContext.QueueConfiguration; } if (cmdletContext.LambdaFunctionConfiguration != null) { request.LambdaFunctionConfigurations = cmdletContext.LambdaFunctionConfiguration; } if (cmdletContext.ExpectedBucketOwner != null) { request.ExpectedBucketOwner = cmdletContext.ExpectedBucketOwner; } if (cmdletContext.SkipDestinationValidation != null) { request.SkipDestinationValidation = cmdletContext.SkipDestinationValidation.Value; } if (cmdletContext.EventBridgeConfiguration != null) { request.EventBridgeConfiguration = cmdletContext.EventBridgeConfiguration; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return(output); }
public void SetTopicConfigurationTests() { var s3Config = new AmazonS3Config(); using (var s3Client = new AmazonS3Client(s3Config)) using (var snsClient = new AmazonSimpleNotificationServiceClient()) { var snsCreateResponse = snsClient.CreateTopic("events-test-" + DateTime.Now.Ticks); var bucketName = S3TestUtils.CreateBucket(s3Client); try { snsClient.AuthorizeS3ToPublish(snsCreateResponse.TopicArn, bucketName); PutBucketNotificationRequest putRequest = new PutBucketNotificationRequest { BucketName = bucketName, TopicConfigurations = new List<TopicConfiguration> { new TopicConfiguration { Id = "the-topic-test", Topic = snsCreateResponse.TopicArn, Events = new List<EventType>{EventType.ObjectCreatedPut} } } }; s3Client.PutBucketNotification(putRequest); var getResponse = s3Client.GetBucketNotification(bucketName); Assert.AreEqual(1, getResponse.TopicConfigurations.Count); Assert.AreEqual(1, getResponse.TopicConfigurations[0].Events.Count); Assert.AreEqual(EventType.ObjectCreatedPut, getResponse.TopicConfigurations[0].Events[0]); #pragma warning disable 618 Assert.AreEqual("s3:ObjectCreated:Put", getResponse.TopicConfigurations[0].Event); #pragma warning restore 618 Assert.AreEqual("the-topic-test", getResponse.TopicConfigurations[0].Id); Assert.AreEqual(snsCreateResponse.TopicArn, getResponse.TopicConfigurations[0].Topic); } finally { snsClient.DeleteTopic(snsCreateResponse.TopicArn); AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName); } } }
/// <summary> /// Initiates the asynchronous execution of the PutBucketNotification operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutBucketNotification operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<PutBucketNotificationResponse> PutBucketNotificationAsync(PutBucketNotificationRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new PutBucketNotificationRequestMarshaller(); var unmarshaller = PutBucketNotificationResponseUnmarshaller.Instance; return InvokeAsync<PutBucketNotificationRequest,PutBucketNotificationResponse>(request, marshaller, unmarshaller, cancellationToken); }
internal PutBucketNotificationResponse PutBucketNotification(PutBucketNotificationRequest request) { var marshaller = new PutBucketNotificationRequestMarshaller(); var unmarshaller = PutBucketNotificationResponseUnmarshaller.Instance; return Invoke<PutBucketNotificationRequest,PutBucketNotificationResponse>(request, marshaller, unmarshaller); }
IAsyncResult invokePutBucketNotification(PutBucketNotificationRequest putBucketNotificationRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new PutBucketNotificationRequestMarshaller().Marshall(putBucketNotificationRequest); var unmarshaller = PutBucketNotificationResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// Initiates the asynchronous execution of the PutBucketNotification operation. /// <seealso cref="Amazon.S3.IAmazonS3.PutBucketNotification"/> /// </summary> /// /// <param name="putBucketNotificationRequest">Container for the necessary parameters to execute the PutBucketNotification operation on /// AmazonS3.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> public IAsyncResult BeginPutBucketNotification(PutBucketNotificationRequest putBucketNotificationRequest, AsyncCallback callback, object state) { return invokePutBucketNotification(putBucketNotificationRequest, callback, state, false); }
/// <summary> /// <para>Enables notifications of specified events for a bucket.</para> /// </summary> /// /// <param name="putBucketNotificationRequest">Container for the necessary parameters to execute the PutBucketNotification service method on /// AmazonS3.</param> /// public PutBucketNotificationResponse PutBucketNotification(PutBucketNotificationRequest putBucketNotificationRequest) { IAsyncResult asyncResult = invokePutBucketNotification(putBucketNotificationRequest, null, null, true); return EndPutBucketNotification(asyncResult); }
private Amazon.S3.Model.PutBucketNotificationResponse CallAWSServiceOperation(IAmazonS3 client, Amazon.S3.Model.PutBucketNotificationRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Storage Service (S3)", "PutBucketNotification"); try { #if DESKTOP return(client.PutBucketNotification(request)); #elif CORECLR return(client.PutBucketNotificationAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
/// <summary> /// Initiates the asynchronous execution of the PutBucketNotification operation. /// This API is supported only when AWSConfigs.HttpClient is set to AWSConfigs.HttpClientOption.UnityWebRequest, the default value for this configuration option is AWSConfigs.HttpClientOption.UnityWWW /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutBucketNotification operation on AmazonS3Client.</param> /// <param name="callback">An Action delegate that is invoked when the operation completes.</param> /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> public void PutBucketNotificationAsync(PutBucketNotificationRequest request, AmazonServiceCallback<PutBucketNotificationRequest, PutBucketNotificationResponse> callback, AsyncOptions options = null) { if (AWSConfigs.HttpClient == AWSConfigs.HttpClientOption.UnityWWW) { throw new InvalidOperationException("PutBucketNotification is only allowed with AWSConfigs.HttpClientOption.UnityWebRequest API option"); } options = options == null?new AsyncOptions():options; var marshaller = new PutBucketNotificationRequestMarshaller(); var unmarshaller = PutBucketNotificationResponseUnmarshaller.Instance; Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null; if(callback !=null ) callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { AmazonServiceResult<PutBucketNotificationRequest,PutBucketNotificationResponse> responseObject = new AmazonServiceResult<PutBucketNotificationRequest,PutBucketNotificationResponse>((PutBucketNotificationRequest)req, (PutBucketNotificationResponse)res, ex , ao.State); callback(responseObject); }; BeginInvoke<PutBucketNotificationRequest>(request, marshaller, unmarshaller, options, callbackHelper); }
/// <summary> /// Initiates the asynchronous execution of the PutBucketNotification operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutBucketNotification operation on AmazonS3Client.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndPutBucketNotification /// operation.</returns> public IAsyncResult BeginPutBucketNotification(PutBucketNotificationRequest request, AsyncCallback callback, object state) { var marshaller = new PutBucketNotificationRequestMarshaller(); var unmarshaller = PutBucketNotificationResponseUnmarshaller.Instance; return BeginInvoke<PutBucketNotificationRequest>(request, marshaller, unmarshaller, callback, state); }
/// <summary> /// Initiates the asynchronous execution of the PutBucketNotification operation. /// <seealso cref="Amazon.S3.IAmazonS3.PutBucketNotification"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutBucketNotification operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<PutBucketNotificationResponse> PutBucketNotificationAsync(PutBucketNotificationRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new PutBucketNotificationRequestMarshaller(); var unmarshaller = PutBucketNotificationResponseUnmarshaller.GetInstance(); return Invoke<IRequest, PutBucketNotificationRequest, PutBucketNotificationResponse>(request, marshaller, unmarshaller, signer, cancellationToken); }
/// <summary> /// <para>Enables notifications of specified events for a bucket.</para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutBucketNotification service method on /// AmazonS3.</param> public PutBucketNotificationResponse PutBucketNotification(PutBucketNotificationRequest request) { var task = PutBucketNotificationAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
/// <summary> /// <para>Enables notifications of specified events for a bucket.</para> /// </summary> /// /// <param name="putBucketNotificationRequest">Container for the necessary parameters to execute the PutBucketNotification service method on /// AmazonS3.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public async Task<PutBucketNotificationResponse> PutBucketNotificationAsync(PutBucketNotificationRequest putBucketNotificationRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new PutBucketNotificationRequestMarshaller(); var unmarshaller = PutBucketNotificationResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, PutBucketNotificationRequest, PutBucketNotificationResponse>(putBucketNotificationRequest, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
public void SetQueueConfigurationTests() { var filterRule = new FilterRule("Prefix", "test/"); var s3Config = new AmazonS3Config(); using (var s3Client = new AmazonS3Client(s3Config)) using (var sqsClient = new AmazonSQSClient()) { var createResponse = sqsClient.CreateQueue("events-test-" + DateTime.Now.Ticks); var bucketName = S3TestUtils.CreateBucket(s3Client); try { var queueArn = sqsClient.AuthorizeS3ToSendMessage(createResponse.QueueUrl, bucketName); PutBucketNotificationRequest putRequest = new PutBucketNotificationRequest { BucketName = bucketName, QueueConfigurations = new List<QueueConfiguration> { new QueueConfiguration { Id = "the-queue-test", Queue = queueArn, Events = {EventType.ObjectCreatedPut}, Filter = new Filter { S3KeyFilter = new S3KeyFilter { FilterRules = new List<FilterRule> { filterRule } } } } } }; s3Client.PutBucketNotification(putRequest); var getResponse = s3Client.GetBucketNotification(bucketName); Assert.AreEqual(1, getResponse.QueueConfigurations.Count); Assert.AreEqual(1, getResponse.QueueConfigurations[0].Events.Count); Assert.AreEqual(EventType.ObjectCreatedPut, getResponse.QueueConfigurations[0].Events[0]); Assert.IsNotNull(getResponse.QueueConfigurations[0].Filter); Assert.IsNotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter); Assert.IsNotNull(getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules); Assert.AreEqual(1, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules.Count); Assert.AreEqual(filterRule.Name, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Name); Assert.AreEqual(filterRule.Value, getResponse.QueueConfigurations[0].Filter.S3KeyFilter.FilterRules[0].Value); Assert.AreEqual("the-queue-test", getResponse.QueueConfigurations[0].Id); Assert.AreEqual(queueArn, getResponse.QueueConfigurations[0].Queue); // Purge queue to remove test message sent configuration was setup. sqsClient.PurgeQueue(createResponse.QueueUrl); Thread.Sleep(TimeSpan.FromSeconds(1)); var putObjectRequest = new PutObjectRequest { BucketName = bucketName, Key = "test/data.txt", ContentBody = "Important Data" }; s3Client.PutObject(putObjectRequest); string messageBody = null; for (int i = 0; i < 5 && messageBody == null; i++) { var receiveResponse = sqsClient.ReceiveMessage(new ReceiveMessageRequest { QueueUrl = createResponse.QueueUrl, WaitTimeSeconds = 20 }); if (receiveResponse.Messages.Count != 0) { messageBody = receiveResponse.Messages[0].Body; } } var evnt = S3EventNotification.ParseJson(messageBody); Assert.AreEqual(1, evnt.Records.Count); Assert.AreEqual(putObjectRequest.BucketName, evnt.Records[0].S3.Bucket.Name); Assert.AreEqual(putObjectRequest.Key, evnt.Records[0].S3.Object.Key); Assert.AreEqual(putObjectRequest.ContentBody.Length, evnt.Records[0].S3.Object.Size); } finally { sqsClient.DeleteQueue(createResponse.QueueUrl); AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName); } } }
/// <summary> /// <para>Enables notifications of specified events for a bucket.</para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutBucketNotification service method on /// AmazonS3.</param> public PutBucketNotificationResponse PutBucketNotification(PutBucketNotificationRequest request) { var task = PutBucketNotificationAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }