1// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
2
3package rekognition_test
4
5import (
6	"fmt"
7	"strings"
8	"time"
9
10	"github.com/aws/aws-sdk-go/aws"
11	"github.com/aws/aws-sdk-go/aws/awserr"
12	"github.com/aws/aws-sdk-go/aws/session"
13	"github.com/aws/aws-sdk-go/service/rekognition"
14)
15
16var _ time.Duration
17var _ strings.Reader
18var _ aws.Config
19
20func parseTime(layout, value string) *time.Time {
21	t, err := time.Parse(layout, value)
22	if err != nil {
23		panic(err)
24	}
25	return &t
26}
27
28// To compare two images
29//
30// This operation compares the largest face detected in the source image with each face
31// detected in the target image.
32func ExampleRekognition_CompareFaces_shared00() {
33	svc := rekognition.New(session.New())
34	input := &rekognition.CompareFacesInput{
35		SimilarityThreshold: aws.Float64(90.000000),
36		SourceImage: &rekognition.Image{
37			S3Object: &rekognition.S3Object{
38				Bucket: aws.String("mybucket"),
39				Name:   aws.String("mysourceimage"),
40			},
41		},
42		TargetImage: &rekognition.Image{
43			S3Object: &rekognition.S3Object{
44				Bucket: aws.String("mybucket"),
45				Name:   aws.String("mytargetimage"),
46			},
47		},
48	}
49
50	result, err := svc.CompareFaces(input)
51	if err != nil {
52		if aerr, ok := err.(awserr.Error); ok {
53			switch aerr.Code() {
54			case rekognition.ErrCodeInvalidParameterException:
55				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
56			case rekognition.ErrCodeInvalidS3ObjectException:
57				fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
58			case rekognition.ErrCodeImageTooLargeException:
59				fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
60			case rekognition.ErrCodeAccessDeniedException:
61				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
62			case rekognition.ErrCodeInternalServerError:
63				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
64			case rekognition.ErrCodeThrottlingException:
65				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
66			case rekognition.ErrCodeProvisionedThroughputExceededException:
67				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
68			case rekognition.ErrCodeInvalidImageFormatException:
69				fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
70			default:
71				fmt.Println(aerr.Error())
72			}
73		} else {
74			// Print the error, cast err to awserr.Error to get the Code and
75			// Message from an error.
76			fmt.Println(err.Error())
77		}
78		return
79	}
80
81	fmt.Println(result)
82}
83
84// To create a collection
85//
86// This operation creates a Rekognition collection for storing image data.
87func ExampleRekognition_CreateCollection_shared00() {
88	svc := rekognition.New(session.New())
89	input := &rekognition.CreateCollectionInput{
90		CollectionId: aws.String("myphotos"),
91	}
92
93	result, err := svc.CreateCollection(input)
94	if err != nil {
95		if aerr, ok := err.(awserr.Error); ok {
96			switch aerr.Code() {
97			case rekognition.ErrCodeInvalidParameterException:
98				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
99			case rekognition.ErrCodeAccessDeniedException:
100				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
101			case rekognition.ErrCodeInternalServerError:
102				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
103			case rekognition.ErrCodeThrottlingException:
104				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
105			case rekognition.ErrCodeProvisionedThroughputExceededException:
106				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
107			case rekognition.ErrCodeResourceAlreadyExistsException:
108				fmt.Println(rekognition.ErrCodeResourceAlreadyExistsException, aerr.Error())
109			default:
110				fmt.Println(aerr.Error())
111			}
112		} else {
113			// Print the error, cast err to awserr.Error to get the Code and
114			// Message from an error.
115			fmt.Println(err.Error())
116		}
117		return
118	}
119
120	fmt.Println(result)
121}
122
123// To delete a collection
124//
125// This operation deletes a Rekognition collection.
126func ExampleRekognition_DeleteCollection_shared00() {
127	svc := rekognition.New(session.New())
128	input := &rekognition.DeleteCollectionInput{
129		CollectionId: aws.String("myphotos"),
130	}
131
132	result, err := svc.DeleteCollection(input)
133	if err != nil {
134		if aerr, ok := err.(awserr.Error); ok {
135			switch aerr.Code() {
136			case rekognition.ErrCodeInvalidParameterException:
137				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
138			case rekognition.ErrCodeAccessDeniedException:
139				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
140			case rekognition.ErrCodeInternalServerError:
141				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
142			case rekognition.ErrCodeThrottlingException:
143				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
144			case rekognition.ErrCodeProvisionedThroughputExceededException:
145				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
146			case rekognition.ErrCodeResourceNotFoundException:
147				fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
148			default:
149				fmt.Println(aerr.Error())
150			}
151		} else {
152			// Print the error, cast err to awserr.Error to get the Code and
153			// Message from an error.
154			fmt.Println(err.Error())
155		}
156		return
157	}
158
159	fmt.Println(result)
160}
161
162// To delete a face
163//
164// This operation deletes one or more faces from a Rekognition collection.
165func ExampleRekognition_DeleteFaces_shared00() {
166	svc := rekognition.New(session.New())
167	input := &rekognition.DeleteFacesInput{
168		CollectionId: aws.String("myphotos"),
169		FaceIds: []*string{
170			aws.String("ff43d742-0c13-5d16-a3e8-03d3f58e980b"),
171		},
172	}
173
174	result, err := svc.DeleteFaces(input)
175	if err != nil {
176		if aerr, ok := err.(awserr.Error); ok {
177			switch aerr.Code() {
178			case rekognition.ErrCodeInvalidParameterException:
179				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
180			case rekognition.ErrCodeAccessDeniedException:
181				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
182			case rekognition.ErrCodeInternalServerError:
183				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
184			case rekognition.ErrCodeThrottlingException:
185				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
186			case rekognition.ErrCodeProvisionedThroughputExceededException:
187				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
188			case rekognition.ErrCodeResourceNotFoundException:
189				fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
190			default:
191				fmt.Println(aerr.Error())
192			}
193		} else {
194			// Print the error, cast err to awserr.Error to get the Code and
195			// Message from an error.
196			fmt.Println(err.Error())
197		}
198		return
199	}
200
201	fmt.Println(result)
202}
203
204// To detect faces in an image
205//
206// This operation detects faces in an image stored in an AWS S3 bucket.
207func ExampleRekognition_DetectFaces_shared00() {
208	svc := rekognition.New(session.New())
209	input := &rekognition.DetectFacesInput{
210		Image: &rekognition.Image{
211			S3Object: &rekognition.S3Object{
212				Bucket: aws.String("mybucket"),
213				Name:   aws.String("myphoto"),
214			},
215		},
216	}
217
218	result, err := svc.DetectFaces(input)
219	if err != nil {
220		if aerr, ok := err.(awserr.Error); ok {
221			switch aerr.Code() {
222			case rekognition.ErrCodeInvalidS3ObjectException:
223				fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
224			case rekognition.ErrCodeInvalidParameterException:
225				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
226			case rekognition.ErrCodeImageTooLargeException:
227				fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
228			case rekognition.ErrCodeAccessDeniedException:
229				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
230			case rekognition.ErrCodeInternalServerError:
231				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
232			case rekognition.ErrCodeThrottlingException:
233				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
234			case rekognition.ErrCodeProvisionedThroughputExceededException:
235				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
236			case rekognition.ErrCodeInvalidImageFormatException:
237				fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
238			default:
239				fmt.Println(aerr.Error())
240			}
241		} else {
242			// Print the error, cast err to awserr.Error to get the Code and
243			// Message from an error.
244			fmt.Println(err.Error())
245		}
246		return
247	}
248
249	fmt.Println(result)
250}
251
252// To detect labels
253//
254// This operation detects labels in the supplied image
255func ExampleRekognition_DetectLabels_shared00() {
256	svc := rekognition.New(session.New())
257	input := &rekognition.DetectLabelsInput{
258		Image: &rekognition.Image{
259			S3Object: &rekognition.S3Object{
260				Bucket: aws.String("mybucket"),
261				Name:   aws.String("myphoto"),
262			},
263		},
264		MaxLabels:     aws.Int64(123),
265		MinConfidence: aws.Float64(70.000000),
266	}
267
268	result, err := svc.DetectLabels(input)
269	if err != nil {
270		if aerr, ok := err.(awserr.Error); ok {
271			switch aerr.Code() {
272			case rekognition.ErrCodeInvalidS3ObjectException:
273				fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
274			case rekognition.ErrCodeInvalidParameterException:
275				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
276			case rekognition.ErrCodeImageTooLargeException:
277				fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
278			case rekognition.ErrCodeAccessDeniedException:
279				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
280			case rekognition.ErrCodeInternalServerError:
281				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
282			case rekognition.ErrCodeThrottlingException:
283				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
284			case rekognition.ErrCodeProvisionedThroughputExceededException:
285				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
286			case rekognition.ErrCodeInvalidImageFormatException:
287				fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
288			default:
289				fmt.Println(aerr.Error())
290			}
291		} else {
292			// Print the error, cast err to awserr.Error to get the Code and
293			// Message from an error.
294			fmt.Println(err.Error())
295		}
296		return
297	}
298
299	fmt.Println(result)
300}
301
302// To add a face to a collection
303//
304// This operation detects faces in an image and adds them to the specified Rekognition
305// collection.
306func ExampleRekognition_IndexFaces_shared00() {
307	svc := rekognition.New(session.New())
308	input := &rekognition.IndexFacesInput{
309		CollectionId:    aws.String("myphotos"),
310		ExternalImageId: aws.String("myphotoid"),
311		Image: &rekognition.Image{
312			S3Object: &rekognition.S3Object{
313				Bucket: aws.String("mybucket"),
314				Name:   aws.String("myphoto"),
315			},
316		},
317	}
318
319	result, err := svc.IndexFaces(input)
320	if err != nil {
321		if aerr, ok := err.(awserr.Error); ok {
322			switch aerr.Code() {
323			case rekognition.ErrCodeInvalidS3ObjectException:
324				fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
325			case rekognition.ErrCodeInvalidParameterException:
326				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
327			case rekognition.ErrCodeImageTooLargeException:
328				fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
329			case rekognition.ErrCodeAccessDeniedException:
330				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
331			case rekognition.ErrCodeInternalServerError:
332				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
333			case rekognition.ErrCodeThrottlingException:
334				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
335			case rekognition.ErrCodeProvisionedThroughputExceededException:
336				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
337			case rekognition.ErrCodeResourceNotFoundException:
338				fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
339			case rekognition.ErrCodeInvalidImageFormatException:
340				fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
341			default:
342				fmt.Println(aerr.Error())
343			}
344		} else {
345			// Print the error, cast err to awserr.Error to get the Code and
346			// Message from an error.
347			fmt.Println(err.Error())
348		}
349		return
350	}
351
352	fmt.Println(result)
353}
354
355// To list the collections
356//
357// This operation returns a list of Rekognition collections.
358func ExampleRekognition_ListCollections_shared00() {
359	svc := rekognition.New(session.New())
360	input := &rekognition.ListCollectionsInput{}
361
362	result, err := svc.ListCollections(input)
363	if err != nil {
364		if aerr, ok := err.(awserr.Error); ok {
365			switch aerr.Code() {
366			case rekognition.ErrCodeInvalidParameterException:
367				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
368			case rekognition.ErrCodeAccessDeniedException:
369				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
370			case rekognition.ErrCodeInternalServerError:
371				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
372			case rekognition.ErrCodeThrottlingException:
373				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
374			case rekognition.ErrCodeProvisionedThroughputExceededException:
375				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
376			case rekognition.ErrCodeInvalidPaginationTokenException:
377				fmt.Println(rekognition.ErrCodeInvalidPaginationTokenException, aerr.Error())
378			case rekognition.ErrCodeResourceNotFoundException:
379				fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
380			default:
381				fmt.Println(aerr.Error())
382			}
383		} else {
384			// Print the error, cast err to awserr.Error to get the Code and
385			// Message from an error.
386			fmt.Println(err.Error())
387		}
388		return
389	}
390
391	fmt.Println(result)
392}
393
394// To list the faces in a collection
395//
396// This operation lists the faces in a Rekognition collection.
397func ExampleRekognition_ListFaces_shared00() {
398	svc := rekognition.New(session.New())
399	input := &rekognition.ListFacesInput{
400		CollectionId: aws.String("myphotos"),
401		MaxResults:   aws.Int64(20),
402	}
403
404	result, err := svc.ListFaces(input)
405	if err != nil {
406		if aerr, ok := err.(awserr.Error); ok {
407			switch aerr.Code() {
408			case rekognition.ErrCodeInvalidParameterException:
409				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
410			case rekognition.ErrCodeAccessDeniedException:
411				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
412			case rekognition.ErrCodeInternalServerError:
413				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
414			case rekognition.ErrCodeThrottlingException:
415				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
416			case rekognition.ErrCodeProvisionedThroughputExceededException:
417				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
418			case rekognition.ErrCodeInvalidPaginationTokenException:
419				fmt.Println(rekognition.ErrCodeInvalidPaginationTokenException, aerr.Error())
420			case rekognition.ErrCodeResourceNotFoundException:
421				fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
422			default:
423				fmt.Println(aerr.Error())
424			}
425		} else {
426			// Print the error, cast err to awserr.Error to get the Code and
427			// Message from an error.
428			fmt.Println(err.Error())
429		}
430		return
431	}
432
433	fmt.Println(result)
434}
435
436// To delete a face
437//
438// This operation searches for matching faces in the collection the supplied face belongs
439// to.
440func ExampleRekognition_SearchFaces_shared00() {
441	svc := rekognition.New(session.New())
442	input := &rekognition.SearchFacesInput{
443		CollectionId:       aws.String("myphotos"),
444		FaceId:             aws.String("70008e50-75e4-55d0-8e80-363fb73b3a14"),
445		FaceMatchThreshold: aws.Float64(90.000000),
446		MaxFaces:           aws.Int64(10),
447	}
448
449	result, err := svc.SearchFaces(input)
450	if err != nil {
451		if aerr, ok := err.(awserr.Error); ok {
452			switch aerr.Code() {
453			case rekognition.ErrCodeInvalidParameterException:
454				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
455			case rekognition.ErrCodeAccessDeniedException:
456				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
457			case rekognition.ErrCodeInternalServerError:
458				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
459			case rekognition.ErrCodeThrottlingException:
460				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
461			case rekognition.ErrCodeProvisionedThroughputExceededException:
462				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
463			case rekognition.ErrCodeResourceNotFoundException:
464				fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
465			default:
466				fmt.Println(aerr.Error())
467			}
468		} else {
469			// Print the error, cast err to awserr.Error to get the Code and
470			// Message from an error.
471			fmt.Println(err.Error())
472		}
473		return
474	}
475
476	fmt.Println(result)
477}
478
479// To search for faces matching a supplied image
480//
481// This operation searches for faces in a Rekognition collection that match the largest
482// face in an S3 bucket stored image.
483func ExampleRekognition_SearchFacesByImage_shared00() {
484	svc := rekognition.New(session.New())
485	input := &rekognition.SearchFacesByImageInput{
486		CollectionId:       aws.String("myphotos"),
487		FaceMatchThreshold: aws.Float64(95.000000),
488		Image: &rekognition.Image{
489			S3Object: &rekognition.S3Object{
490				Bucket: aws.String("mybucket"),
491				Name:   aws.String("myphoto"),
492			},
493		},
494		MaxFaces: aws.Int64(5),
495	}
496
497	result, err := svc.SearchFacesByImage(input)
498	if err != nil {
499		if aerr, ok := err.(awserr.Error); ok {
500			switch aerr.Code() {
501			case rekognition.ErrCodeInvalidS3ObjectException:
502				fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
503			case rekognition.ErrCodeInvalidParameterException:
504				fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
505			case rekognition.ErrCodeImageTooLargeException:
506				fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
507			case rekognition.ErrCodeAccessDeniedException:
508				fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
509			case rekognition.ErrCodeInternalServerError:
510				fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
511			case rekognition.ErrCodeThrottlingException:
512				fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
513			case rekognition.ErrCodeProvisionedThroughputExceededException:
514				fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
515			case rekognition.ErrCodeResourceNotFoundException:
516				fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
517			case rekognition.ErrCodeInvalidImageFormatException:
518				fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
519			default:
520				fmt.Println(aerr.Error())
521			}
522		} else {
523			// Print the error, cast err to awserr.Error to get the Code and
524			// Message from an error.
525			fmt.Println(err.Error())
526		}
527		return
528	}
529
530	fmt.Println(result)
531}
532