1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package elasticloadbalancing
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// Generates a stickiness policy with sticky session lifetimes controlled by the
14// lifetime of the browser (user-agent) or a specified expiration period. This
15// policy can be associated only with HTTP/HTTPS listeners. When a load balancer
16// implements this policy, the load balancer uses a special cookie to track the
17// instance for each request. When the load balancer receives a request, it first
18// checks to see if this cookie is present in the request. If so, the load balancer
19// sends the request to the application server specified in the cookie. If not, the
20// load balancer sends the request to a server that is chosen based on the existing
21// load-balancing algorithm. A cookie is inserted into the response for binding
22// subsequent requests from the same user to that server. The validity of the
23// cookie is based on the cookie expiration time, which is specified in the policy
24// configuration. For more information, see Duration-Based Session Stickiness
25// (https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-sticky-sessions.html#enable-sticky-sessions-duration)
26// in the Classic Load Balancers Guide.
27func (c *Client) CreateLBCookieStickinessPolicy(ctx context.Context, params *CreateLBCookieStickinessPolicyInput, optFns ...func(*Options)) (*CreateLBCookieStickinessPolicyOutput, error) {
28	if params == nil {
29		params = &CreateLBCookieStickinessPolicyInput{}
30	}
31
32	result, metadata, err := c.invokeOperation(ctx, "CreateLBCookieStickinessPolicy", params, optFns, addOperationCreateLBCookieStickinessPolicyMiddlewares)
33	if err != nil {
34		return nil, err
35	}
36
37	out := result.(*CreateLBCookieStickinessPolicyOutput)
38	out.ResultMetadata = metadata
39	return out, nil
40}
41
42// Contains the parameters for CreateLBCookieStickinessPolicy.
43type CreateLBCookieStickinessPolicyInput struct {
44
45	// The name of the load balancer.
46	//
47	// This member is required.
48	LoadBalancerName *string
49
50	// The name of the policy being created. Policy names must consist of alphanumeric
51	// characters and dashes (-). This name must be unique within the set of policies
52	// for this load balancer.
53	//
54	// This member is required.
55	PolicyName *string
56
57	// The time period, in seconds, after which the cookie should be considered stale.
58	// If you do not specify this parameter, the default value is 0, which indicates
59	// that the sticky session should last for the duration of the browser session.
60	CookieExpirationPeriod *int64
61}
62
63// Contains the output for CreateLBCookieStickinessPolicy.
64type CreateLBCookieStickinessPolicyOutput struct {
65	// Metadata pertaining to the operation's result.
66	ResultMetadata middleware.Metadata
67}
68
69func addOperationCreateLBCookieStickinessPolicyMiddlewares(stack *middleware.Stack, options Options) (err error) {
70	err = stack.Serialize.Add(&awsAwsquery_serializeOpCreateLBCookieStickinessPolicy{}, middleware.After)
71	if err != nil {
72		return err
73	}
74	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpCreateLBCookieStickinessPolicy{}, middleware.After)
75	if err != nil {
76		return err
77	}
78	if err = addSetLoggerMiddleware(stack, options); err != nil {
79		return err
80	}
81	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
82		return err
83	}
84	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
85		return err
86	}
87	if err = addResolveEndpointMiddleware(stack, options); err != nil {
88		return err
89	}
90	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
91		return err
92	}
93	if err = addRetryMiddlewares(stack, options); err != nil {
94		return err
95	}
96	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
97		return err
98	}
99	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
100		return err
101	}
102	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
103		return err
104	}
105	if err = addClientUserAgent(stack); err != nil {
106		return err
107	}
108	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
109		return err
110	}
111	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
112		return err
113	}
114	if err = addOpCreateLBCookieStickinessPolicyValidationMiddleware(stack); err != nil {
115		return err
116	}
117	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateLBCookieStickinessPolicy(options.Region), middleware.Before); err != nil {
118		return err
119	}
120	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
121		return err
122	}
123	if err = addResponseErrorMiddleware(stack); err != nil {
124		return err
125	}
126	if err = addRequestResponseLogging(stack, options); err != nil {
127		return err
128	}
129	return nil
130}
131
132func newServiceMetadataMiddleware_opCreateLBCookieStickinessPolicy(region string) *awsmiddleware.RegisterServiceMetadata {
133	return &awsmiddleware.RegisterServiceMetadata{
134		Region:        region,
135		ServiceID:     ServiceID,
136		SigningName:   "elasticloadbalancing",
137		OperationName: "CreateLBCookieStickinessPolicy",
138	}
139}
140