1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package ec2 4 5import ( 6 "context" 7 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 8 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 9 "github.com/aws/aws-sdk-go-v2/service/ec2/types" 10 "github.com/aws/smithy-go/middleware" 11 smithyhttp "github.com/aws/smithy-go/transport/http" 12) 13 14// Creates a 2048-bit RSA key pair with the specified name. Amazon EC2 stores the 15// public key and displays the private key for you to save to a file. The private 16// key is returned as an unencrypted PEM encoded PKCS#1 private key. If a key with 17// the specified name already exists, Amazon EC2 returns an error. You can have up 18// to five thousand key pairs per Region. The key pair returned to you is available 19// only in the Region in which you create it. If you prefer, you can create your 20// own key pair using a third-party tool and upload it to any Region using 21// ImportKeyPair. For more information, see Key Pairs 22// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html) in the 23// Amazon Elastic Compute Cloud User Guide. 24func (c *Client) CreateKeyPair(ctx context.Context, params *CreateKeyPairInput, optFns ...func(*Options)) (*CreateKeyPairOutput, error) { 25 if params == nil { 26 params = &CreateKeyPairInput{} 27 } 28 29 result, metadata, err := c.invokeOperation(ctx, "CreateKeyPair", params, optFns, addOperationCreateKeyPairMiddlewares) 30 if err != nil { 31 return nil, err 32 } 33 34 out := result.(*CreateKeyPairOutput) 35 out.ResultMetadata = metadata 36 return out, nil 37} 38 39type CreateKeyPairInput struct { 40 41 // A unique name for the key pair. Constraints: Up to 255 ASCII characters 42 // 43 // This member is required. 44 KeyName *string 45 46 // Checks whether you have the required permissions for the action, without 47 // actually making the request, and provides an error response. If you have the 48 // required permissions, the error response is DryRunOperation. Otherwise, it is 49 // UnauthorizedOperation. 50 DryRun bool 51 52 // The tags to apply to the new key pair. 53 TagSpecifications []types.TagSpecification 54} 55 56// Describes a key pair. 57type CreateKeyPairOutput struct { 58 59 // The SHA-1 digest of the DER encoded private key. 60 KeyFingerprint *string 61 62 // An unencrypted PEM encoded RSA private key. 63 KeyMaterial *string 64 65 // The name of the key pair. 66 KeyName *string 67 68 // The ID of the key pair. 69 KeyPairId *string 70 71 // Any tags applied to the key pair. 72 Tags []types.Tag 73 74 // Metadata pertaining to the operation's result. 75 ResultMetadata middleware.Metadata 76} 77 78func addOperationCreateKeyPairMiddlewares(stack *middleware.Stack, options Options) (err error) { 79 err = stack.Serialize.Add(&awsEc2query_serializeOpCreateKeyPair{}, middleware.After) 80 if err != nil { 81 return err 82 } 83 err = stack.Deserialize.Add(&awsEc2query_deserializeOpCreateKeyPair{}, middleware.After) 84 if err != nil { 85 return err 86 } 87 if err = addSetLoggerMiddleware(stack, options); err != nil { 88 return err 89 } 90 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 91 return err 92 } 93 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 94 return err 95 } 96 if err = addResolveEndpointMiddleware(stack, options); err != nil { 97 return err 98 } 99 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 100 return err 101 } 102 if err = addRetryMiddlewares(stack, options); err != nil { 103 return err 104 } 105 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 106 return err 107 } 108 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 109 return err 110 } 111 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 112 return err 113 } 114 if err = addClientUserAgent(stack); err != nil { 115 return err 116 } 117 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 118 return err 119 } 120 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 121 return err 122 } 123 if err = addOpCreateKeyPairValidationMiddleware(stack); err != nil { 124 return err 125 } 126 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateKeyPair(options.Region), middleware.Before); err != nil { 127 return err 128 } 129 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 130 return err 131 } 132 if err = addResponseErrorMiddleware(stack); err != nil { 133 return err 134 } 135 if err = addRequestResponseLogging(stack, options); err != nil { 136 return err 137 } 138 return nil 139} 140 141func newServiceMetadataMiddleware_opCreateKeyPair(region string) *awsmiddleware.RegisterServiceMetadata { 142 return &awsmiddleware.RegisterServiceMetadata{ 143 Region: region, 144 ServiceID: ServiceID, 145 SigningName: "ec2", 146 OperationName: "CreateKeyPair", 147 } 148} 149