1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package servicediscovery
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/servicediscovery/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Creates a service, which defines the configuration for the following
16// entities:
17//
18// * For public and private DNS namespaces, one of the following
19// combinations of DNS records in Amazon Route 53:
20//
21// * A
22//
23// * AAAA
24//
25// * A and AAAA
26//
27// *
28// SRV
29//
30// * CNAME
31//
32// * Optionally, a health check
33//
34// After you create the service, you
35// can submit a RegisterInstance
36// (https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html)
37// request, and AWS Cloud Map uses the values in the configuration to create the
38// specified entities. For the current quota on the number of instances that you
39// can register using the same namespace and using the same service, see AWS Cloud
40// Map Limits
41// (https://docs.aws.amazon.com/cloud-map/latest/dg/cloud-map-limits.html) in the
42// AWS Cloud Map Developer Guide.
43func (c *Client) CreateService(ctx context.Context, params *CreateServiceInput, optFns ...func(*Options)) (*CreateServiceOutput, error) {
44	if params == nil {
45		params = &CreateServiceInput{}
46	}
47
48	result, metadata, err := c.invokeOperation(ctx, "CreateService", params, optFns, addOperationCreateServiceMiddlewares)
49	if err != nil {
50		return nil, err
51	}
52
53	out := result.(*CreateServiceOutput)
54	out.ResultMetadata = metadata
55	return out, nil
56}
57
58type CreateServiceInput struct {
59
60	// The name that you want to assign to the service. If you want AWS Cloud Map to
61	// create an SRV record when you register an instance, and if you're using a system
62	// that requires a specific SRV format, such as HAProxy (http://www.haproxy.org/),
63	// specify the following for Name:
64	//
65	// * Start the name with an underscore (_), such
66	// as _exampleservice
67	//
68	// * End the name with ._protocol, such as ._tcp
69	//
70	// When you
71	// register an instance, AWS Cloud Map creates an SRV record and assigns a name to
72	// the record by concatenating the service name and the namespace name, for
73	// example: _exampleservice._tcp.example.com For a single DNS namespace, you cannot
74	// create two services with names that differ only by case (such as EXAMPLE and
75	// example). Otherwise, these services will have the same DNS name. However, you
76	// can create multiple HTTP services with names that differ only by case because
77	// HTTP services are case sensitive.
78	//
79	// This member is required.
80	Name *string
81
82	// A unique string that identifies the request and that allows failed CreateService
83	// requests to be retried without the risk of executing the operation twice.
84	// CreatorRequestId can be any unique string, for example, a date/time stamp.
85	CreatorRequestId *string
86
87	// A description for the service.
88	Description *string
89
90	// A complex type that contains information about the Amazon Route 53 records that
91	// you want AWS Cloud Map to create when you register an instance.
92	DnsConfig *types.DnsConfig
93
94	// Public DNS and HTTP namespaces only. A complex type that contains settings for
95	// an optional Route 53 health check. If you specify settings for a health check,
96	// AWS Cloud Map associates the health check with all the Route 53 DNS records that
97	// you specify in DnsConfig. If you specify a health check configuration, you can
98	// specify either HealthCheckCustomConfig or HealthCheckConfig but not both. For
99	// information about the charges for health checks, see AWS Cloud Map Pricing
100	// (http://aws.amazon.com/cloud-map/pricing/).
101	HealthCheckConfig *types.HealthCheckConfig
102
103	// A complex type that contains information about an optional custom health check.
104	// If you specify a health check configuration, you can specify either
105	// HealthCheckCustomConfig or HealthCheckConfig but not both. You can't add,
106	// update, or delete a HealthCheckCustomConfig configuration from an existing
107	// service.
108	HealthCheckCustomConfig *types.HealthCheckCustomConfig
109
110	// The ID of the namespace that you want to use to create the service.
111	NamespaceId *string
112
113	// The tags to add to the service. Each tag consists of a key and an optional
114	// value, both of which you define. Tag keys can have a maximum character length of
115	// 128 characters, and tag values can have a maximum length of 256 characters.
116	Tags []types.Tag
117
118	// If present, specifies that the service instances are only discoverable using the
119	// DiscoverInstances API operation. No DNS records will be registered for the
120	// service instances. The only valid value is HTTP.
121	Type types.ServiceTypeOption
122}
123
124type CreateServiceOutput struct {
125
126	// A complex type that contains information about the new service.
127	Service *types.Service
128
129	// Metadata pertaining to the operation's result.
130	ResultMetadata middleware.Metadata
131}
132
133func addOperationCreateServiceMiddlewares(stack *middleware.Stack, options Options) (err error) {
134	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateService{}, middleware.After)
135	if err != nil {
136		return err
137	}
138	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateService{}, middleware.After)
139	if err != nil {
140		return err
141	}
142	if err = addSetLoggerMiddleware(stack, options); err != nil {
143		return err
144	}
145	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
146		return err
147	}
148	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
149		return err
150	}
151	if err = addResolveEndpointMiddleware(stack, options); err != nil {
152		return err
153	}
154	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
155		return err
156	}
157	if err = addRetryMiddlewares(stack, options); err != nil {
158		return err
159	}
160	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
161		return err
162	}
163	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
164		return err
165	}
166	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
167		return err
168	}
169	if err = addClientUserAgent(stack); err != nil {
170		return err
171	}
172	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
173		return err
174	}
175	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
176		return err
177	}
178	if err = addIdempotencyToken_opCreateServiceMiddleware(stack, options); err != nil {
179		return err
180	}
181	if err = addOpCreateServiceValidationMiddleware(stack); err != nil {
182		return err
183	}
184	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateService(options.Region), middleware.Before); err != nil {
185		return err
186	}
187	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
188		return err
189	}
190	if err = addResponseErrorMiddleware(stack); err != nil {
191		return err
192	}
193	if err = addRequestResponseLogging(stack, options); err != nil {
194		return err
195	}
196	return nil
197}
198
199type idempotencyToken_initializeOpCreateService struct {
200	tokenProvider IdempotencyTokenProvider
201}
202
203func (*idempotencyToken_initializeOpCreateService) ID() string {
204	return "OperationIdempotencyTokenAutoFill"
205}
206
207func (m *idempotencyToken_initializeOpCreateService) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
208	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
209) {
210	if m.tokenProvider == nil {
211		return next.HandleInitialize(ctx, in)
212	}
213
214	input, ok := in.Parameters.(*CreateServiceInput)
215	if !ok {
216		return out, metadata, fmt.Errorf("expected middleware input to be of type *CreateServiceInput ")
217	}
218
219	if input.CreatorRequestId == nil {
220		t, err := m.tokenProvider.GetIdempotencyToken()
221		if err != nil {
222			return out, metadata, err
223		}
224		input.CreatorRequestId = &t
225	}
226	return next.HandleInitialize(ctx, in)
227}
228func addIdempotencyToken_opCreateServiceMiddleware(stack *middleware.Stack, cfg Options) error {
229	return stack.Initialize.Add(&idempotencyToken_initializeOpCreateService{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
230}
231
232func newServiceMetadataMiddleware_opCreateService(region string) *awsmiddleware.RegisterServiceMetadata {
233	return &awsmiddleware.RegisterServiceMetadata{
234		Region:        region,
235		ServiceID:     ServiceID,
236		SigningName:   "servicediscovery",
237		OperationName: "CreateService",
238	}
239}
240