protected override void ProcessRecord() { AmazonEC2 client = base.GetClient(); Amazon.EC2.Model.DescribeSpotPriceHistoryRequest request = new Amazon.EC2.Model.DescribeSpotPriceHistoryRequest(); request.StartTime = this._StartTime; request.EndTime = this._EndTime; if (string.IsNullOrEmpty(this._InstanceType)) { request.InstanceType.Add(this._InstanceType); } if (string.IsNullOrEmpty(this._ProductDescription)) { request.ProductDescription.Add(this._ProductDescription); } Amazon.EC2.Model.DescribeSpotPriceHistoryResponse response = client.DescribeSpotPriceHistory(request); base.WriteObject(response.DescribeSpotPriceHistoryResult.SpotPriceHistory, true); }
/// <summary> /// Query EC2 for the spot pricing history for a specified instance type. /// </summary> protected override void AmazonExecute() { var request = new DescribeSpotPriceHistoryRequest { InstanceType = new List<string> { this.InstanceType.Get(this.ActivityContext) }, StartTime = this.StartTime.Get(this.ActivityContext).ToAmazonDateTime(), EndTime = this.EndTime.Get(this.ActivityContext).ToAmazonDateTime() }; try { var response = EC2Client.DescribeSpotPriceHistory(request); this.PriceHistory.Set(this.ActivityContext, response.DescribeSpotPriceHistoryResult.SpotPriceHistory); } catch (EndpointNotFoundException ex) { this.LogBuildMessage(ex.Message); } }
/// <summary> /// Query the market for product spot pricing. /// </summary> protected override void AmazonExecute() { var request = new DescribeSpotPriceHistoryRequest { InstanceType = new List<string> { this.InstanceType.Get(this.ActivityContext) }, ProductDescription = new List<string> { this.ProductDescription.Get(this.ActivityContext) }, StartTime = DateTime.Now.ToAmazonDateTime(), }; try { var response = EC2Client.DescribeSpotPriceHistory(request); // Get the first price in the price history array decimal price = decimal.Parse(response.DescribeSpotPriceHistoryResult.SpotPriceHistory[0].SpotPrice); this.CurrentSpotPrice.Set(this.ActivityContext, price); } catch (EndpointNotFoundException ex) { this.LogBuildMessage(ex.Message); } }
private Amazon.EC2.Model.DescribeSpotPriceHistoryResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.DescribeSpotPriceHistoryRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "DescribeSpotPriceHistory"); try { #if DESKTOP return(client.DescribeSpotPriceHistory(request)); #elif CORECLR return(client.DescribeSpotPriceHistoryAsync(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; } }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; var useParameterSelect = this.Select.StartsWith("^"); // create request and set iteration invariants var request = new Amazon.EC2.Model.DescribeSpotPriceHistoryRequest(); if (cmdletContext.AvailabilityZone != null) { request.AvailabilityZone = cmdletContext.AvailabilityZone; } if (cmdletContext.UtcEndTime != null) { request.EndTimeUtc = cmdletContext.UtcEndTime.Value; } if (cmdletContext.Filter != null) { request.Filters = cmdletContext.Filter; } if (cmdletContext.InstanceType != null) { request.InstanceTypes = cmdletContext.InstanceType; } if (cmdletContext.ProductDescription != null) { request.ProductDescriptions = cmdletContext.ProductDescription; } if (cmdletContext.UtcStartTime != null) { request.StartTimeUtc = cmdletContext.UtcStartTime.Value; } #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (cmdletContext.EndTime != null) { if (cmdletContext.UtcEndTime != null) { throw new System.ArgumentException("Parameters EndTime and UtcEndTime are mutually exclusive.", nameof(this.EndTime)); } request.EndTime = cmdletContext.EndTime.Value; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (cmdletContext.StartTime != null) { if (cmdletContext.UtcStartTime != null) { throw new System.ArgumentException("Parameters StartTime and UtcStartTime are mutually exclusive.", nameof(this.StartTime)); } request.StartTime = cmdletContext.StartTime.Value; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute // Initialize loop variants and commence piping System.String _nextToken = null; int? _emitLimit = null; int _retrievedSoFar = 0; if (AutoIterationHelpers.HasValue(cmdletContext.NextToken)) { _nextToken = cmdletContext.NextToken; } if (AutoIterationHelpers.HasValue(cmdletContext.MaxResult)) { _emitLimit = cmdletContext.MaxResult; } var _userControllingPaging = this.NoAutoIteration.IsPresent || ParameterWasBound(nameof(this.NextToken)); var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); do { request.NextToken = _nextToken; if (_emitLimit.HasValue) { request.MaxResults = AutoIterationHelpers.ConvertEmitLimitToInt32(_emitLimit.Value); } CmdletOutput output; try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; if (!useParameterSelect) { pipelineOutput = cmdletContext.Select(response, this); } output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; int _receivedThisCall = response.SpotPriceHistory.Count; _nextToken = response.NextToken; _retrievedSoFar += _receivedThisCall; if (_emitLimit.HasValue) { _emitLimit -= _receivedThisCall; } } catch (Exception e) { if (_retrievedSoFar == 0 || !_emitLimit.HasValue) { output = new CmdletOutput { ErrorResponse = e }; } else { break; } } ProcessOutput(output); } while (!_userControllingPaging && AutoIterationHelpers.HasValue(_nextToken) && (!_emitLimit.HasValue || _emitLimit.Value >= 1)); if (useParameterSelect) { WriteObject(cmdletContext.Select(null, this)); } return(null); }
/// <summary> /// Initiates the asynchronous execution of the DescribeSpotPriceHistory operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeSpotPriceHistory operation on AmazonEC2Client.</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 EndDescribeSpotPriceHistory /// operation.</returns> public IAsyncResult BeginDescribeSpotPriceHistory(DescribeSpotPriceHistoryRequest request, AsyncCallback callback, object state) { var marshaller = new DescribeSpotPriceHistoryRequestMarshaller(); var unmarshaller = DescribeSpotPriceHistoryResponseUnmarshaller.Instance; return BeginInvoke<DescribeSpotPriceHistoryRequest>(request, marshaller, unmarshaller, callback, state); }
internal DescribeSpotPriceHistoryPaginator(IAmazonEC2 client, DescribeSpotPriceHistoryRequest request) { this._client = client; this._request = request; }
/// <summary> /// Paginator for DescribeSpotPriceHistory operation ///</summary> public IDescribeSpotPriceHistoryPaginator DescribeSpotPriceHistory(DescribeSpotPriceHistoryRequest request) { return(new DescribeSpotPriceHistoryPaginator(this.client, request)); }
static async Task<DescribeSpotPriceHistoryResponse> GetSpotPricesFromRegion(string region, InstanceType instanceType, string description) { AmazonEC2Client client = GetEC2Client(region); var request = new DescribeSpotPriceHistoryRequest(); request.StartTime = DateTime.UtcNow - TimeSpan.FromMinutes(10.0); request.InstanceTypes = new List<string>() { instanceType.Value }; request.ProductDescriptions = new List<string>() { description }; return await client.DescribeSpotPriceHistoryAsync(request); }
/// <summary> /// Initiates the asynchronous execution of the DescribeSpotPriceHistory operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.DescribeSpotPriceHistory"/> /// </summary> /// /// <param name="describeSpotPriceHistoryRequest">Container for the necessary parameters to execute the DescribeSpotPriceHistory operation on /// AmazonEC2.</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 /// EndDescribeSpotPriceHistory operation.</returns> public IAsyncResult BeginDescribeSpotPriceHistory(DescribeSpotPriceHistoryRequest describeSpotPriceHistoryRequest, AsyncCallback callback, object state) { return invokeDescribeSpotPriceHistory(describeSpotPriceHistoryRequest, callback, state, false); }
/// <summary> /// <para>Describes the Spot Price history. Spot Instances are instances that Amazon EC2 starts on your behalf when the maximum price that you /// specify exceeds the current Spot Price. Amazon EC2 periodically sets the Spot Price based on available Spot Instance capacity and current /// Spot Instance requests. For more information about Spot Instances, see <a /// href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html" >Spot Instances</a> in the <i>Amazon Elastic Compute /// Cloud User Guide</i> .</para> <para>When you specify an Availability Zone, this operation describes the price history for the specified /// Availability Zone with the most recent set of prices listed first. If you don't specify an Availability Zone, you get the prices across all /// Availability Zones, starting with the most recent set. However, if you're using an API version earlier than 2011-05-15, you get the lowest /// price across the region for the specified time period. The prices returned are listed in chronological order, from the oldest to the most /// recent.</para> /// </summary> /// /// <param name="describeSpotPriceHistoryRequest">Container for the necessary parameters to execute the DescribeSpotPriceHistory service method /// on AmazonEC2.</param> /// /// <returns>The response from the DescribeSpotPriceHistory service method, as returned by AmazonEC2.</returns> /// public DescribeSpotPriceHistoryResponse DescribeSpotPriceHistory(DescribeSpotPriceHistoryRequest describeSpotPriceHistoryRequest) { IAsyncResult asyncResult = invokeDescribeSpotPriceHistory(describeSpotPriceHistoryRequest, null, null, true); return EndDescribeSpotPriceHistory(asyncResult); }
/// <summary> /// <para>Describes the Spot Price history. Spot Instances are instances that Amazon EC2 starts on your behalf when the maximum price that you /// specify exceeds the current Spot Price. Amazon EC2 periodically sets the Spot Price based on available Spot Instance capacity and current /// Spot Instance requests. For more information about Spot Instances, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html">Spot Instances</a> in the <i>Amazon Elastic Compute /// Cloud User Guide</i> .</para> <para>When you specify an Availability Zone, this operation describes the price history for the specified /// Availability Zone with the most recent set of prices listed first. If you don't specify an Availability Zone, you get the prices across all /// Availability Zones, starting with the most recent set. However, if you're using an API version earlier than 2011-05-15, you get the lowest /// price across the region for the specified time period. The prices returned are listed in chronological order, from the oldest to the most /// recent.</para> /// </summary> /// /// <param name="describeSpotPriceHistoryRequest">Container for the necessary parameters to execute the DescribeSpotPriceHistory service method /// on AmazonEC2.</param> /// /// <returns>The response from the DescribeSpotPriceHistory service method, as returned by AmazonEC2.</returns> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public Task<DescribeSpotPriceHistoryResponse> DescribeSpotPriceHistoryAsync(DescribeSpotPriceHistoryRequest describeSpotPriceHistoryRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DescribeSpotPriceHistoryRequestMarshaller(); var unmarshaller = DescribeSpotPriceHistoryResponseUnmarshaller.GetInstance(); return Invoke<IRequest, DescribeSpotPriceHistoryRequest, DescribeSpotPriceHistoryResponse>(describeSpotPriceHistoryRequest, marshaller, unmarshaller, signer, cancellationToken); }
internal DescribeSpotPriceHistoryResponse DescribeSpotPriceHistory(DescribeSpotPriceHistoryRequest request) { var task = DescribeSpotPriceHistoryAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// Initiates the asynchronous execution of the DescribeSpotPriceHistory operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.DescribeSpotPriceHistory"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeSpotPriceHistory 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 async Task<DescribeSpotPriceHistoryResponse> DescribeSpotPriceHistoryAsync(DescribeSpotPriceHistoryRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DescribeSpotPriceHistoryRequestMarshaller(); var unmarshaller = DescribeSpotPriceHistoryResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, DescribeSpotPriceHistoryRequest, DescribeSpotPriceHistoryResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// <para> Describes the Spot Price history. </para> <para> Spot Instances are instances that Amazon EC2 starts on your behalf when the maximum /// price that you specify exceeds the current Spot Price. Amazon EC2 periodically sets the Spot Price based on available Spot Instance capacity /// and current spot instance requests. </para> <para> For conceptual information about Spot Instances, refer to the Amazon Elastic Compute /// Cloud Developer Guide or Amazon Elastic Compute Cloud User Guide . /// </para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeSpotPriceHistory service method /// on AmazonEC2.</param> /// /// <returns>The response from the DescribeSpotPriceHistory service method, as returned by AmazonEC2.</returns> public DescribeSpotPriceHistoryResponse DescribeSpotPriceHistory(DescribeSpotPriceHistoryRequest request) { var task = DescribeSpotPriceHistoryAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
/// <summary> /// Describes the Spot Price history. The prices returned are listed in chronological /// order, from the oldest to the most recent, for up to the past 90 days. For more information, /// see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances-history.html">Spot /// Instance Pricing History</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>. /// /// /// <para> /// When you specify a start and end time, this operation returns the prices of the instance /// types within the time range that you specified and the time when the price changed. /// The price is valid within the time period that you specified; the response merely /// indicates the last time that the price changed. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the DescribeSpotPriceHistory service method.</param> /// /// <returns>The response from the DescribeSpotPriceHistory service method, as returned by EC2.</returns> public DescribeSpotPriceHistoryResponse DescribeSpotPriceHistory(DescribeSpotPriceHistoryRequest request) { var marshaller = new DescribeSpotPriceHistoryRequestMarshaller(); var unmarshaller = DescribeSpotPriceHistoryResponseUnmarshaller.Instance; return Invoke<DescribeSpotPriceHistoryRequest,DescribeSpotPriceHistoryResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the DescribeSpotPriceHistory operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeSpotPriceHistory 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<DescribeSpotPriceHistoryResponse> DescribeSpotPriceHistoryAsync(DescribeSpotPriceHistoryRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DescribeSpotPriceHistoryRequestMarshaller(); var unmarshaller = DescribeSpotPriceHistoryResponseUnmarshaller.Instance; return InvokeAsync<DescribeSpotPriceHistoryRequest,DescribeSpotPriceHistoryResponse>(request, marshaller, unmarshaller, cancellationToken); }
IAsyncResult invokeDescribeSpotPriceHistory(DescribeSpotPriceHistoryRequest describeSpotPriceHistoryRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new DescribeSpotPriceHistoryRequestMarshaller().Marshall(describeSpotPriceHistoryRequest); var unmarshaller = DescribeSpotPriceHistoryResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }