/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.Kinesis;
using Amazon.Kinesis.Model;
namespace Amazon.PowerShell.Cmdlets.KIN
{
///
/// Gets an Amazon Kinesis shard iterator. A shard iterator expires 5 minutes after it
/// is returned to the requester.
///
///
/// When invoking this API, it is recommended you use the StreamARN
input
/// parameter rather than the StreamName
input parameter.
///
/// A shard iterator specifies the shard position from which to start reading data records
/// sequentially. The position is specified using the sequence number of a data record
/// in a shard. A sequence number is the identifier associated with every record ingested
/// in the stream, and is assigned when a record is put into the stream. Each stream has
/// one or more shards.
///
/// You must specify the shard iterator type. For example, you can set the ShardIteratorType
/// parameter to read exactly from the position denoted by a specific sequence number
/// by using the AT_SEQUENCE_NUMBER
shard iterator type. Alternatively, the
/// parameter can read right after the sequence number by using the AFTER_SEQUENCE_NUMBER
/// shard iterator type, using sequence numbers returned by earlier calls to PutRecord,
/// PutRecords, GetRecords, or DescribeStream. In the request, you
/// can specify the shard iterator type AT_TIMESTAMP
to read records from
/// an arbitrary point in time, TRIM_HORIZON
to cause ShardIterator
/// to point to the last untrimmed record in the shard in the system (the oldest data
/// record in the shard), or LATEST
so that you always read the most recent
/// data in the shard.
///
/// When you read repeatedly from a stream, use a GetShardIterator request to get
/// the first shard iterator for use in your first GetRecords request and for subsequent
/// reads use the shard iterator returned by the GetRecords request in NextShardIterator
.
/// A new shard iterator is returned by every GetRecords request in NextShardIterator
,
/// which you use in the ShardIterator
parameter of the next GetRecords
/// request.
///
/// If a GetShardIterator request is made too often, you receive a ProvisionedThroughputExceededException
.
/// For more information about throughput limits, see GetRecords, and Streams
/// Limits in the Amazon Kinesis Data Streams Developer Guide.
///
/// If the shard is closed, GetShardIterator returns a valid iterator for the last
/// sequence number of the shard. A shard can be closed as a result of using SplitShard
/// or MergeShards.
/// GetShardIterator has a limit of five transactions per second per account per
/// open shard.
///
///
[Cmdlet("Get", "KINShardIterator")]
[OutputType("System.String")]
[AWSCmdlet("Calls the Amazon Kinesis GetShardIterator API operation.", Operation = new[] {"GetShardIterator"}, SelectReturnType = typeof(Amazon.Kinesis.Model.GetShardIteratorResponse))]
[AWSCmdletOutput("System.String or Amazon.Kinesis.Model.GetShardIteratorResponse",
"This cmdlet returns a System.String object.",
"The service call response (type Amazon.Kinesis.Model.GetShardIteratorResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class GetKINShardIteratorCmdlet : AmazonKinesisClientCmdlet, IExecutor
{
#region Parameter ShardId
///
///
/// The shard ID of the Kinesis Data Streams shard to get the iterator for.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
#else
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String ShardId { get; set; }
#endregion
#region Parameter ShardIteratorType
///
///
/// Determines how the shard iterator is used to start reading data records from the shard.The following are the valid Amazon Kinesis shard iterator types:- AT_SEQUENCE_NUMBER - Start reading from the position denoted by a specific sequence
/// number, provided in the value
StartingSequenceNumber
. - AFTER_SEQUENCE_NUMBER - Start reading right after the position denoted by a specific
/// sequence number, provided in the value
StartingSequenceNumber
. - AT_TIMESTAMP - Start reading from the position denoted by a specific time stamp, provided
/// in the value
Timestamp
. - TRIM_HORIZON - Start reading at the last untrimmed record in the shard in the system,
/// which is the oldest data record in the shard.
- LATEST - Start reading just after the most recent record in the shard, so that you
/// always read the most recent data in the shard.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
[AWSConstantClassSource("Amazon.Kinesis.ShardIteratorType")]
public Amazon.Kinesis.ShardIteratorType ShardIteratorType { get; set; }
#endregion
#region Parameter StartingSequenceNumber
///
///
/// The sequence number of the data record in the shard from which to start reading. Used
/// with shard iterator type AT_SEQUENCE_NUMBER and AFTER_SEQUENCE_NUMBER.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String StartingSequenceNumber { get; set; }
#endregion
#region Parameter StreamARN
///
///
/// The ARN of the stream.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String StreamARN { get; set; }
#endregion
#region Parameter StreamName
///
///
/// The name of the Amazon Kinesis data stream.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String StreamName { get; set; }
#endregion
#region Parameter Timestamp
///
///
/// The time stamp of the data record from which to start reading. Used with shard iterator
/// type AT_TIMESTAMP. A time stamp is the Unix epoch date with precision in milliseconds.
/// For example, 2016-04-04T19:58:46.480-00:00
or 1459799926.480
.
/// If a record with this exact time stamp does not exist, the iterator returned is for
/// the next (later) record. If the time stamp is older than the current trim horizon,
/// the iterator returned is for the oldest untrimmed data record (TRIM_HORIZON).
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.DateTime? Timestamp { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'ShardIterator'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Kinesis.Model.GetShardIteratorResponse).
/// Specifying the name of a property of type Amazon.Kinesis.Model.GetShardIteratorResponse will result in that property being returned.
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "ShardIterator";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the ShardId parameter.
/// The -PassThru parameter is deprecated, use -Select '^ShardId' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ShardId' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.ShardId;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.ShardId = this.ShardId;
#if MODULAR
if (this.ShardId == null && ParameterWasBound(nameof(this.ShardId)))
{
WriteWarning("You are passing $null as a value for parameter ShardId which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.ShardIteratorType = this.ShardIteratorType;
#if MODULAR
if (this.ShardIteratorType == null && ParameterWasBound(nameof(this.ShardIteratorType)))
{
WriteWarning("You are passing $null as a value for parameter ShardIteratorType which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.StartingSequenceNumber = this.StartingSequenceNumber;
context.StreamARN = this.StreamARN;
context.StreamName = this.StreamName;
context.Timestamp = this.Timestamp;
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.Kinesis.Model.GetShardIteratorRequest();
if (cmdletContext.ShardId != null)
{
request.ShardId = cmdletContext.ShardId;
}
if (cmdletContext.ShardIteratorType != null)
{
request.ShardIteratorType = cmdletContext.ShardIteratorType;
}
if (cmdletContext.StartingSequenceNumber != null)
{
request.StartingSequenceNumber = cmdletContext.StartingSequenceNumber;
}
if (cmdletContext.StreamARN != null)
{
request.StreamARN = cmdletContext.StreamARN;
}
if (cmdletContext.StreamName != null)
{
request.StreamName = cmdletContext.StreamName;
}
if (cmdletContext.Timestamp != null)
{
request.Timestamp = cmdletContext.Timestamp.Value;
}
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 ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.Kinesis.Model.GetShardIteratorResponse CallAWSServiceOperation(IAmazonKinesis client, Amazon.Kinesis.Model.GetShardIteratorRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Kinesis", "GetShardIterator");
try
{
#if DESKTOP
return client.GetShardIterator(request);
#elif CORECLR
return client.GetShardIteratorAsync(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;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public System.String ShardId { get; set; }
public Amazon.Kinesis.ShardIteratorType ShardIteratorType { get; set; }
public System.String StartingSequenceNumber { get; set; }
public System.String StreamARN { get; set; }
public System.String StreamName { get; set; }
public System.DateTime? Timestamp { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.ShardIterator;
}
}
}