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/smithy-go/middleware"
10	smithyhttp "github.com/aws/smithy-go/transport/http"
11)
12
13// Creates a route in a route table within a VPC. You must specify one of the
14// following targets: internet gateway or virtual private gateway, NAT instance,
15// NAT gateway, VPC peering connection, network interface, egress-only internet
16// gateway, or transit gateway. When determining how to route traffic, we use the
17// route with the most specific match. For example, traffic is destined for the
18// IPv4 address 192.0.2.3, and the route table includes the following two IPv4
19// routes:
20//
21// * 192.0.2.0/24 (goes to some target A)
22//
23// * 192.0.2.0/28 (goes to some
24// target B)
25//
26// Both routes apply to the traffic destined for 192.0.2.3. However, the
27// second route in the list covers a smaller number of IP addresses and is
28// therefore more specific, so we use that route to determine where to target the
29// traffic. For more information about route tables, see Route Tables
30// (https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Route_Tables.html) in the
31// Amazon Virtual Private Cloud User Guide.
32func (c *Client) CreateRoute(ctx context.Context, params *CreateRouteInput, optFns ...func(*Options)) (*CreateRouteOutput, error) {
33	if params == nil {
34		params = &CreateRouteInput{}
35	}
36
37	result, metadata, err := c.invokeOperation(ctx, "CreateRoute", params, optFns, addOperationCreateRouteMiddlewares)
38	if err != nil {
39		return nil, err
40	}
41
42	out := result.(*CreateRouteOutput)
43	out.ResultMetadata = metadata
44	return out, nil
45}
46
47type CreateRouteInput struct {
48
49	// The ID of the route table for the route.
50	//
51	// This member is required.
52	RouteTableId *string
53
54	// The ID of the carrier gateway. You can only use this option when the VPC
55	// contains a subnet which is associated with a Wavelength Zone.
56	CarrierGatewayId *string
57
58	// The IPv4 CIDR address block used for the destination match. Routing decisions
59	// are based on the most specific match. We modify the specified CIDR block to its
60	// canonical form; for example, if you specify 100.68.0.18/18, we modify it to
61	// 100.68.0.0/18.
62	DestinationCidrBlock *string
63
64	// The IPv6 CIDR block used for the destination match. Routing decisions are based
65	// on the most specific match.
66	DestinationIpv6CidrBlock *string
67
68	// The ID of a prefix list used for the destination match.
69	DestinationPrefixListId *string
70
71	// Checks whether you have the required permissions for the action, without
72	// actually making the request, and provides an error response. If you have the
73	// required permissions, the error response is DryRunOperation. Otherwise, it is
74	// UnauthorizedOperation.
75	DryRun bool
76
77	// [IPv6 traffic only] The ID of an egress-only internet gateway.
78	EgressOnlyInternetGatewayId *string
79
80	// The ID of an internet gateway or virtual private gateway attached to your VPC.
81	GatewayId *string
82
83	// The ID of a NAT instance in your VPC. The operation fails if you specify an
84	// instance ID unless exactly one network interface is attached.
85	InstanceId *string
86
87	// The ID of the local gateway.
88	LocalGatewayId *string
89
90	// [IPv4 traffic only] The ID of a NAT gateway.
91	NatGatewayId *string
92
93	// The ID of a network interface.
94	NetworkInterfaceId *string
95
96	// The ID of a transit gateway.
97	TransitGatewayId *string
98
99	// The ID of a VPC endpoint. Supported for Gateway Load Balancer endpoints only.
100	VpcEndpointId *string
101
102	// The ID of a VPC peering connection.
103	VpcPeeringConnectionId *string
104}
105
106type CreateRouteOutput struct {
107
108	// Returns true if the request succeeds; otherwise, it returns an error.
109	Return bool
110
111	// Metadata pertaining to the operation's result.
112	ResultMetadata middleware.Metadata
113}
114
115func addOperationCreateRouteMiddlewares(stack *middleware.Stack, options Options) (err error) {
116	err = stack.Serialize.Add(&awsEc2query_serializeOpCreateRoute{}, middleware.After)
117	if err != nil {
118		return err
119	}
120	err = stack.Deserialize.Add(&awsEc2query_deserializeOpCreateRoute{}, middleware.After)
121	if err != nil {
122		return err
123	}
124	if err = addSetLoggerMiddleware(stack, options); err != nil {
125		return err
126	}
127	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
128		return err
129	}
130	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
131		return err
132	}
133	if err = addResolveEndpointMiddleware(stack, options); err != nil {
134		return err
135	}
136	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
137		return err
138	}
139	if err = addRetryMiddlewares(stack, options); err != nil {
140		return err
141	}
142	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
143		return err
144	}
145	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
146		return err
147	}
148	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
149		return err
150	}
151	if err = addClientUserAgent(stack); err != nil {
152		return err
153	}
154	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
155		return err
156	}
157	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
158		return err
159	}
160	if err = addOpCreateRouteValidationMiddleware(stack); err != nil {
161		return err
162	}
163	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateRoute(options.Region), middleware.Before); err != nil {
164		return err
165	}
166	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
167		return err
168	}
169	if err = addResponseErrorMiddleware(stack); err != nil {
170		return err
171	}
172	if err = addRequestResponseLogging(stack, options); err != nil {
173		return err
174	}
175	return nil
176}
177
178func newServiceMetadataMiddleware_opCreateRoute(region string) *awsmiddleware.RegisterServiceMetadata {
179	return &awsmiddleware.RegisterServiceMetadata{
180		Region:        region,
181		ServiceID:     ServiceID,
182		SigningName:   "ec2",
183		OperationName: "CreateRoute",
184	}
185}
186