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. This action 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 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 Cloud Map
40// quotas (https://docs.aws.amazon.com/cloud-map/latest/dg/cloud-map-limits.html)
41// in the Cloud Map Developer Guide.
42func (c *Client) CreateService(ctx context.Context, params *CreateServiceInput, optFns ...func(*Options)) (*CreateServiceOutput, error) {
43	if params == nil {
44		params = &CreateServiceInput{}
45	}
46
47	result, metadata, err := c.invokeOperation(ctx, "CreateService", params, optFns, c.addOperationCreateServiceMiddlewares)
48	if err != nil {
49		return nil, err
50	}
51
52	out := result.(*CreateServiceOutput)
53	out.ResultMetadata = metadata
54	return out, nil
55}
56
57type CreateServiceInput struct {
58
59	// The name that you want to assign to the service. If you want Cloud Map to create
60	// an SRV record when you register an instance and you're using a system that
61	// requires a specific SRV format, such as HAProxy (http://www.haproxy.org/),
62	// specify the following for Name:
63	//
64	// * Start the name with an underscore (_), such
65	// as _exampleservice.
66	//
67	// * End the name with ._protocol, such as ._tcp.
68	//
69	// When you
70	// register an instance, Cloud Map creates an SRV record and assigns a name to the
71	// record by concatenating the service name and the namespace name (for example,
72	// _exampleservice._tcp.example.com). For services that are accessible by DNS
73	// queries, you can't create multiple services with names that differ only by case
74	// (such as EXAMPLE and example). Otherwise, these services have the same DNS name
75	// and can't be distinguished. However, if you use a namespace that's only
76	// accessible by API calls, then you can create services that with names that
77	// differ only by case.
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 running the operation twice.
84	// CreatorRequestId can be any unique string (for example, a date/timestamp).
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 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	// Cloud Map associates the health check with all the Route 53 DNS records that you
97	// 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 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. The
111	// namespace ID must be specified, but it can be specified either here or in the
112	// DnsConfig object.
113	NamespaceId *string
114
115	// The tags to add to the service. Each tag consists of a key and an optional value
116	// that you define. Tags keys can be up to 128 characters in length, and tag values
117	// can be up to 256 characters in length.
118	Tags []types.Tag
119
120	// If present, specifies that the service instances are only discoverable using the
121	// DiscoverInstances API operation. No DNS records is registered for the service
122	// instances. The only valid value is HTTP.
123	Type types.ServiceTypeOption
124
125	noSmithyDocumentSerde
126}
127
128type CreateServiceOutput struct {
129
130	// A complex type that contains information about the new service.
131	Service *types.Service
132
133	// Metadata pertaining to the operation's result.
134	ResultMetadata middleware.Metadata
135
136	noSmithyDocumentSerde
137}
138
139func (c *Client) addOperationCreateServiceMiddlewares(stack *middleware.Stack, options Options) (err error) {
140	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateService{}, middleware.After)
141	if err != nil {
142		return err
143	}
144	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateService{}, middleware.After)
145	if err != nil {
146		return err
147	}
148	if err = addSetLoggerMiddleware(stack, options); err != nil {
149		return err
150	}
151	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
152		return err
153	}
154	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
155		return err
156	}
157	if err = addResolveEndpointMiddleware(stack, options); err != nil {
158		return err
159	}
160	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
161		return err
162	}
163	if err = addRetryMiddlewares(stack, options); err != nil {
164		return err
165	}
166	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
167		return err
168	}
169	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
170		return err
171	}
172	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
173		return err
174	}
175	if err = addClientUserAgent(stack); err != nil {
176		return err
177	}
178	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
179		return err
180	}
181	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
182		return err
183	}
184	if err = addIdempotencyToken_opCreateServiceMiddleware(stack, options); err != nil {
185		return err
186	}
187	if err = addOpCreateServiceValidationMiddleware(stack); err != nil {
188		return err
189	}
190	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateService(options.Region), middleware.Before); err != nil {
191		return err
192	}
193	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
194		return err
195	}
196	if err = addResponseErrorMiddleware(stack); err != nil {
197		return err
198	}
199	if err = addRequestResponseLogging(stack, options); err != nil {
200		return err
201	}
202	return nil
203}
204
205type idempotencyToken_initializeOpCreateService struct {
206	tokenProvider IdempotencyTokenProvider
207}
208
209func (*idempotencyToken_initializeOpCreateService) ID() string {
210	return "OperationIdempotencyTokenAutoFill"
211}
212
213func (m *idempotencyToken_initializeOpCreateService) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
214	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
215) {
216	if m.tokenProvider == nil {
217		return next.HandleInitialize(ctx, in)
218	}
219
220	input, ok := in.Parameters.(*CreateServiceInput)
221	if !ok {
222		return out, metadata, fmt.Errorf("expected middleware input to be of type *CreateServiceInput ")
223	}
224
225	if input.CreatorRequestId == nil {
226		t, err := m.tokenProvider.GetIdempotencyToken()
227		if err != nil {
228			return out, metadata, err
229		}
230		input.CreatorRequestId = &t
231	}
232	return next.HandleInitialize(ctx, in)
233}
234func addIdempotencyToken_opCreateServiceMiddleware(stack *middleware.Stack, cfg Options) error {
235	return stack.Initialize.Add(&idempotencyToken_initializeOpCreateService{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
236}
237
238func newServiceMetadataMiddleware_opCreateService(region string) *awsmiddleware.RegisterServiceMetadata {
239	return &awsmiddleware.RegisterServiceMetadata{
240		Region:        region,
241		ServiceID:     ServiceID,
242		SigningName:   "servicediscovery",
243		OperationName: "CreateService",
244	}
245}
246