/// <summary> /// The CreateKeyPair operation creates a new 2048 bit RSA key pair and returns a /// unique ID that can be used to reference this key pair when launching new /// instances. For more information, see RunInstances. /// /// </summary> /// <param name="service">Instance of AmazonEC2 service</param> /// <param name="request">CreateKeyPairRequest request</param> public static void InvokeCreateKeyPair(AmazonEC2 service, CreateKeyPairRequest request) { try { CreateKeyPairResponse response = service.CreateKeyPair(request); Console.WriteLine ("Service Response"); Console.WriteLine ("============================================================================="); Console.WriteLine (); Console.WriteLine(" CreateKeyPairResponse"); if (response.IsSetResponseMetadata()) { Console.WriteLine(" ResponseMetadata"); ResponseMetadata responseMetadata = response.ResponseMetadata; if (responseMetadata.IsSetRequestId()) { Console.WriteLine(" RequestId"); Console.WriteLine(" {0}", responseMetadata.RequestId); } } if (response.IsSetCreateKeyPairResult()) { Console.WriteLine(" CreateKeyPairResult"); CreateKeyPairResult createKeyPairResult = response.CreateKeyPairResult; if (createKeyPairResult.IsSetKeyPair()) { Console.WriteLine(" KeyPair"); KeyPair keyPair = createKeyPairResult.KeyPair; if (keyPair.IsSetKeyName()) { Console.WriteLine(" KeyName"); Console.WriteLine(" {0}", keyPair.KeyName); } if (keyPair.IsSetKeyFingerprint()) { Console.WriteLine(" KeyFingerprint"); Console.WriteLine(" {0}", keyPair.KeyFingerprint); } if (keyPair.IsSetKeyMaterial()) { Console.WriteLine(" KeyMaterial"); Console.WriteLine(" {0}", keyPair.KeyMaterial); } } } } catch (AmazonEC2Exception ex) { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Response Status Code: " + ex.StatusCode); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine("Error Type: " + ex.ErrorType); Console.WriteLine("Request ID: " + ex.RequestId); Console.WriteLine("XML: " + ex.XML); } }
protected override void ProcessRecord() { AmazonEC2 client = base.GetClient(); Amazon.EC2.Model.CreateKeyPairRequest request = new Amazon.EC2.Model.CreateKeyPairRequest(); request.KeyName = this._KeyName; Amazon.EC2.Model.CreateKeyPairResponse response = client.CreateKeyPair(request); base.WriteObject(response.CreateKeyPairResult.KeyPair, true); }
public KeyPair CreateKeyPair(string keyName) { AWSModel.CreateKeyPairRequest request = new AWSModel.CreateKeyPairRequest(); request.KeyName = keyName; AWSModel.CreateKeyPairResponse response = ec2.CreateKeyPair(request); KeyPair keyPair = ModelUtil.CreateInstance(response.CreateKeyPairResult.KeyPair); return(keyPair); }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.EC2.Model.CreateKeyPairRequest(); if (cmdletContext.KeyName != null) { request.KeyName = cmdletContext.KeyName; } if (cmdletContext.KeyType != null) { request.KeyType = cmdletContext.KeyType; } if (cmdletContext.TagSpecification != null) { request.TagSpecifications = cmdletContext.TagSpecification; } 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 CreateKeyPair operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateKeyPair 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 EndCreateKeyPair /// operation.</returns> public IAsyncResult BeginCreateKeyPair(CreateKeyPairRequest request, AsyncCallback callback, object state) { var marshaller = new CreateKeyPairRequestMarshaller(); var unmarshaller = CreateKeyPairResponseUnmarshaller.Instance; return BeginInvoke<CreateKeyPairRequest>(request, marshaller, unmarshaller, callback, state); }
IAsyncResult invokeCreateKeyPair(CreateKeyPairRequest createKeyPairRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new CreateKeyPairRequestMarshaller().Marshall(createKeyPairRequest); var unmarshaller = CreateKeyPairResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// Initiates the asynchronous execution of the CreateKeyPair operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.CreateKeyPair"/> /// </summary> /// /// <param name="createKeyPairRequest">Container for the necessary parameters to execute the CreateKeyPair 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 EndCreateKeyPair /// operation.</returns> public IAsyncResult BeginCreateKeyPair(CreateKeyPairRequest createKeyPairRequest, AsyncCallback callback, object state) { return invokeCreateKeyPair(createKeyPairRequest, callback, state, false); }
/// <summary> /// <para>Creates a 2048-bit RSA key pair with the specified name. Amazon EC2 stores the public key and displays the private key for you to save /// to a file. The private key is returned as an unencrypted PEM encoded PKCS#8 private key. If a key with the specified name already exists, /// Amazon EC2 returns an error.</para> <para>You can have up to five thousand key pairs per region.</para> <para>For more information about key /// pairs, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html" >Key Pairs</a> in the <i>Amazon Elastic Compute /// Cloud User Guide</i> .</para> /// </summary> /// /// <param name="createKeyPairRequest">Container for the necessary parameters to execute the CreateKeyPair service method on AmazonEC2.</param> /// /// <returns>The response from the CreateKeyPair service method, as returned by AmazonEC2.</returns> /// public CreateKeyPairResponse CreateKeyPair(CreateKeyPairRequest createKeyPairRequest) { IAsyncResult asyncResult = invokeCreateKeyPair(createKeyPairRequest, null, null, true); return EndCreateKeyPair(asyncResult); }
/// <summary> /// <para>Creates a 2048-bit RSA key pair with the specified name. Amazon EC2 stores the public key and displays the private key for you to save /// to a file. The private key is returned as an unencrypted PEM encoded PKCS#8 private key. If a key with the specified name already exists, /// Amazon EC2 returns an error.</para> <para>You can have up to five thousand key pairs per region.</para> <para>For more information about key /// pairs, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">Key Pairs</a> in the <i>Amazon Elastic Compute /// Cloud User Guide</i> .</para> /// </summary> /// /// <param name="createKeyPairRequest">Container for the necessary parameters to execute the CreateKeyPair service method on AmazonEC2.</param> /// /// <returns>The response from the CreateKeyPair 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<CreateKeyPairResponse> CreateKeyPairAsync(CreateKeyPairRequest createKeyPairRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new CreateKeyPairRequestMarshaller(); var unmarshaller = CreateKeyPairResponseUnmarshaller.GetInstance(); return Invoke<IRequest, CreateKeyPairRequest, CreateKeyPairResponse>(createKeyPairRequest, marshaller, unmarshaller, signer, cancellationToken); }
internal CreateKeyPairResponse CreateKeyPair(CreateKeyPairRequest request) { var task = CreateKeyPairAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// <para> The CreateKeyPair operation creates a new 2048 bit RSA key pair and returns a unique ID that can be used to reference this key pair /// when launching new instances. For more information, see RunInstances. </para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateKeyPair service method on AmazonEC2.</param> /// /// <returns>The response from the CreateKeyPair service method, as returned by AmazonEC2.</returns> public CreateKeyPairResponse CreateKeyPair(CreateKeyPairRequest request) { var task = CreateKeyPairAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
public KeyPair CreateKeyPair(string keyName) { AWSModel.CreateKeyPairRequest request = new AWSModel.CreateKeyPairRequest(); request.KeyName = keyName; AWSModel.CreateKeyPairResponse response = ec2.CreateKeyPair(request); KeyPair keyPair = ModelUtil.CreateInstance(response.CreateKeyPairResult.KeyPair); return keyPair; }
private Amazon.EC2.Model.CreateKeyPairResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.CreateKeyPairRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "CreateKeyPair"); try { #if DESKTOP return(client.CreateKeyPair(request)); #elif CORECLR return(client.CreateKeyPairAsync(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> /// Creates a 2048-bit RSA key pair with the specified name. Amazon EC2 stores the public /// key and displays the private key for you to save to a file. The private key is returned /// as an unencrypted PEM encoded PKCS#8 private key. If a key with the specified name /// already exists, Amazon EC2 returns an error. /// /// /// <para> /// You can have up to five thousand key pairs per region. /// </para> /// /// <para> /// The key pair returned to you is available only in the region in which you create it. /// To create a key pair that is available in all regions, use <a>ImportKeyPair</a>. /// </para> /// /// <para> /// For more information about key pairs, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">Key /// Pairs</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the CreateKeyPair service method.</param> /// /// <returns>The response from the CreateKeyPair service method, as returned by EC2.</returns> public CreateKeyPairResponse CreateKeyPair(CreateKeyPairRequest request) { var marshaller = new CreateKeyPairRequestMarshaller(); var unmarshaller = CreateKeyPairResponseUnmarshaller.Instance; return Invoke<CreateKeyPairRequest,CreateKeyPairResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the CreateKeyPair operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.CreateKeyPair"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateKeyPair 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<CreateKeyPairResponse> CreateKeyPairAsync(CreateKeyPairRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new CreateKeyPairRequestMarshaller(); var unmarshaller = CreateKeyPairResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, CreateKeyPairRequest, CreateKeyPairResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// Initiates the asynchronous execution of the CreateKeyPair operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateKeyPair 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<CreateKeyPairResponse> CreateKeyPairAsync(CreateKeyPairRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new CreateKeyPairRequestMarshaller(); var unmarshaller = CreateKeyPairResponseUnmarshaller.Instance; return InvokeAsync<CreateKeyPairRequest,CreateKeyPairResponse>(request, marshaller, unmarshaller, cancellationToken); }
//once we get here we know the key file doesn't exist private void createKayPair() { try { string keyFileDir = CAwsConfig.getEc2BootstrapperDirectory(); if(Directory.Exists(keyFileDir) == false) { Directory.CreateDirectory(keyFileDir); } string keyFilePath = null; FolderBrowserDialog folder = new FolderBrowserDialog(); folder.ShowNewFolderButton = true; folder.SelectedPath = keyFileDir; folder.Description = "Please select directory where you want to save key file"; DialogResult result = DialogResult.No; while (result == DialogResult.No) { if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK) { keyFilePath = folder.SelectedPath + "\\" + _keyPairName + ".pem"; if (File.Exists(keyFilePath)) { result = MessageBox.Show(null, "Key file " + keyFilePath + " exists. Do you want to overwrite it?", "Key File", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); } else { break; } } } CreateKeyPairRequest request = new CreateKeyPairRequest(); request.KeyName = _keyPairName; CreateKeyPairResponse response = _service.CreateKeyPair(request); if (response.IsSetCreateKeyPairResult()) { CreateKeyPairResult createKeyPairResult = response.CreateKeyPairResult; if (createKeyPairResult.IsSetKeyPair()) { using (FileStream stream = new FileStream( keyFilePath, FileMode.Create, FileAccess.Write)) { KeyPair keyPair = createKeyPairResult.KeyPair; if (keyPair.IsSetKeyMaterial()) { byte[] fileData = new UTF8Encoding(true).GetBytes(keyPair.KeyMaterial); stream.Write(fileData, 0, fileData.Length); CAwsConfig.Instance.setKeyFilePath(_keyPairName, keyFilePath); CAwsConfig.Instance.commit(); } } } } } catch (AmazonEC2Exception ex) { throw new Exception("Caught Exception: " + ex.XML); } }