public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.S3.Model.PutLifecycleConfigurationRequest(); if (cmdletContext.BucketName != null) { request.BucketName = cmdletContext.BucketName; } // populate Configuration var requestConfigurationIsNull = true; request.Configuration = new Amazon.S3.Model.LifecycleConfiguration(); List <Amazon.S3.Model.LifecycleRule> requestConfiguration_configuration_Rule = null; if (cmdletContext.Configuration_Rule != null) { requestConfiguration_configuration_Rule = cmdletContext.Configuration_Rule; } if (requestConfiguration_configuration_Rule != null) { request.Configuration.Rules = requestConfiguration_configuration_Rule; requestConfigurationIsNull = false; } // determine if request.Configuration should be set to null if (requestConfigurationIsNull) { request.Configuration = null; } 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); }
/// <summary> /// Initiates the asynchronous execution of the PutLifecycleConfiguration operation. /// <seealso cref="Amazon.S3.IAmazonS3.PutLifecycleConfiguration"/> /// </summary> /// /// <param name="putLifecycleConfigurationRequest">Container for the necessary parameters to execute the PutLifecycleConfiguration 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 BeginPutLifecycleConfiguration(PutLifecycleConfigurationRequest putLifecycleConfigurationRequest, AsyncCallback callback, object state) { return invokePutLifecycleConfiguration(putLifecycleConfigurationRequest, callback, state, false); }
/// <summary> /// <para>Sets lifecycle configuration for your bucket. If a lifecycle configuration exists, it replaces it.</para> /// </summary> /// /// <param name="putLifecycleConfigurationRequest">Container for the necessary parameters to execute the PutLifecycleConfiguration service method on /// AmazonS3.</param> /// public PutLifecycleConfigurationResponse PutLifecycleConfiguration(PutLifecycleConfigurationRequest putLifecycleConfigurationRequest) { IAsyncResult asyncResult = invokePutLifecycleConfiguration(putLifecycleConfigurationRequest, null, null, true); return EndPutLifecycleConfiguration(asyncResult); }
/// <summary> /// Initiates the asynchronous execution of the PutLifecycleConfiguration 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 PutLifecycleConfiguration 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 PutLifecycleConfigurationAsync(PutLifecycleConfigurationRequest request, AmazonServiceCallback<PutLifecycleConfigurationRequest, PutLifecycleConfigurationResponse> callback, AsyncOptions options = null) { if (AWSConfigs.HttpClient == AWSConfigs.HttpClientOption.UnityWWW) { throw new InvalidOperationException("PutLifecycleConfiguration is only allowed with AWSConfigs.HttpClientOption.UnityWebRequest API option"); } options = options == null?new AsyncOptions():options; var marshaller = new PutLifecycleConfigurationRequestMarshaller(); var unmarshaller = PutLifecycleConfigurationResponseUnmarshaller.Instance; Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null; if(callback !=null ) callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { AmazonServiceResult<PutLifecycleConfigurationRequest,PutLifecycleConfigurationResponse> responseObject = new AmazonServiceResult<PutLifecycleConfigurationRequest,PutLifecycleConfigurationResponse>((PutLifecycleConfigurationRequest)req, (PutLifecycleConfigurationResponse)res, ex , ao.State); callback(responseObject); }; BeginInvoke<PutLifecycleConfigurationRequest>(request, marshaller, unmarshaller, options, callbackHelper); }
/// <summary> /// Sets lifecycle configuration for your bucket. If a lifecycle configuration exists, /// it replaces it. /// This API is supported only when AWSConfigs.HttpClient is set to AWSConfigs.HttpClientOption.UnityWebRequest, the default value of this configuration option is AWSConfigs.HttpClientOption.UnityWWW /// </summary> /// <param name="bucketName">A property of PutLifecycleConfigurationRequest used to execute the PutLifecycleConfiguration service method.</param> /// <param name="configuration">A property of PutLifecycleConfigurationRequest used to execute the PutLifecycleConfiguration service method.</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> /// /// <returns>The response from the PutLifecycleConfiguration service method, as returned by S3.</returns> public void PutLifecycleConfigurationAsync(string bucketName, LifecycleConfiguration configuration, AmazonServiceCallback<PutLifecycleConfigurationRequest, PutLifecycleConfigurationResponse> callback, AsyncOptions options = null) { var request = new PutLifecycleConfigurationRequest(); request.BucketName = bucketName; request.Configuration = configuration; PutLifecycleConfigurationAsync(request, callback, options); }
private async Task PutLifecycleConfigurationAsync(IAmazonS3 s3Client, LifecycleConfiguration configuration) { var request = new PutLifecycleConfigurationRequest { BucketName = s3ConfigurationProvider.BucketName, Configuration = configuration }; await s3Client.PutLifecycleConfigurationAsync(request); }
public void BucketSamples() { { #region ListBuckets Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Issue call ListBucketsResponse response = client.ListBuckets(); // View response data Console.WriteLine("Buckets owner - {0}", response.Owner.DisplayName); foreach (S3Bucket bucket in response.Buckets) { Console.WriteLine("Bucket {0}, Created on {1}", bucket.BucketName, bucket.CreationDate); } #endregion } { #region BucketPolicy Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Put sample bucket policy (overwrite an existing policy) string newPolicy = @"{ ""Statement"":[{ ""Sid"":""BasicPerms"", ""Effect"":""Allow"", ""Principal"": ""*"", ""Action"":[""s3:PutObject"",""s3:GetObject""], ""Resource"":[""arn:aws:s3:::samplebucketname/*""] }]}"; PutBucketPolicyRequest putRequest = new PutBucketPolicyRequest { BucketName = "SampleBucket", Policy = newPolicy }; client.PutBucketPolicy(putRequest); // Retrieve current policy GetBucketPolicyRequest getRequest = new GetBucketPolicyRequest { BucketName = "SampleBucket" }; string policy = client.GetBucketPolicy(getRequest).Policy; Console.WriteLine(policy); Debug.Assert(policy.Contains("BasicPerms")); // Delete current policy DeleteBucketPolicyRequest deleteRequest = new DeleteBucketPolicyRequest { BucketName = "SampleBucket" }; client.DeleteBucketPolicy(deleteRequest); // Retrieve current policy and verify that it is null policy = client.GetBucketPolicy(getRequest).Policy; Debug.Assert(policy == null); #endregion } { #region GetBucketLocation Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Construct request GetBucketLocationRequest request = new GetBucketLocationRequest { BucketName = "SampleBucket" }; // Issue call GetBucketLocationResponse response = client.GetBucketLocation(request); // View response data Console.WriteLine("Bucket location - {0}", response.Location); #endregion } { #region PutBucket Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Construct request PutBucketRequest request = new PutBucketRequest { BucketName = "SampleBucket", BucketRegion = S3Region.EU, // set region to EU CannedACL = S3CannedACL.PublicRead // make bucket publicly readable }; // Issue call PutBucketResponse response = client.PutBucket(request); #endregion } { #region DeleteBucket Sample 1 // Create a client AmazonS3Client client = new AmazonS3Client(); // Construct request DeleteBucketRequest request = new DeleteBucketRequest { BucketName = "SampleBucket" }; // Issue call DeleteBucketResponse response = client.DeleteBucket(request); #endregion } { #region DeleteBucket Sample 2 // Create a client AmazonS3Client client = new AmazonS3Client(); // List and delete all objects ListObjectsRequest listRequest = new ListObjectsRequest { BucketName = "SampleBucket" }; ListObjectsResponse listResponse; do { // Get a list of objects listResponse = client.ListObjects(listRequest); foreach (S3Object obj in listResponse.S3Objects) { // Delete each object client.DeleteObject(new DeleteObjectRequest { BucketName = "SampleBucket", Key = obj.Key }); } // Set the marker property listRequest.Marker = listResponse.NextMarker; } while (listResponse.IsTruncated); // Construct DeleteBucket request DeleteBucketRequest request = new DeleteBucketRequest { BucketName = "SampleBucket" }; // Issue call DeleteBucketResponse response = client.DeleteBucket(request); #endregion } { #region LifecycleConfiguration Sample // Create a client AmazonS3Client client = new AmazonS3Client(); // Put sample lifecycle configuration (overwrite an existing configuration) LifecycleConfiguration newConfiguration = new LifecycleConfiguration { Rules = new List<LifecycleRule> { // Rule to delete keys with prefix "Test-" after 5 days new LifecycleRule { Prefix = "Test-", Expiration = new LifecycleRuleExpiration { Days = 5 } }, // Rule to delete keys in subdirectory "Logs" after 2 days new LifecycleRule { Prefix = "Logs/", Expiration = new LifecycleRuleExpiration { Days = 2 }, Id = "log-file-removal" } } }; PutLifecycleConfigurationRequest putRequest = new PutLifecycleConfigurationRequest { BucketName = "SampleBucket", Configuration = newConfiguration }; client.PutLifecycleConfiguration(putRequest); // Retrieve current configuration GetLifecycleConfigurationRequest getRequest = new GetLifecycleConfigurationRequest { BucketName = "SampleBucket" }; LifecycleConfiguration configuration = client.GetLifecycleConfiguration(getRequest).Configuration; Console.WriteLine("Configuration contains {0} rules", configuration.Rules.Count); foreach (LifecycleRule rule in configuration.Rules) { Console.WriteLine("Rule"); Console.WriteLine(" Prefix = " + rule.Prefix); Console.WriteLine(" Expiration (days) = " + rule.Expiration.Days); Console.WriteLine(" Id = " + rule.Id); Console.WriteLine(" Status = " + rule.Status); } // Put a new configuration and overwrite the existing configuration configuration.Rules.RemoveAt(0); // remove first rule client.PutLifecycleConfiguration(putRequest); // Delete current configuration DeleteLifecycleConfigurationRequest deleteRequest = new DeleteLifecycleConfigurationRequest { BucketName = "SampleBucket" }; client.DeleteLifecycleConfiguration(deleteRequest); // Retrieve current configuration and verify that it is null configuration = client.GetLifecycleConfiguration(getRequest).Configuration; Debug.Assert(configuration == null); #endregion } }
internal PutLifecycleConfigurationResponse PutLifecycleConfiguration(PutLifecycleConfigurationRequest request) { var marshaller = new PutLifecycleConfigurationRequestMarshaller(); var unmarshaller = PutLifecycleConfigurationResponseUnmarshaller.Instance; return Invoke<PutLifecycleConfigurationRequest,PutLifecycleConfigurationResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the PutLifecycleConfiguration operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutLifecycleConfiguration 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 EndPutLifecycleConfiguration /// operation.</returns> public IAsyncResult BeginPutLifecycleConfiguration(PutLifecycleConfigurationRequest request, AsyncCallback callback, object state) { var marshaller = new PutLifecycleConfigurationRequestMarshaller(); var unmarshaller = PutLifecycleConfigurationResponseUnmarshaller.Instance; return BeginInvoke<PutLifecycleConfigurationRequest>(request, marshaller, unmarshaller, callback, state); }
/// <summary> /// Initiates the asynchronous execution of the PutLifecycleConfiguration operation. /// <seealso cref="Amazon.S3.IAmazonS3.PutLifecycleConfiguration"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutLifecycleConfiguration 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<PutLifecycleConfigurationResponse> PutLifecycleConfigurationAsync(PutLifecycleConfigurationRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new PutLifecycleConfigurationRequestMarshaller(); var unmarshaller = PutLifecycleConfigurationResponseUnmarshaller.GetInstance(); return Invoke<IRequest, PutLifecycleConfigurationRequest, PutLifecycleConfigurationResponse>(request, marshaller, unmarshaller, signer, cancellationToken); }
/// <summary> /// <para>Sets lifecycle configuration for your bucket. If a lifecycle configuration exists, it replaces it.</para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutLifecycleConfiguration service method on /// AmazonS3.</param> public PutLifecycleConfigurationResponse PutLifecycleConfiguration(PutLifecycleConfigurationRequest request) { var task = PutLifecycleConfigurationAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
/// <summary> /// <para>Sets lifecycle configuration for your bucket. If a lifecycle configuration exists, it replaces it.</para> /// </summary> /// /// <param name="putLifecycleConfigurationRequest">Container for the necessary parameters to execute the PutLifecycleConfiguration 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<PutLifecycleConfigurationResponse> PutLifecycleConfigurationAsync(PutLifecycleConfigurationRequest putLifecycleConfigurationRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new PutLifecycleConfigurationRequestMarshaller(); var unmarshaller = PutLifecycleConfigurationResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, PutLifecycleConfigurationRequest, PutLifecycleConfigurationResponse>(putLifecycleConfigurationRequest, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// <para>Sets lifecycle configuration for your bucket. If a lifecycle configuration exists, it replaces it.</para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutLifecycleConfiguration service method on /// AmazonS3.</param> public PutLifecycleConfigurationResponse PutLifecycleConfiguration(PutLifecycleConfigurationRequest request) { var task = PutLifecycleConfigurationAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
public static void lifecycleSerial() { System.Console.WriteLine("\nhello,Lifecyle!!"); NameValueCollection appConfig = ConfigurationManager.AppSettings; AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(appConfig["AWSAccessKey"], appConfig["AWSSecretKey"]); String bucketName = "chttest2"; //PutBucket System.Console.WriteLine("PutBucket: {0}\n", bucketName); s3Client.PutBucket(new PutBucketRequest().WithBucketName(bucketName)); //PutBucketLifecycle rule1 day******************************************************************************************** PutLifecycleConfigurationRequest request = new PutLifecycleConfigurationRequest(); LifecycleConfiguration configuration = new LifecycleConfiguration(); List<LifecycleRule> list = new List<LifecycleRule>(); System.Console.WriteLine("PutBucketLicycle Rule1"); LifecycleRule rule1 = new LifecycleRule(); LifecycleRuleExpiration days = new LifecycleRuleExpiration(); days.Days = 5; rule1.Id = "Day_rule"; rule1.Prefix = "day"; rule1.Status = LifecycleRuleStatus.Enabled; rule1.Expiration = days; list.Add(rule1); //PutBucketLifecycle rule2 date******************************************************************************************** System.Console.WriteLine("PutBucketLicycle Rule2"); LifecycleRule rule2 = new LifecycleRule(); LifecycleRuleExpiration date = new LifecycleRuleExpiration(); DateTime dt = DateTime.Now.AddDays(100); date.Date = dt; rule2.Id = "Date-rule"; rule2.Prefix = "date"; rule2.Status = LifecycleRuleStatus.Enabled; rule2.Expiration = date; list.Add(rule2); configuration.Rules = list; request.WithBucketName(bucketName); request.WithConfiguration(configuration); PutLifecycleConfigurationResponse putResult = s3Client.PutLifecycleConfiguration(request); System.Console.WriteLine("PutBucketLifecycle, requestID: {0}\n", putResult.RequestId); //GetBucketLifecycle GetLifecycleConfigurationResponse getResut = s3Client.GetLifecycleConfiguration(new GetLifecycleConfigurationRequest().WithBucketName(bucketName)); System.Console.WriteLine("GetBucketLifecycle result:\n {0}\n", getResut.ResponseXml); //DeleteBucketLifecycle DeleteLifecycleConfigurationResponse deleteResult = s3Client.DeleteLifecycleConfiguration(new DeleteLifecycleConfigurationRequest().WithBucketName(bucketName)); System.Console.WriteLine("DeleteBucketLifecycle, requestID: {0}\n", deleteResult.RequestId); //DeleteBucket System.Console.WriteLine("Delete Bucket!"); s3Client.DeleteBucket(new DeleteBucketRequest().WithBucketName(bucketName)); System.Console.WriteLine("END!"); }
private string MarshallRequest(LifecycleFilter filter, string prefix = null) { var request = new PutLifecycleConfigurationRequest() { Configuration = new LifecycleConfiguration() { Rules = new List<LifecycleRule>() { new LifecycleRule() { Prefix = prefix, Filter = filter, Transitions = new List<LifecycleTransition>() { new LifecycleTransition() { Days = 1, StorageClass = S3StorageClass.Glacier } } } } } }; return Encoding.UTF8.GetString(new PutLifecycleConfigurationRequestMarshaller().Marshall(request).Content); }
IAsyncResult invokePutLifecycleConfiguration(PutLifecycleConfigurationRequest putLifecycleConfigurationRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new PutLifecycleConfigurationRequestMarshaller().Marshall(putLifecycleConfigurationRequest); var unmarshaller = PutLifecycleConfigurationResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
private Amazon.S3.Model.PutLifecycleConfigurationResponse CallAWSServiceOperation(IAmazonS3 client, Amazon.S3.Model.PutLifecycleConfigurationRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Storage Service (S3)", "PutLifecycleConfiguration"); try { #if DESKTOP return(client.PutLifecycleConfiguration(request)); #elif CORECLR return(client.PutLifecycleConfigurationAsync(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> /// Sets lifecycle configuration for your bucket. If a lifecycle configuration exists, /// it replaces it. /// </summary> /// <param name="bucketName">A property of PutLifecycleConfigurationRequest used to execute the PutLifecycleConfiguration service method.</param> /// <param name="configuration">A property of PutLifecycleConfigurationRequest used to execute the PutLifecycleConfiguration service method.</param> /// /// <returns>The response from the PutLifecycleConfiguration service method, as returned by S3.</returns> public PutLifecycleConfigurationResponse PutLifecycleConfiguration(string bucketName, LifecycleConfiguration configuration) { var request = new PutLifecycleConfigurationRequest(); request.BucketName = bucketName; request.Configuration = configuration; return PutLifecycleConfiguration(request); }
/// <summary> /// Initiates the asynchronous execution of the PutLifecycleConfiguration operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PutLifecycleConfiguration 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<PutLifecycleConfigurationResponse> PutLifecycleConfigurationAsync(PutLifecycleConfigurationRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new PutLifecycleConfigurationRequestMarshaller(); var unmarshaller = PutLifecycleConfigurationResponseUnmarshaller.Instance; return InvokeAsync<PutLifecycleConfigurationRequest,PutLifecycleConfigurationResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Sets lifecycle configuration for your bucket. If a lifecycle configuration exists, /// it replaces it. /// </summary> /// <param name="bucketName">A property of PutLifecycleConfigurationRequest used to execute the PutLifecycleConfiguration service method.</param> /// <param name="configuration">A property of PutLifecycleConfigurationRequest used to execute the PutLifecycleConfiguration service method.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// /// <returns>The response from the PutLifecycleConfiguration service method, as returned by S3.</returns> public Task<PutLifecycleConfigurationResponse> PutLifecycleConfigurationAsync(string bucketName, LifecycleConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var request = new PutLifecycleConfigurationRequest(); request.BucketName = bucketName; request.Configuration = configuration; return PutLifecycleConfigurationAsync(request, cancellationToken); }