1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package route53
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/aws-sdk-go-v2/service/route53/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Creates a configuration for DNS query logging. After you create a query logging
15// configuration, Amazon Route 53 begins to publish log data to an Amazon
16// CloudWatch Logs log group. DNS query logs contain information about the queries
17// that Route 53 receives for a specified public hosted zone, such as the
18// following:
19//
20// * Route 53 edge location that responded to the DNS query
21//
22// * Domain
23// or subdomain that was requested
24//
25// * DNS record type, such as A or AAAA
26//
27// * DNS
28// response code, such as NoError or ServFail
29//
30// Log Group and Resource Policy Before
31// you create a query logging configuration, perform the following operations. If
32// you create a query logging configuration using the Route 53 console, Route 53
33// performs these operations automatically.
34//
35// * Create a CloudWatch Logs log group,
36// and make note of the ARN, which you specify when you create a query logging
37// configuration. Note the following:
38//
39// * You must create the log group in the
40// us-east-1 region.
41//
42// * You must use the same AWS account to create the log group
43// and the hosted zone that you want to configure query logging for.
44//
45// * When you
46// create log groups for query logging, we recommend that you use a consistent
47// prefix, for example: /aws/route53/hosted zone name  In the next step, you'll
48// create a resource policy, which controls access to one or more log groups and
49// the associated AWS resources, such as Route 53 hosted zones. There's a limit on
50// the number of resource policies that you can create, so we recommend that you
51// use a consistent prefix so you can use the same resource policy for all the log
52// groups that you create for query logging.
53//
54// * Create a CloudWatch Logs resource
55// policy, and give it the permissions that Route 53 needs to create log streams
56// and to send query logs to log streams. For the value of Resource, specify the
57// ARN for the log group that you created in the previous step. To use the same
58// resource policy for all the CloudWatch Logs log groups that you created for
59// query logging configurations, replace the hosted zone name with , for example:
60// arn:aws:logs:us-east-1:123412341234:log-group:/aws/route53/ You can't use the
61// CloudWatch console to create or edit a resource policy. You must use the
62// CloudWatch API, one of the AWS SDKs, or the AWS CLI.
63//
64// Log Streams and Edge
65// Locations When Route 53 finishes creating the configuration for DNS query
66// logging, it does the following:
67//
68// * Creates a log stream for an edge location the
69// first time that the edge location responds to DNS queries for the specified
70// hosted zone. That log stream is used to log all queries that Route 53 responds
71// to for that edge location.
72//
73// * Begins to send query logs to the applicable log
74// stream.
75//
76// The name of each log stream is in the following format:  hosted zone
77// ID/edge location code  The edge location code is a three-letter code and an
78// arbitrarily assigned number, for example, DFW3. The three-letter code typically
79// corresponds with the International Air Transport Association airport code for an
80// airport near the edge location. (These abbreviations might change in the
81// future.) For a list of edge locations, see "The Route 53 Global Network" on the
82// Route 53 Product Details (http://aws.amazon.com/route53/details/) page. Queries
83// That Are Logged Query logs contain only the queries that DNS resolvers forward
84// to Route 53. If a DNS resolver has already cached the response to a query (such
85// as the IP address for a load balancer for example.com), the resolver will
86// continue to return the cached response. It doesn't forward another query to
87// Route 53 until the TTL for the corresponding resource record set expires.
88// Depending on how many DNS queries are submitted for a resource record set, and
89// depending on the TTL for that resource record set, query logs might contain
90// information about only one query out of every several thousand queries that are
91// submitted to DNS. For more information about how DNS works, see Routing Internet
92// Traffic to Your Website or Web Application
93// (https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/welcome-dns-service.html)
94// in the Amazon Route 53 Developer Guide. Log File Format For a list of the values
95// in each query log and the format of each value, see Logging DNS Queries
96// (https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/query-logs.html) in
97// the Amazon Route 53 Developer Guide. Pricing For information about charges for
98// query logs, see Amazon CloudWatch Pricing
99// (http://aws.amazon.com/cloudwatch/pricing/). How to Stop Logging If you want
100// Route 53 to stop sending query logs to CloudWatch Logs, delete the query logging
101// configuration. For more information, see DeleteQueryLoggingConfig
102// (https://docs.aws.amazon.com/Route53/latest/APIReference/API_DeleteQueryLoggingConfig.html).
103func (c *Client) CreateQueryLoggingConfig(ctx context.Context, params *CreateQueryLoggingConfigInput, optFns ...func(*Options)) (*CreateQueryLoggingConfigOutput, error) {
104	if params == nil {
105		params = &CreateQueryLoggingConfigInput{}
106	}
107
108	result, metadata, err := c.invokeOperation(ctx, "CreateQueryLoggingConfig", params, optFns, addOperationCreateQueryLoggingConfigMiddlewares)
109	if err != nil {
110		return nil, err
111	}
112
113	out := result.(*CreateQueryLoggingConfigOutput)
114	out.ResultMetadata = metadata
115	return out, nil
116}
117
118type CreateQueryLoggingConfigInput struct {
119
120	// The Amazon Resource Name (ARN) for the log group that you want to Amazon Route
121	// 53 to send query logs to. This is the format of the ARN:
122	// arn:aws:logs:region:account-id:log-group:log_group_name To get the ARN for a log
123	// group, you can use the CloudWatch console, the DescribeLogGroups
124	// (https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html)
125	// API action, the describe-log-groups
126	// (https://docs.aws.amazon.com/cli/latest/reference/logs/describe-log-groups.html)
127	// command, or the applicable command in one of the AWS SDKs.
128	//
129	// This member is required.
130	CloudWatchLogsLogGroupArn *string
131
132	// The ID of the hosted zone that you want to log queries for. You can log queries
133	// only for public hosted zones.
134	//
135	// This member is required.
136	HostedZoneId *string
137}
138
139type CreateQueryLoggingConfigOutput struct {
140
141	// The unique URL representing the new query logging configuration.
142	//
143	// This member is required.
144	Location *string
145
146	// A complex type that contains the ID for a query logging configuration, the ID of
147	// the hosted zone that you want to log queries for, and the ARN for the log group
148	// that you want Amazon Route 53 to send query logs to.
149	//
150	// This member is required.
151	QueryLoggingConfig *types.QueryLoggingConfig
152
153	// Metadata pertaining to the operation's result.
154	ResultMetadata middleware.Metadata
155}
156
157func addOperationCreateQueryLoggingConfigMiddlewares(stack *middleware.Stack, options Options) (err error) {
158	err = stack.Serialize.Add(&awsRestxml_serializeOpCreateQueryLoggingConfig{}, middleware.After)
159	if err != nil {
160		return err
161	}
162	err = stack.Deserialize.Add(&awsRestxml_deserializeOpCreateQueryLoggingConfig{}, middleware.After)
163	if err != nil {
164		return err
165	}
166	if err = addSetLoggerMiddleware(stack, options); err != nil {
167		return err
168	}
169	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
170		return err
171	}
172	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
173		return err
174	}
175	if err = addResolveEndpointMiddleware(stack, options); err != nil {
176		return err
177	}
178	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
179		return err
180	}
181	if err = addRetryMiddlewares(stack, options); err != nil {
182		return err
183	}
184	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
185		return err
186	}
187	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
188		return err
189	}
190	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
191		return err
192	}
193	if err = addClientUserAgent(stack); err != nil {
194		return err
195	}
196	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
197		return err
198	}
199	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
200		return err
201	}
202	if err = addOpCreateQueryLoggingConfigValidationMiddleware(stack); err != nil {
203		return err
204	}
205	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateQueryLoggingConfig(options.Region), middleware.Before); err != nil {
206		return err
207	}
208	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
209		return err
210	}
211	if err = addResponseErrorMiddleware(stack); err != nil {
212		return err
213	}
214	if err = addSanitizeURLMiddleware(stack); err != nil {
215		return err
216	}
217	if err = addRequestResponseLogging(stack, options); err != nil {
218		return err
219	}
220	return nil
221}
222
223func newServiceMetadataMiddleware_opCreateQueryLoggingConfig(region string) *awsmiddleware.RegisterServiceMetadata {
224	return &awsmiddleware.RegisterServiceMetadata{
225		Region:        region,
226		ServiceID:     ServiceID,
227		SigningName:   "route53",
228		OperationName: "CreateQueryLoggingConfig",
229	}
230}
231