/*******************************************************************************
* 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.KinesisAnalytics;
using Amazon.KinesisAnalytics.Model;
namespace Amazon.PowerShell.Cmdlets.KINA
{
///
///
/// This documentation is for version 1 of the Amazon Kinesis Data Analytics API, which
/// only supports SQL applications. Version 2 of the API supports SQL and Java applications.
/// For more information about version 2, see Amazon
/// Kinesis Data Analytics API V2 Documentation.
///
/// Creates an Amazon Kinesis Analytics application. You can configure each application
/// with one streaming source as input, application code to process the input, and up
/// to three destinations where you want Amazon Kinesis Analytics to write the output
/// data from your application. For an overview, see How
/// it Works.
///
/// In the input configuration, you map the streaming source to an in-application stream,
/// which you can think of as a constantly updating table. In the mapping, you must provide
/// a schema for the in-application stream and map each data column in the in-application
/// stream to a data element in the streaming source.
///
/// Your application code is one or more SQL statements that read input data, transform
/// it, and generate output. Your application code can create one or more SQL artifacts
/// like SQL streams or pumps.
///
/// In the output configuration, you can configure the application to write data from
/// in-application streams created in your applications to up to three destinations.
///
/// To read data from your source stream or write data to destination streams, Amazon
/// Kinesis Analytics needs your permissions. You grant these permissions by creating
/// IAM roles. This operation requires permissions to perform the kinesisanalytics:CreateApplication
/// action.
///
/// For introductory exercises to create an Amazon Kinesis Analytics application, see
/// Getting
/// Started.
///
///
[Cmdlet("New", "KINAApplication", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.KinesisAnalytics.Model.ApplicationSummary")]
[AWSCmdlet("Calls the Amazon Kinesis Analytics CreateApplication API operation.", Operation = new[] {"CreateApplication"}, SelectReturnType = typeof(Amazon.KinesisAnalytics.Model.CreateApplicationResponse))]
[AWSCmdletOutput("Amazon.KinesisAnalytics.Model.ApplicationSummary or Amazon.KinesisAnalytics.Model.CreateApplicationResponse",
"This cmdlet returns an Amazon.KinesisAnalytics.Model.ApplicationSummary object.",
"The service call response (type Amazon.KinesisAnalytics.Model.CreateApplicationResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewKINAApplicationCmdlet : AmazonKinesisAnalyticsClientCmdlet, IExecutor
{
#region Parameter ApplicationCode
///
///
/// One or more SQL statements that read input data, transform it, and generate output.
/// For example, you can write a SQL statement that reads data from one in-application
/// stream, generates a running average of the number of advertisement clicks by vendor,
/// and insert resulting rows in another in-application stream using pumps. For more information
/// about the typical pattern, see Application
/// Code. You can provide such series of SQL statements, where output of one statement can be
/// used as the input for the next statement. You store intermediate results by creating
/// in-application streams and pumps.Note that the application code must create the streams with names specified in the
/// Outputs
. For example, if your Outputs
defines output streams
/// named ExampleOutputStream1
and ExampleOutputStream2
, then
/// your application code must create these streams.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ApplicationCode { get; set; }
#endregion
#region Parameter ApplicationDescription
///
///
/// Summary description of the application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ApplicationDescription { get; set; }
#endregion
#region Parameter ApplicationName
///
///
/// Name of your Amazon Kinesis Analytics application (for example, sample-app
).
///
///
#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 ApplicationName { get; set; }
#endregion
#region Parameter CloudWatchLoggingOption
///
///
/// Use this parameter to configure a CloudWatch log stream to monitor application configuration
/// errors. For more information, see Working
/// with Amazon CloudWatch Logs.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("CloudWatchLoggingOptions")]
public Amazon.KinesisAnalytics.Model.CloudWatchLoggingOption[] CloudWatchLoggingOption { get; set; }
#endregion
#region Parameter Input
///
///
/// Use this parameter to configure the application input.You can configure your application to receive input from a single streaming source.
/// In this configuration, you map this streaming source to an in-application stream that
/// is created. Your application code can then query the in-application stream like a
/// table (you can think of it as a constantly updating table).For the streaming source, you provide its Amazon Resource Name (ARN) and format of
/// data on the stream (for example, JSON, CSV, etc.). You also must provide an IAM role
/// that Amazon Kinesis Analytics can assume to read this stream on your behalf.To create the in-application stream, you need to specify a schema to transform your
/// data into a schematized version used in SQL. In the schema, you provide the necessary
/// mapping of the data elements in the streaming source to record columns in the in-app
/// stream.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Inputs")]
public Amazon.KinesisAnalytics.Model.Input[] Input { get; set; }
#endregion
#region Parameter Output
///
///
/// You can configure application output to write data from any of the in-application
/// streams to up to three destinations.These destinations can be Amazon Kinesis streams, Amazon Kinesis Firehose delivery
/// streams, AWS Lambda destinations, or any combination of the three.In the configuration, you specify the in-application stream name, the destination
/// stream or Lambda function Amazon Resource Name (ARN), and the format to use when writing
/// data. You must also provide an IAM role that Amazon Kinesis Analytics can assume to
/// write to the destination stream or Lambda function on your behalf.In the output configuration, you also provide the output stream or Lambda function
/// ARN. For stream destinations, you provide the format of data in the stream (for example,
/// JSON, CSV). You also must provide an IAM role that Amazon Kinesis Analytics can assume
/// to write to the stream or Lambda function on your behalf.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Outputs")]
public Amazon.KinesisAnalytics.Model.Output[] Output { get; set; }
#endregion
#region Parameter Tag
///
///
/// A list of one or more tags to assign to the application. A tag is a key-value pair
/// that identifies an application. Note that the maximum number of application tags includes
/// system tags. The maximum number of user-defined application tags is 50. For more information,
/// see Using
/// Tagging.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.KinesisAnalytics.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'ApplicationSummary'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.KinesisAnalytics.Model.CreateApplicationResponse).
/// Specifying the name of a property of type Amazon.KinesisAnalytics.Model.CreateApplicationResponse 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; } = "ApplicationSummary";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the ApplicationName parameter.
/// The -PassThru parameter is deprecated, use -Select '^ApplicationName' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ApplicationName' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
#region Parameter Force
///
/// This parameter overrides confirmation prompts to force
/// the cmdlet to continue its operation. This parameter should always
/// be used with caution.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.ApplicationName), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-KINAApplication (CreateApplication)"))
{
return;
}
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.ApplicationName;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.ApplicationCode = this.ApplicationCode;
context.ApplicationDescription = this.ApplicationDescription;
context.ApplicationName = this.ApplicationName;
#if MODULAR
if (this.ApplicationName == null && ParameterWasBound(nameof(this.ApplicationName)))
{
WriteWarning("You are passing $null as a value for parameter ApplicationName 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
if (this.CloudWatchLoggingOption != null)
{
context.CloudWatchLoggingOption = new List(this.CloudWatchLoggingOption);
}
if (this.Input != null)
{
context.Input = new List(this.Input);
}
if (this.Output != null)
{
context.Output = new List(this.Output);
}
if (this.Tag != null)
{
context.Tag = new List(this.Tag);
}
// 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.KinesisAnalytics.Model.CreateApplicationRequest();
if (cmdletContext.ApplicationCode != null)
{
request.ApplicationCode = cmdletContext.ApplicationCode;
}
if (cmdletContext.ApplicationDescription != null)
{
request.ApplicationDescription = cmdletContext.ApplicationDescription;
}
if (cmdletContext.ApplicationName != null)
{
request.ApplicationName = cmdletContext.ApplicationName;
}
if (cmdletContext.CloudWatchLoggingOption != null)
{
request.CloudWatchLoggingOptions = cmdletContext.CloudWatchLoggingOption;
}
if (cmdletContext.Input != null)
{
request.Inputs = cmdletContext.Input;
}
if (cmdletContext.Output != null)
{
request.Outputs = cmdletContext.Output;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
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.KinesisAnalytics.Model.CreateApplicationResponse CallAWSServiceOperation(IAmazonKinesisAnalytics client, Amazon.KinesisAnalytics.Model.CreateApplicationRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Kinesis Analytics", "CreateApplication");
try
{
#if DESKTOP
return client.CreateApplication(request);
#elif CORECLR
return client.CreateApplicationAsync(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 ApplicationCode { get; set; }
public System.String ApplicationDescription { get; set; }
public System.String ApplicationName { get; set; }
public List CloudWatchLoggingOption { get; set; }
public List Input { get; set; }
public List Output { get; set; }
public List Tag { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.ApplicationSummary;
}
}
}