1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package ec2 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/ec2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Creates a NAT gateway in the specified public subnet. This action creates a 16// network interface in the specified subnet with a private IP address from the IP 17// address range of the subnet. Internet-bound traffic from a private subnet can be 18// routed to the NAT gateway, therefore enabling instances in the private subnet to 19// connect to the internet. For more information, see NAT Gateways 20// (https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html) in the 21// Amazon Virtual Private Cloud User Guide. 22func (c *Client) CreateNatGateway(ctx context.Context, params *CreateNatGatewayInput, optFns ...func(*Options)) (*CreateNatGatewayOutput, error) { 23 if params == nil { 24 params = &CreateNatGatewayInput{} 25 } 26 27 result, metadata, err := c.invokeOperation(ctx, "CreateNatGateway", params, optFns, addOperationCreateNatGatewayMiddlewares) 28 if err != nil { 29 return nil, err 30 } 31 32 out := result.(*CreateNatGatewayOutput) 33 out.ResultMetadata = metadata 34 return out, nil 35} 36 37type CreateNatGatewayInput struct { 38 39 // The allocation ID of an Elastic IP address to associate with the NAT gateway. If 40 // the Elastic IP address is associated with another resource, you must first 41 // disassociate it. 42 // 43 // This member is required. 44 AllocationId *string 45 46 // The subnet in which to create the NAT gateway. 47 // 48 // This member is required. 49 SubnetId *string 50 51 // Unique, case-sensitive identifier that you provide to ensure the idempotency of 52 // the request. For more information, see How to Ensure Idempotency 53 // (https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html). 54 // Constraint: Maximum 64 ASCII characters. 55 ClientToken *string 56 57 // Checks whether you have the required permissions for the action, without 58 // actually making the request, and provides an error response. If you have the 59 // required permissions, the error response is DryRunOperation. Otherwise, it is 60 // UnauthorizedOperation. 61 DryRun bool 62 63 // The tags to assign to the NAT gateway. 64 TagSpecifications []types.TagSpecification 65} 66 67type CreateNatGatewayOutput struct { 68 69 // Unique, case-sensitive identifier to ensure the idempotency of the request. Only 70 // returned if a client token was provided in the request. 71 ClientToken *string 72 73 // Information about the NAT gateway. 74 NatGateway *types.NatGateway 75 76 // Metadata pertaining to the operation's result. 77 ResultMetadata middleware.Metadata 78} 79 80func addOperationCreateNatGatewayMiddlewares(stack *middleware.Stack, options Options) (err error) { 81 err = stack.Serialize.Add(&awsEc2query_serializeOpCreateNatGateway{}, middleware.After) 82 if err != nil { 83 return err 84 } 85 err = stack.Deserialize.Add(&awsEc2query_deserializeOpCreateNatGateway{}, middleware.After) 86 if err != nil { 87 return err 88 } 89 if err = addSetLoggerMiddleware(stack, options); err != nil { 90 return err 91 } 92 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 93 return err 94 } 95 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 96 return err 97 } 98 if err = addResolveEndpointMiddleware(stack, options); err != nil { 99 return err 100 } 101 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 102 return err 103 } 104 if err = addRetryMiddlewares(stack, options); err != nil { 105 return err 106 } 107 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 108 return err 109 } 110 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 111 return err 112 } 113 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 114 return err 115 } 116 if err = addClientUserAgent(stack); err != nil { 117 return err 118 } 119 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 120 return err 121 } 122 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addIdempotencyToken_opCreateNatGatewayMiddleware(stack, options); err != nil { 126 return err 127 } 128 if err = addOpCreateNatGatewayValidationMiddleware(stack); err != nil { 129 return err 130 } 131 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateNatGateway(options.Region), middleware.Before); err != nil { 132 return err 133 } 134 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 135 return err 136 } 137 if err = addResponseErrorMiddleware(stack); err != nil { 138 return err 139 } 140 if err = addRequestResponseLogging(stack, options); err != nil { 141 return err 142 } 143 return nil 144} 145 146type idempotencyToken_initializeOpCreateNatGateway struct { 147 tokenProvider IdempotencyTokenProvider 148} 149 150func (*idempotencyToken_initializeOpCreateNatGateway) ID() string { 151 return "OperationIdempotencyTokenAutoFill" 152} 153 154func (m *idempotencyToken_initializeOpCreateNatGateway) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) ( 155 out middleware.InitializeOutput, metadata middleware.Metadata, err error, 156) { 157 if m.tokenProvider == nil { 158 return next.HandleInitialize(ctx, in) 159 } 160 161 input, ok := in.Parameters.(*CreateNatGatewayInput) 162 if !ok { 163 return out, metadata, fmt.Errorf("expected middleware input to be of type *CreateNatGatewayInput ") 164 } 165 166 if input.ClientToken == nil { 167 t, err := m.tokenProvider.GetIdempotencyToken() 168 if err != nil { 169 return out, metadata, err 170 } 171 input.ClientToken = &t 172 } 173 return next.HandleInitialize(ctx, in) 174} 175func addIdempotencyToken_opCreateNatGatewayMiddleware(stack *middleware.Stack, cfg Options) error { 176 return stack.Initialize.Add(&idempotencyToken_initializeOpCreateNatGateway{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before) 177} 178 179func newServiceMetadataMiddleware_opCreateNatGateway(region string) *awsmiddleware.RegisterServiceMetadata { 180 return &awsmiddleware.RegisterServiceMetadata{ 181 Region: region, 182 ServiceID: ServiceID, 183 SigningName: "ec2", 184 OperationName: "CreateNatGateway", 185 } 186} 187