1// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
2
3package s3_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/s3"
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 abort a multipart upload
29//
30// The following example aborts a multipart upload.
31func ExampleS3_AbortMultipartUpload_shared00() {
32	svc := s3.New(session.New())
33	input := &s3.AbortMultipartUploadInput{
34		Bucket:   aws.String("examplebucket"),
35		Key:      aws.String("bigobject"),
36		UploadId: aws.String("xadcOB_7YPBOJuoFiQ9cz4P3Pe6FIZwO4f7wN93uHsNBEw97pl5eNwzExg0LAT2dUN91cOmrEQHDsP3WA60CEg--"),
37	}
38
39	result, err := svc.AbortMultipartUpload(input)
40	if err != nil {
41		if aerr, ok := err.(awserr.Error); ok {
42			switch aerr.Code() {
43			case s3.ErrCodeNoSuchUpload:
44				fmt.Println(s3.ErrCodeNoSuchUpload, aerr.Error())
45			default:
46				fmt.Println(aerr.Error())
47			}
48		} else {
49			// Print the error, cast err to awserr.Error to get the Code and
50			// Message from an error.
51			fmt.Println(err.Error())
52		}
53		return
54	}
55
56	fmt.Println(result)
57}
58
59// To complete multipart upload
60//
61// The following example completes a multipart upload.
62func ExampleS3_CompleteMultipartUpload_shared00() {
63	svc := s3.New(session.New())
64	input := &s3.CompleteMultipartUploadInput{
65		Bucket: aws.String("examplebucket"),
66		Key:    aws.String("bigobject"),
67		MultipartUpload: &s3.CompletedMultipartUpload{
68			Parts: []*s3.CompletedPart{
69				{
70					ETag:       aws.String("\"d8c2eafd90c266e19ab9dcacc479f8af\""),
71					PartNumber: aws.Int64(1),
72				},
73				{
74					ETag:       aws.String("\"d8c2eafd90c266e19ab9dcacc479f8af\""),
75					PartNumber: aws.Int64(2),
76				},
77			},
78		},
79		UploadId: aws.String("7YPBOJuoFiQ9cz4P3Pe6FIZwO4f7wN93uHsNBEw97pl5eNwzExg0LAT2dUN91cOmrEQHDsP3WA60CEg--"),
80	}
81
82	result, err := svc.CompleteMultipartUpload(input)
83	if err != nil {
84		if aerr, ok := err.(awserr.Error); ok {
85			switch aerr.Code() {
86			default:
87				fmt.Println(aerr.Error())
88			}
89		} else {
90			// Print the error, cast err to awserr.Error to get the Code and
91			// Message from an error.
92			fmt.Println(err.Error())
93		}
94		return
95	}
96
97	fmt.Println(result)
98}
99
100// To copy an object
101//
102// The following example copies an object from one bucket to another.
103func ExampleS3_CopyObject_shared00() {
104	svc := s3.New(session.New())
105	input := &s3.CopyObjectInput{
106		Bucket:     aws.String("destinationbucket"),
107		CopySource: aws.String("/sourcebucket/HappyFacejpg"),
108		Key:        aws.String("HappyFaceCopyjpg"),
109	}
110
111	result, err := svc.CopyObject(input)
112	if err != nil {
113		if aerr, ok := err.(awserr.Error); ok {
114			switch aerr.Code() {
115			case s3.ErrCodeObjectNotInActiveTierError:
116				fmt.Println(s3.ErrCodeObjectNotInActiveTierError, aerr.Error())
117			default:
118				fmt.Println(aerr.Error())
119			}
120		} else {
121			// Print the error, cast err to awserr.Error to get the Code and
122			// Message from an error.
123			fmt.Println(err.Error())
124		}
125		return
126	}
127
128	fmt.Println(result)
129}
130
131// To create a bucket in a specific region
132//
133// The following example creates a bucket. The request specifies an AWS region where
134// to create the bucket.
135func ExampleS3_CreateBucket_shared00() {
136	svc := s3.New(session.New())
137	input := &s3.CreateBucketInput{
138		Bucket: aws.String("examplebucket"),
139		CreateBucketConfiguration: &s3.CreateBucketConfiguration{
140			LocationConstraint: aws.String("eu-west-1"),
141		},
142	}
143
144	result, err := svc.CreateBucket(input)
145	if err != nil {
146		if aerr, ok := err.(awserr.Error); ok {
147			switch aerr.Code() {
148			case s3.ErrCodeBucketAlreadyExists:
149				fmt.Println(s3.ErrCodeBucketAlreadyExists, aerr.Error())
150			case s3.ErrCodeBucketAlreadyOwnedByYou:
151				fmt.Println(s3.ErrCodeBucketAlreadyOwnedByYou, aerr.Error())
152			default:
153				fmt.Println(aerr.Error())
154			}
155		} else {
156			// Print the error, cast err to awserr.Error to get the Code and
157			// Message from an error.
158			fmt.Println(err.Error())
159		}
160		return
161	}
162
163	fmt.Println(result)
164}
165
166// To create a bucket
167//
168// The following example creates a bucket.
169func ExampleS3_CreateBucket_shared01() {
170	svc := s3.New(session.New())
171	input := &s3.CreateBucketInput{
172		Bucket: aws.String("examplebucket"),
173	}
174
175	result, err := svc.CreateBucket(input)
176	if err != nil {
177		if aerr, ok := err.(awserr.Error); ok {
178			switch aerr.Code() {
179			case s3.ErrCodeBucketAlreadyExists:
180				fmt.Println(s3.ErrCodeBucketAlreadyExists, aerr.Error())
181			case s3.ErrCodeBucketAlreadyOwnedByYou:
182				fmt.Println(s3.ErrCodeBucketAlreadyOwnedByYou, aerr.Error())
183			default:
184				fmt.Println(aerr.Error())
185			}
186		} else {
187			// Print the error, cast err to awserr.Error to get the Code and
188			// Message from an error.
189			fmt.Println(err.Error())
190		}
191		return
192	}
193
194	fmt.Println(result)
195}
196
197// To initiate a multipart upload
198//
199// The following example initiates a multipart upload.
200func ExampleS3_CreateMultipartUpload_shared00() {
201	svc := s3.New(session.New())
202	input := &s3.CreateMultipartUploadInput{
203		Bucket: aws.String("examplebucket"),
204		Key:    aws.String("largeobject"),
205	}
206
207	result, err := svc.CreateMultipartUpload(input)
208	if err != nil {
209		if aerr, ok := err.(awserr.Error); ok {
210			switch aerr.Code() {
211			default:
212				fmt.Println(aerr.Error())
213			}
214		} else {
215			// Print the error, cast err to awserr.Error to get the Code and
216			// Message from an error.
217			fmt.Println(err.Error())
218		}
219		return
220	}
221
222	fmt.Println(result)
223}
224
225// To delete a bucket
226//
227// The following example deletes the specified bucket.
228func ExampleS3_DeleteBucket_shared00() {
229	svc := s3.New(session.New())
230	input := &s3.DeleteBucketInput{
231		Bucket: aws.String("forrandall2"),
232	}
233
234	result, err := svc.DeleteBucket(input)
235	if err != nil {
236		if aerr, ok := err.(awserr.Error); ok {
237			switch aerr.Code() {
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 delete cors configuration on a bucket.
253//
254// The following example deletes CORS configuration on a bucket.
255func ExampleS3_DeleteBucketCors_shared00() {
256	svc := s3.New(session.New())
257	input := &s3.DeleteBucketCorsInput{
258		Bucket: aws.String("examplebucket"),
259	}
260
261	result, err := svc.DeleteBucketCors(input)
262	if err != nil {
263		if aerr, ok := err.(awserr.Error); ok {
264			switch aerr.Code() {
265			default:
266				fmt.Println(aerr.Error())
267			}
268		} else {
269			// Print the error, cast err to awserr.Error to get the Code and
270			// Message from an error.
271			fmt.Println(err.Error())
272		}
273		return
274	}
275
276	fmt.Println(result)
277}
278
279// To delete lifecycle configuration on a bucket.
280//
281// The following example deletes lifecycle configuration on a bucket.
282func ExampleS3_DeleteBucketLifecycle_shared00() {
283	svc := s3.New(session.New())
284	input := &s3.DeleteBucketLifecycleInput{
285		Bucket: aws.String("examplebucket"),
286	}
287
288	result, err := svc.DeleteBucketLifecycle(input)
289	if err != nil {
290		if aerr, ok := err.(awserr.Error); ok {
291			switch aerr.Code() {
292			default:
293				fmt.Println(aerr.Error())
294			}
295		} else {
296			// Print the error, cast err to awserr.Error to get the Code and
297			// Message from an error.
298			fmt.Println(err.Error())
299		}
300		return
301	}
302
303	fmt.Println(result)
304}
305
306// To delete bucket policy
307//
308// The following example deletes bucket policy on the specified bucket.
309func ExampleS3_DeleteBucketPolicy_shared00() {
310	svc := s3.New(session.New())
311	input := &s3.DeleteBucketPolicyInput{
312		Bucket: aws.String("examplebucket"),
313	}
314
315	result, err := svc.DeleteBucketPolicy(input)
316	if err != nil {
317		if aerr, ok := err.(awserr.Error); ok {
318			switch aerr.Code() {
319			default:
320				fmt.Println(aerr.Error())
321			}
322		} else {
323			// Print the error, cast err to awserr.Error to get the Code and
324			// Message from an error.
325			fmt.Println(err.Error())
326		}
327		return
328	}
329
330	fmt.Println(result)
331}
332
333// To delete bucket replication configuration
334//
335// The following example deletes replication configuration set on bucket.
336func ExampleS3_DeleteBucketReplication_shared00() {
337	svc := s3.New(session.New())
338	input := &s3.DeleteBucketReplicationInput{
339		Bucket: aws.String("example"),
340	}
341
342	result, err := svc.DeleteBucketReplication(input)
343	if err != nil {
344		if aerr, ok := err.(awserr.Error); ok {
345			switch aerr.Code() {
346			default:
347				fmt.Println(aerr.Error())
348			}
349		} else {
350			// Print the error, cast err to awserr.Error to get the Code and
351			// Message from an error.
352			fmt.Println(err.Error())
353		}
354		return
355	}
356
357	fmt.Println(result)
358}
359
360// To delete bucket tags
361//
362// The following example deletes bucket tags.
363func ExampleS3_DeleteBucketTagging_shared00() {
364	svc := s3.New(session.New())
365	input := &s3.DeleteBucketTaggingInput{
366		Bucket: aws.String("examplebucket"),
367	}
368
369	result, err := svc.DeleteBucketTagging(input)
370	if err != nil {
371		if aerr, ok := err.(awserr.Error); ok {
372			switch aerr.Code() {
373			default:
374				fmt.Println(aerr.Error())
375			}
376		} else {
377			// Print the error, cast err to awserr.Error to get the Code and
378			// Message from an error.
379			fmt.Println(err.Error())
380		}
381		return
382	}
383
384	fmt.Println(result)
385}
386
387// To delete bucket website configuration
388//
389// The following example deletes bucket website configuration.
390func ExampleS3_DeleteBucketWebsite_shared00() {
391	svc := s3.New(session.New())
392	input := &s3.DeleteBucketWebsiteInput{
393		Bucket: aws.String("examplebucket"),
394	}
395
396	result, err := svc.DeleteBucketWebsite(input)
397	if err != nil {
398		if aerr, ok := err.(awserr.Error); ok {
399			switch aerr.Code() {
400			default:
401				fmt.Println(aerr.Error())
402			}
403		} else {
404			// Print the error, cast err to awserr.Error to get the Code and
405			// Message from an error.
406			fmt.Println(err.Error())
407		}
408		return
409	}
410
411	fmt.Println(result)
412}
413
414// To delete an object (from a non-versioned bucket)
415//
416// The following example deletes an object from a non-versioned bucket.
417func ExampleS3_DeleteObject_shared00() {
418	svc := s3.New(session.New())
419	input := &s3.DeleteObjectInput{
420		Bucket: aws.String("ExampleBucket"),
421		Key:    aws.String("HappyFace.jpg"),
422	}
423
424	result, err := svc.DeleteObject(input)
425	if err != nil {
426		if aerr, ok := err.(awserr.Error); ok {
427			switch aerr.Code() {
428			default:
429				fmt.Println(aerr.Error())
430			}
431		} else {
432			// Print the error, cast err to awserr.Error to get the Code and
433			// Message from an error.
434			fmt.Println(err.Error())
435		}
436		return
437	}
438
439	fmt.Println(result)
440}
441
442// To delete an object
443//
444// The following example deletes an object from an S3 bucket.
445func ExampleS3_DeleteObject_shared01() {
446	svc := s3.New(session.New())
447	input := &s3.DeleteObjectInput{
448		Bucket: aws.String("examplebucket"),
449		Key:    aws.String("objectkey.jpg"),
450	}
451
452	result, err := svc.DeleteObject(input)
453	if err != nil {
454		if aerr, ok := err.(awserr.Error); ok {
455			switch aerr.Code() {
456			default:
457				fmt.Println(aerr.Error())
458			}
459		} else {
460			// Print the error, cast err to awserr.Error to get the Code and
461			// Message from an error.
462			fmt.Println(err.Error())
463		}
464		return
465	}
466
467	fmt.Println(result)
468}
469
470// To remove tag set from an object version
471//
472// The following example removes tag set associated with the specified object version.
473// The request specifies both the object key and object version.
474func ExampleS3_DeleteObjectTagging_shared00() {
475	svc := s3.New(session.New())
476	input := &s3.DeleteObjectTaggingInput{
477		Bucket:    aws.String("examplebucket"),
478		Key:       aws.String("HappyFace.jpg"),
479		VersionId: aws.String("ydlaNkwWm0SfKJR.T1b1fIdPRbldTYRI"),
480	}
481
482	result, err := svc.DeleteObjectTagging(input)
483	if err != nil {
484		if aerr, ok := err.(awserr.Error); ok {
485			switch aerr.Code() {
486			default:
487				fmt.Println(aerr.Error())
488			}
489		} else {
490			// Print the error, cast err to awserr.Error to get the Code and
491			// Message from an error.
492			fmt.Println(err.Error())
493		}
494		return
495	}
496
497	fmt.Println(result)
498}
499
500// To remove tag set from an object
501//
502// The following example removes tag set associated with the specified object. If the
503// bucket is versioning enabled, the operation removes tag set from the latest object
504// version.
505func ExampleS3_DeleteObjectTagging_shared01() {
506	svc := s3.New(session.New())
507	input := &s3.DeleteObjectTaggingInput{
508		Bucket: aws.String("examplebucket"),
509		Key:    aws.String("HappyFace.jpg"),
510	}
511
512	result, err := svc.DeleteObjectTagging(input)
513	if err != nil {
514		if aerr, ok := err.(awserr.Error); ok {
515			switch aerr.Code() {
516			default:
517				fmt.Println(aerr.Error())
518			}
519		} else {
520			// Print the error, cast err to awserr.Error to get the Code and
521			// Message from an error.
522			fmt.Println(err.Error())
523		}
524		return
525	}
526
527	fmt.Println(result)
528}
529
530// To delete multiple object versions from a versioned bucket
531//
532// The following example deletes objects from a bucket. The request specifies object
533// versions. S3 deletes specific object versions and returns the key and versions of
534// deleted objects in the response.
535func ExampleS3_DeleteObjects_shared00() {
536	svc := s3.New(session.New())
537	input := &s3.DeleteObjectsInput{
538		Bucket: aws.String("examplebucket"),
539		Delete: &s3.Delete{
540			Objects: []*s3.ObjectIdentifier{
541				{
542					Key:       aws.String("HappyFace.jpg"),
543					VersionId: aws.String("2LWg7lQLnY41.maGB5Z6SWW.dcq0vx7b"),
544				},
545				{
546					Key:       aws.String("HappyFace.jpg"),
547					VersionId: aws.String("yoz3HB.ZhCS_tKVEmIOr7qYyyAaZSKVd"),
548				},
549			},
550			Quiet: aws.Bool(false),
551		},
552	}
553
554	result, err := svc.DeleteObjects(input)
555	if err != nil {
556		if aerr, ok := err.(awserr.Error); ok {
557			switch aerr.Code() {
558			default:
559				fmt.Println(aerr.Error())
560			}
561		} else {
562			// Print the error, cast err to awserr.Error to get the Code and
563			// Message from an error.
564			fmt.Println(err.Error())
565		}
566		return
567	}
568
569	fmt.Println(result)
570}
571
572// To delete multiple objects from a versioned bucket
573//
574// The following example deletes objects from a bucket. The bucket is versioned, and
575// the request does not specify the object version to delete. In this case, all versions
576// remain in the bucket and S3 adds a delete marker.
577func ExampleS3_DeleteObjects_shared01() {
578	svc := s3.New(session.New())
579	input := &s3.DeleteObjectsInput{
580		Bucket: aws.String("examplebucket"),
581		Delete: &s3.Delete{
582			Objects: []*s3.ObjectIdentifier{
583				{
584					Key: aws.String("objectkey1"),
585				},
586				{
587					Key: aws.String("objectkey2"),
588				},
589			},
590			Quiet: aws.Bool(false),
591		},
592	}
593
594	result, err := svc.DeleteObjects(input)
595	if err != nil {
596		if aerr, ok := err.(awserr.Error); ok {
597			switch aerr.Code() {
598			default:
599				fmt.Println(aerr.Error())
600			}
601		} else {
602			// Print the error, cast err to awserr.Error to get the Code and
603			// Message from an error.
604			fmt.Println(err.Error())
605		}
606		return
607	}
608
609	fmt.Println(result)
610}
611
612// To get cors configuration set on a bucket
613//
614// The following example returns cross-origin resource sharing (CORS) configuration
615// set on a bucket.
616func ExampleS3_GetBucketCors_shared00() {
617	svc := s3.New(session.New())
618	input := &s3.GetBucketCorsInput{
619		Bucket: aws.String("examplebucket"),
620	}
621
622	result, err := svc.GetBucketCors(input)
623	if err != nil {
624		if aerr, ok := err.(awserr.Error); ok {
625			switch aerr.Code() {
626			default:
627				fmt.Println(aerr.Error())
628			}
629		} else {
630			// Print the error, cast err to awserr.Error to get the Code and
631			// Message from an error.
632			fmt.Println(err.Error())
633		}
634		return
635	}
636
637	fmt.Println(result)
638}
639
640// To get a bucket acl
641//
642// The following example gets ACL on the specified bucket.
643func ExampleS3_GetBucketLifecycle_shared00() {
644	svc := s3.New(session.New())
645	input := &s3.GetBucketLifecycleInput{
646		Bucket: aws.String("acl1"),
647	}
648
649	result, err := svc.GetBucketLifecycle(input)
650	if err != nil {
651		if aerr, ok := err.(awserr.Error); ok {
652			switch aerr.Code() {
653			default:
654				fmt.Println(aerr.Error())
655			}
656		} else {
657			// Print the error, cast err to awserr.Error to get the Code and
658			// Message from an error.
659			fmt.Println(err.Error())
660		}
661		return
662	}
663
664	fmt.Println(result)
665}
666
667// To get lifecycle configuration on a bucket
668//
669// The following example retrieves lifecycle configuration on set on a bucket.
670func ExampleS3_GetBucketLifecycleConfiguration_shared00() {
671	svc := s3.New(session.New())
672	input := &s3.GetBucketLifecycleConfigurationInput{
673		Bucket: aws.String("examplebucket"),
674	}
675
676	result, err := svc.GetBucketLifecycleConfiguration(input)
677	if err != nil {
678		if aerr, ok := err.(awserr.Error); ok {
679			switch aerr.Code() {
680			default:
681				fmt.Println(aerr.Error())
682			}
683		} else {
684			// Print the error, cast err to awserr.Error to get the Code and
685			// Message from an error.
686			fmt.Println(err.Error())
687		}
688		return
689	}
690
691	fmt.Println(result)
692}
693
694// To get bucket location
695//
696// The following example returns bucket location.
697func ExampleS3_GetBucketLocation_shared00() {
698	svc := s3.New(session.New())
699	input := &s3.GetBucketLocationInput{
700		Bucket: aws.String("examplebucket"),
701	}
702
703	result, err := svc.GetBucketLocation(input)
704	if err != nil {
705		if aerr, ok := err.(awserr.Error); ok {
706			switch aerr.Code() {
707			default:
708				fmt.Println(aerr.Error())
709			}
710		} else {
711			// Print the error, cast err to awserr.Error to get the Code and
712			// Message from an error.
713			fmt.Println(err.Error())
714		}
715		return
716	}
717
718	fmt.Println(result)
719}
720
721// To get notification configuration set on a bucket
722//
723// The following example returns notification configuration set on a bucket.
724func ExampleS3_GetBucketNotification_shared00() {
725	svc := s3.New(session.New())
726	input := &s3.GetBucketNotificationConfigurationRequest{
727		Bucket: aws.String("examplebucket"),
728	}
729
730	result, err := svc.GetBucketNotification(input)
731	if err != nil {
732		if aerr, ok := err.(awserr.Error); ok {
733			switch aerr.Code() {
734			default:
735				fmt.Println(aerr.Error())
736			}
737		} else {
738			// Print the error, cast err to awserr.Error to get the Code and
739			// Message from an error.
740			fmt.Println(err.Error())
741		}
742		return
743	}
744
745	fmt.Println(result)
746}
747
748// To get notification configuration set on a bucket
749//
750// The following example returns notification configuration set on a bucket.
751func ExampleS3_GetBucketNotification_shared01() {
752	svc := s3.New(session.New())
753	input := &s3.GetBucketNotificationConfigurationRequest{
754		Bucket: aws.String("examplebucket"),
755	}
756
757	result, err := svc.GetBucketNotification(input)
758	if err != nil {
759		if aerr, ok := err.(awserr.Error); ok {
760			switch aerr.Code() {
761			default:
762				fmt.Println(aerr.Error())
763			}
764		} else {
765			// Print the error, cast err to awserr.Error to get the Code and
766			// Message from an error.
767			fmt.Println(err.Error())
768		}
769		return
770	}
771
772	fmt.Println(result)
773}
774
775// To get bucket policy
776//
777// The following example returns bucket policy associated with a bucket.
778func ExampleS3_GetBucketPolicy_shared00() {
779	svc := s3.New(session.New())
780	input := &s3.GetBucketPolicyInput{
781		Bucket: aws.String("examplebucket"),
782	}
783
784	result, err := svc.GetBucketPolicy(input)
785	if err != nil {
786		if aerr, ok := err.(awserr.Error); ok {
787			switch aerr.Code() {
788			default:
789				fmt.Println(aerr.Error())
790			}
791		} else {
792			// Print the error, cast err to awserr.Error to get the Code and
793			// Message from an error.
794			fmt.Println(err.Error())
795		}
796		return
797	}
798
799	fmt.Println(result)
800}
801
802// To get replication configuration set on a bucket
803//
804// The following example returns replication configuration set on a bucket.
805func ExampleS3_GetBucketReplication_shared00() {
806	svc := s3.New(session.New())
807	input := &s3.GetBucketReplicationInput{
808		Bucket: aws.String("examplebucket"),
809	}
810
811	result, err := svc.GetBucketReplication(input)
812	if err != nil {
813		if aerr, ok := err.(awserr.Error); ok {
814			switch aerr.Code() {
815			default:
816				fmt.Println(aerr.Error())
817			}
818		} else {
819			// Print the error, cast err to awserr.Error to get the Code and
820			// Message from an error.
821			fmt.Println(err.Error())
822		}
823		return
824	}
825
826	fmt.Println(result)
827}
828
829// To get bucket versioning configuration
830//
831// The following example retrieves bucket versioning configuration.
832func ExampleS3_GetBucketRequestPayment_shared00() {
833	svc := s3.New(session.New())
834	input := &s3.GetBucketRequestPaymentInput{
835		Bucket: aws.String("examplebucket"),
836	}
837
838	result, err := svc.GetBucketRequestPayment(input)
839	if err != nil {
840		if aerr, ok := err.(awserr.Error); ok {
841			switch aerr.Code() {
842			default:
843				fmt.Println(aerr.Error())
844			}
845		} else {
846			// Print the error, cast err to awserr.Error to get the Code and
847			// Message from an error.
848			fmt.Println(err.Error())
849		}
850		return
851	}
852
853	fmt.Println(result)
854}
855
856// To get tag set associated with a bucket
857//
858// The following example returns tag set associated with a bucket
859func ExampleS3_GetBucketTagging_shared00() {
860	svc := s3.New(session.New())
861	input := &s3.GetBucketTaggingInput{
862		Bucket: aws.String("examplebucket"),
863	}
864
865	result, err := svc.GetBucketTagging(input)
866	if err != nil {
867		if aerr, ok := err.(awserr.Error); ok {
868			switch aerr.Code() {
869			default:
870				fmt.Println(aerr.Error())
871			}
872		} else {
873			// Print the error, cast err to awserr.Error to get the Code and
874			// Message from an error.
875			fmt.Println(err.Error())
876		}
877		return
878	}
879
880	fmt.Println(result)
881}
882
883// To get bucket versioning configuration
884//
885// The following example retrieves bucket versioning configuration.
886func ExampleS3_GetBucketVersioning_shared00() {
887	svc := s3.New(session.New())
888	input := &s3.GetBucketVersioningInput{
889		Bucket: aws.String("examplebucket"),
890	}
891
892	result, err := svc.GetBucketVersioning(input)
893	if err != nil {
894		if aerr, ok := err.(awserr.Error); ok {
895			switch aerr.Code() {
896			default:
897				fmt.Println(aerr.Error())
898			}
899		} else {
900			// Print the error, cast err to awserr.Error to get the Code and
901			// Message from an error.
902			fmt.Println(err.Error())
903		}
904		return
905	}
906
907	fmt.Println(result)
908}
909
910// To get bucket website configuration
911//
912// The following example retrieves website configuration of a bucket.
913func ExampleS3_GetBucketWebsite_shared00() {
914	svc := s3.New(session.New())
915	input := &s3.GetBucketWebsiteInput{
916		Bucket: aws.String("examplebucket"),
917	}
918
919	result, err := svc.GetBucketWebsite(input)
920	if err != nil {
921		if aerr, ok := err.(awserr.Error); ok {
922			switch aerr.Code() {
923			default:
924				fmt.Println(aerr.Error())
925			}
926		} else {
927			// Print the error, cast err to awserr.Error to get the Code and
928			// Message from an error.
929			fmt.Println(err.Error())
930		}
931		return
932	}
933
934	fmt.Println(result)
935}
936
937// To retrieve an object
938//
939// The following example retrieves an object for an S3 bucket.
940func ExampleS3_GetObject_shared00() {
941	svc := s3.New(session.New())
942	input := &s3.GetObjectInput{
943		Bucket: aws.String("examplebucket"),
944		Key:    aws.String("HappyFace.jpg"),
945	}
946
947	result, err := svc.GetObject(input)
948	if err != nil {
949		if aerr, ok := err.(awserr.Error); ok {
950			switch aerr.Code() {
951			case s3.ErrCodeNoSuchKey:
952				fmt.Println(s3.ErrCodeNoSuchKey, aerr.Error())
953			default:
954				fmt.Println(aerr.Error())
955			}
956		} else {
957			// Print the error, cast err to awserr.Error to get the Code and
958			// Message from an error.
959			fmt.Println(err.Error())
960		}
961		return
962	}
963
964	fmt.Println(result)
965}
966
967// To retrieve a byte range of an object
968//
969// The following example retrieves an object for an S3 bucket. The request specifies
970// the range header to retrieve a specific byte range.
971func ExampleS3_GetObject_shared01() {
972	svc := s3.New(session.New())
973	input := &s3.GetObjectInput{
974		Bucket: aws.String("examplebucket"),
975		Key:    aws.String("SampleFile.txt"),
976		Range:  aws.String("bytes=0-9"),
977	}
978
979	result, err := svc.GetObject(input)
980	if err != nil {
981		if aerr, ok := err.(awserr.Error); ok {
982			switch aerr.Code() {
983			case s3.ErrCodeNoSuchKey:
984				fmt.Println(s3.ErrCodeNoSuchKey, aerr.Error())
985			default:
986				fmt.Println(aerr.Error())
987			}
988		} else {
989			// Print the error, cast err to awserr.Error to get the Code and
990			// Message from an error.
991			fmt.Println(err.Error())
992		}
993		return
994	}
995
996	fmt.Println(result)
997}
998
999// To retrieve object ACL
1000//
1001// The following example retrieves access control list (ACL) of an object.
1002func ExampleS3_GetObjectAcl_shared00() {
1003	svc := s3.New(session.New())
1004	input := &s3.GetObjectAclInput{
1005		Bucket: aws.String("examplebucket"),
1006		Key:    aws.String("HappyFace.jpg"),
1007	}
1008
1009	result, err := svc.GetObjectAcl(input)
1010	if err != nil {
1011		if aerr, ok := err.(awserr.Error); ok {
1012			switch aerr.Code() {
1013			case s3.ErrCodeNoSuchKey:
1014				fmt.Println(s3.ErrCodeNoSuchKey, aerr.Error())
1015			default:
1016				fmt.Println(aerr.Error())
1017			}
1018		} else {
1019			// Print the error, cast err to awserr.Error to get the Code and
1020			// Message from an error.
1021			fmt.Println(err.Error())
1022		}
1023		return
1024	}
1025
1026	fmt.Println(result)
1027}
1028
1029// To retrieve tag set of an object
1030//
1031// The following example retrieves tag set of an object.
1032func ExampleS3_GetObjectTagging_shared00() {
1033	svc := s3.New(session.New())
1034	input := &s3.GetObjectTaggingInput{
1035		Bucket: aws.String("examplebucket"),
1036		Key:    aws.String("HappyFace.jpg"),
1037	}
1038
1039	result, err := svc.GetObjectTagging(input)
1040	if err != nil {
1041		if aerr, ok := err.(awserr.Error); ok {
1042			switch aerr.Code() {
1043			default:
1044				fmt.Println(aerr.Error())
1045			}
1046		} else {
1047			// Print the error, cast err to awserr.Error to get the Code and
1048			// Message from an error.
1049			fmt.Println(err.Error())
1050		}
1051		return
1052	}
1053
1054	fmt.Println(result)
1055}
1056
1057// To retrieve tag set of a specific object version
1058//
1059// The following example retrieves tag set of an object. The request specifies object
1060// version.
1061func ExampleS3_GetObjectTagging_shared01() {
1062	svc := s3.New(session.New())
1063	input := &s3.GetObjectTaggingInput{
1064		Bucket:    aws.String("examplebucket"),
1065		Key:       aws.String("exampleobject"),
1066		VersionId: aws.String("ydlaNkwWm0SfKJR.T1b1fIdPRbldTYRI"),
1067	}
1068
1069	result, err := svc.GetObjectTagging(input)
1070	if err != nil {
1071		if aerr, ok := err.(awserr.Error); ok {
1072			switch aerr.Code() {
1073			default:
1074				fmt.Println(aerr.Error())
1075			}
1076		} else {
1077			// Print the error, cast err to awserr.Error to get the Code and
1078			// Message from an error.
1079			fmt.Println(err.Error())
1080		}
1081		return
1082	}
1083
1084	fmt.Println(result)
1085}
1086
1087// To retrieve torrent files for an object
1088//
1089// The following example retrieves torrent files of an object.
1090func ExampleS3_GetObjectTorrent_shared00() {
1091	svc := s3.New(session.New())
1092	input := &s3.GetObjectTorrentInput{
1093		Bucket: aws.String("examplebucket"),
1094		Key:    aws.String("HappyFace.jpg"),
1095	}
1096
1097	result, err := svc.GetObjectTorrent(input)
1098	if err != nil {
1099		if aerr, ok := err.(awserr.Error); ok {
1100			switch aerr.Code() {
1101			default:
1102				fmt.Println(aerr.Error())
1103			}
1104		} else {
1105			// Print the error, cast err to awserr.Error to get the Code and
1106			// Message from an error.
1107			fmt.Println(err.Error())
1108		}
1109		return
1110	}
1111
1112	fmt.Println(result)
1113}
1114
1115// To determine if bucket exists
1116//
1117// This operation checks to see if a bucket exists.
1118func ExampleS3_HeadBucket_shared00() {
1119	svc := s3.New(session.New())
1120	input := &s3.HeadBucketInput{
1121		Bucket: aws.String("acl1"),
1122	}
1123
1124	result, err := svc.HeadBucket(input)
1125	if err != nil {
1126		if aerr, ok := err.(awserr.Error); ok {
1127			switch aerr.Code() {
1128			case s3.ErrCodeNoSuchBucket:
1129				fmt.Println(s3.ErrCodeNoSuchBucket, aerr.Error())
1130			default:
1131				fmt.Println(aerr.Error())
1132			}
1133		} else {
1134			// Print the error, cast err to awserr.Error to get the Code and
1135			// Message from an error.
1136			fmt.Println(err.Error())
1137		}
1138		return
1139	}
1140
1141	fmt.Println(result)
1142}
1143
1144// To retrieve metadata of an object without returning the object itself
1145//
1146// The following example retrieves an object metadata.
1147func ExampleS3_HeadObject_shared00() {
1148	svc := s3.New(session.New())
1149	input := &s3.HeadObjectInput{
1150		Bucket: aws.String("examplebucket"),
1151		Key:    aws.String("HappyFace.jpg"),
1152	}
1153
1154	result, err := svc.HeadObject(input)
1155	if err != nil {
1156		if aerr, ok := err.(awserr.Error); ok {
1157			switch aerr.Code() {
1158			default:
1159				fmt.Println(aerr.Error())
1160			}
1161		} else {
1162			// Print the error, cast err to awserr.Error to get the Code and
1163			// Message from an error.
1164			fmt.Println(err.Error())
1165		}
1166		return
1167	}
1168
1169	fmt.Println(result)
1170}
1171
1172// To list object versions
1173//
1174// The following example return versions of an object with specific key name prefix.
1175// The request limits the number of items returned to two. If there are are more than
1176// two object version, S3 returns NextToken in the response. You can specify this token
1177// value in your next request to fetch next set of object versions.
1178func ExampleS3_ListBuckets_shared00() {
1179	svc := s3.New(session.New())
1180	input := &s3.ListBucketsInput{}
1181
1182	result, err := svc.ListBuckets(input)
1183	if err != nil {
1184		if aerr, ok := err.(awserr.Error); ok {
1185			switch aerr.Code() {
1186			default:
1187				fmt.Println(aerr.Error())
1188			}
1189		} else {
1190			// Print the error, cast err to awserr.Error to get the Code and
1191			// Message from an error.
1192			fmt.Println(err.Error())
1193		}
1194		return
1195	}
1196
1197	fmt.Println(result)
1198}
1199
1200// To list in-progress multipart uploads on a bucket
1201//
1202// The following example lists in-progress multipart uploads on a specific bucket.
1203func ExampleS3_ListMultipartUploads_shared00() {
1204	svc := s3.New(session.New())
1205	input := &s3.ListMultipartUploadsInput{
1206		Bucket: aws.String("examplebucket"),
1207	}
1208
1209	result, err := svc.ListMultipartUploads(input)
1210	if err != nil {
1211		if aerr, ok := err.(awserr.Error); ok {
1212			switch aerr.Code() {
1213			default:
1214				fmt.Println(aerr.Error())
1215			}
1216		} else {
1217			// Print the error, cast err to awserr.Error to get the Code and
1218			// Message from an error.
1219			fmt.Println(err.Error())
1220		}
1221		return
1222	}
1223
1224	fmt.Println(result)
1225}
1226
1227// List next set of multipart uploads when previous result is truncated
1228//
1229// The following example specifies the upload-id-marker and key-marker from previous
1230// truncated response to retrieve next setup of multipart uploads.
1231func ExampleS3_ListMultipartUploads_shared01() {
1232	svc := s3.New(session.New())
1233	input := &s3.ListMultipartUploadsInput{
1234		Bucket:         aws.String("examplebucket"),
1235		KeyMarker:      aws.String("nextkeyfrompreviousresponse"),
1236		MaxUploads:     aws.Int64(2),
1237		UploadIdMarker: aws.String("valuefrompreviousresponse"),
1238	}
1239
1240	result, err := svc.ListMultipartUploads(input)
1241	if err != nil {
1242		if aerr, ok := err.(awserr.Error); ok {
1243			switch aerr.Code() {
1244			default:
1245				fmt.Println(aerr.Error())
1246			}
1247		} else {
1248			// Print the error, cast err to awserr.Error to get the Code and
1249			// Message from an error.
1250			fmt.Println(err.Error())
1251		}
1252		return
1253	}
1254
1255	fmt.Println(result)
1256}
1257
1258// To list object versions
1259//
1260// The following example return versions of an object with specific key name prefix.
1261// The request limits the number of items returned to two. If there are are more than
1262// two object version, S3 returns NextToken in the response. You can specify this token
1263// value in your next request to fetch next set of object versions.
1264func ExampleS3_ListObjectVersions_shared00() {
1265	svc := s3.New(session.New())
1266	input := &s3.ListObjectVersionsInput{
1267		Bucket: aws.String("examplebucket"),
1268		Prefix: aws.String("HappyFace.jpg"),
1269	}
1270
1271	result, err := svc.ListObjectVersions(input)
1272	if err != nil {
1273		if aerr, ok := err.(awserr.Error); ok {
1274			switch aerr.Code() {
1275			default:
1276				fmt.Println(aerr.Error())
1277			}
1278		} else {
1279			// Print the error, cast err to awserr.Error to get the Code and
1280			// Message from an error.
1281			fmt.Println(err.Error())
1282		}
1283		return
1284	}
1285
1286	fmt.Println(result)
1287}
1288
1289// To list objects in a bucket
1290//
1291// The following example list two objects in a bucket.
1292func ExampleS3_ListObjects_shared00() {
1293	svc := s3.New(session.New())
1294	input := &s3.ListObjectsInput{
1295		Bucket:  aws.String("examplebucket"),
1296		MaxKeys: aws.Int64(2),
1297	}
1298
1299	result, err := svc.ListObjects(input)
1300	if err != nil {
1301		if aerr, ok := err.(awserr.Error); ok {
1302			switch aerr.Code() {
1303			case s3.ErrCodeNoSuchBucket:
1304				fmt.Println(s3.ErrCodeNoSuchBucket, aerr.Error())
1305			default:
1306				fmt.Println(aerr.Error())
1307			}
1308		} else {
1309			// Print the error, cast err to awserr.Error to get the Code and
1310			// Message from an error.
1311			fmt.Println(err.Error())
1312		}
1313		return
1314	}
1315
1316	fmt.Println(result)
1317}
1318
1319// To get object list
1320//
1321// The following example retrieves object list. The request specifies max keys to limit
1322// response to include only 2 object keys.
1323func ExampleS3_ListObjectsV2_shared00() {
1324	svc := s3.New(session.New())
1325	input := &s3.ListObjectsV2Input{
1326		Bucket:  aws.String("examplebucket"),
1327		MaxKeys: aws.Int64(2),
1328	}
1329
1330	result, err := svc.ListObjectsV2(input)
1331	if err != nil {
1332		if aerr, ok := err.(awserr.Error); ok {
1333			switch aerr.Code() {
1334			case s3.ErrCodeNoSuchBucket:
1335				fmt.Println(s3.ErrCodeNoSuchBucket, aerr.Error())
1336			default:
1337				fmt.Println(aerr.Error())
1338			}
1339		} else {
1340			// Print the error, cast err to awserr.Error to get the Code and
1341			// Message from an error.
1342			fmt.Println(err.Error())
1343		}
1344		return
1345	}
1346
1347	fmt.Println(result)
1348}
1349
1350// To list parts of a multipart upload.
1351//
1352// The following example lists parts uploaded for a specific multipart upload.
1353func ExampleS3_ListParts_shared00() {
1354	svc := s3.New(session.New())
1355	input := &s3.ListPartsInput{
1356		Bucket:   aws.String("examplebucket"),
1357		Key:      aws.String("bigobject"),
1358		UploadId: aws.String("example7YPBOJuoFiQ9cz4P3Pe6FIZwO4f7wN93uHsNBEw97pl5eNwzExg0LAT2dUN91cOmrEQHDsP3WA60CEg--"),
1359	}
1360
1361	result, err := svc.ListParts(input)
1362	if err != nil {
1363		if aerr, ok := err.(awserr.Error); ok {
1364			switch aerr.Code() {
1365			default:
1366				fmt.Println(aerr.Error())
1367			}
1368		} else {
1369			// Print the error, cast err to awserr.Error to get the Code and
1370			// Message from an error.
1371			fmt.Println(err.Error())
1372		}
1373		return
1374	}
1375
1376	fmt.Println(result)
1377}
1378
1379// Put bucket acl
1380//
1381// The following example replaces existing ACL on a bucket. The ACL grants the bucket
1382// owner (specified using the owner ID) and write permission to the LogDelivery group.
1383// Because this is a replace operation, you must specify all the grants in your request.
1384// To incrementally add or remove ACL grants, you might use the console.
1385func ExampleS3_PutBucketAcl_shared00() {
1386	svc := s3.New(session.New())
1387	input := &s3.PutBucketAclInput{
1388		Bucket:           aws.String("examplebucket"),
1389		GrantFullControl: aws.String("id=examplee7a2f25102679df27bb0ae12b3f85be6f290b936c4393484"),
1390		GrantWrite:       aws.String("uri=http://acs.amazonaws.com/groups/s3/LogDelivery"),
1391	}
1392
1393	result, err := svc.PutBucketAcl(input)
1394	if err != nil {
1395		if aerr, ok := err.(awserr.Error); ok {
1396			switch aerr.Code() {
1397			default:
1398				fmt.Println(aerr.Error())
1399			}
1400		} else {
1401			// Print the error, cast err to awserr.Error to get the Code and
1402			// Message from an error.
1403			fmt.Println(err.Error())
1404		}
1405		return
1406	}
1407
1408	fmt.Println(result)
1409}
1410
1411// To set cors configuration on a bucket.
1412//
1413// The following example enables PUT, POST, and DELETE requests from www.example.com,
1414// and enables GET requests from any domain.
1415func ExampleS3_PutBucketCors_shared00() {
1416	svc := s3.New(session.New())
1417	input := &s3.PutBucketCorsInput{
1418		Bucket: aws.String(""),
1419		CORSConfiguration: &s3.CORSConfiguration{
1420			CORSRules: []*s3.CORSRule{
1421				{
1422					AllowedHeaders: []*string{
1423						aws.String("*"),
1424					},
1425					AllowedMethods: []*string{
1426						aws.String("PUT"),
1427						aws.String("POST"),
1428						aws.String("DELETE"),
1429					},
1430					AllowedOrigins: []*string{
1431						aws.String("http://www.example.com"),
1432					},
1433					ExposeHeaders: []*string{
1434						aws.String("x-amz-server-side-encryption"),
1435					},
1436					MaxAgeSeconds: aws.Int64(3000),
1437				},
1438				{
1439					AllowedHeaders: []*string{
1440						aws.String("Authorization"),
1441					},
1442					AllowedMethods: []*string{
1443						aws.String("GET"),
1444					},
1445					AllowedOrigins: []*string{
1446						aws.String("*"),
1447					},
1448					MaxAgeSeconds: aws.Int64(3000),
1449				},
1450			},
1451		},
1452	}
1453
1454	result, err := svc.PutBucketCors(input)
1455	if err != nil {
1456		if aerr, ok := err.(awserr.Error); ok {
1457			switch aerr.Code() {
1458			default:
1459				fmt.Println(aerr.Error())
1460			}
1461		} else {
1462			// Print the error, cast err to awserr.Error to get the Code and
1463			// Message from an error.
1464			fmt.Println(err.Error())
1465		}
1466		return
1467	}
1468
1469	fmt.Println(result)
1470}
1471
1472// Put bucket lifecycle
1473//
1474// The following example replaces existing lifecycle configuration, if any, on the specified
1475// bucket.
1476func ExampleS3_PutBucketLifecycleConfiguration_shared00() {
1477	svc := s3.New(session.New())
1478	input := &s3.PutBucketLifecycleConfigurationInput{
1479		Bucket: aws.String("examplebucket"),
1480		LifecycleConfiguration: &s3.BucketLifecycleConfiguration{
1481			Rules: []*s3.LifecycleRule{
1482				{
1483					Expiration: &s3.LifecycleExpiration{
1484						Days: aws.Int64(3650),
1485					},
1486					Filter: &s3.LifecycleRuleFilter{
1487						Prefix: aws.String("documents/"),
1488					},
1489					ID:     aws.String("TestOnly"),
1490					Status: aws.String("Enabled"),
1491					Transitions: []*s3.Transition{
1492						{
1493							Days:         aws.Int64(365),
1494							StorageClass: aws.String("GLACIER"),
1495						},
1496					},
1497				},
1498			},
1499		},
1500	}
1501
1502	result, err := svc.PutBucketLifecycleConfiguration(input)
1503	if err != nil {
1504		if aerr, ok := err.(awserr.Error); ok {
1505			switch aerr.Code() {
1506			default:
1507				fmt.Println(aerr.Error())
1508			}
1509		} else {
1510			// Print the error, cast err to awserr.Error to get the Code and
1511			// Message from an error.
1512			fmt.Println(err.Error())
1513		}
1514		return
1515	}
1516
1517	fmt.Println(result)
1518}
1519
1520// Set logging configuration for a bucket
1521//
1522// The following example sets logging policy on a bucket. For the Log Delivery group
1523// to deliver logs to the destination bucket, it needs permission for the READ_ACP action
1524// which the policy grants.
1525func ExampleS3_PutBucketLogging_shared00() {
1526	svc := s3.New(session.New())
1527	input := &s3.PutBucketLoggingInput{
1528		Bucket: aws.String("sourcebucket"),
1529		BucketLoggingStatus: &s3.BucketLoggingStatus{
1530			LoggingEnabled: &s3.LoggingEnabled{
1531				TargetBucket: aws.String("targetbucket"),
1532				TargetGrants: []*s3.TargetGrant{
1533					{
1534						Grantee: &s3.Grantee{
1535							Type: aws.String("Group"),
1536							URI:  aws.String("http://acs.amazonaws.com/groups/global/AllUsers"),
1537						},
1538						Permission: aws.String("READ"),
1539					},
1540				},
1541				TargetPrefix: aws.String("MyBucketLogs/"),
1542			},
1543		},
1544	}
1545
1546	result, err := svc.PutBucketLogging(input)
1547	if err != nil {
1548		if aerr, ok := err.(awserr.Error); ok {
1549			switch aerr.Code() {
1550			default:
1551				fmt.Println(aerr.Error())
1552			}
1553		} else {
1554			// Print the error, cast err to awserr.Error to get the Code and
1555			// Message from an error.
1556			fmt.Println(err.Error())
1557		}
1558		return
1559	}
1560
1561	fmt.Println(result)
1562}
1563
1564// Set notification configuration for a bucket
1565//
1566// The following example sets notification configuration on a bucket to publish the
1567// object created events to an SNS topic.
1568func ExampleS3_PutBucketNotificationConfiguration_shared00() {
1569	svc := s3.New(session.New())
1570	input := &s3.PutBucketNotificationConfigurationInput{
1571		Bucket: aws.String("examplebucket"),
1572		NotificationConfiguration: &s3.NotificationConfiguration{
1573			TopicConfigurations: []*s3.TopicConfiguration{
1574				{
1575					Events: []*string{
1576						aws.String("s3:ObjectCreated:*"),
1577					},
1578					TopicArn: aws.String("arn:aws:sns:us-west-2:123456789012:s3-notification-topic"),
1579				},
1580			},
1581		},
1582	}
1583
1584	result, err := svc.PutBucketNotificationConfiguration(input)
1585	if err != nil {
1586		if aerr, ok := err.(awserr.Error); ok {
1587			switch aerr.Code() {
1588			default:
1589				fmt.Println(aerr.Error())
1590			}
1591		} else {
1592			// Print the error, cast err to awserr.Error to get the Code and
1593			// Message from an error.
1594			fmt.Println(err.Error())
1595		}
1596		return
1597	}
1598
1599	fmt.Println(result)
1600}
1601
1602// Set bucket policy
1603//
1604// The following example sets a permission policy on a bucket.
1605func ExampleS3_PutBucketPolicy_shared00() {
1606	svc := s3.New(session.New())
1607	input := &s3.PutBucketPolicyInput{
1608		Bucket: aws.String("examplebucket"),
1609		Policy: aws.String("{\"Version\": \"2012-10-17\", \"Statement\": [{ \"Sid\": \"id-1\",\"Effect\": \"Allow\",\"Principal\": {\"AWS\": \"arn:aws:iam::123456789012:root\"}, \"Action\": [ \"s3:PutObject\",\"s3:PutObjectAcl\"], \"Resource\": [\"arn:aws:s3:::acl3/*\" ] } ]}"),
1610	}
1611
1612	result, err := svc.PutBucketPolicy(input)
1613	if err != nil {
1614		if aerr, ok := err.(awserr.Error); ok {
1615			switch aerr.Code() {
1616			default:
1617				fmt.Println(aerr.Error())
1618			}
1619		} else {
1620			// Print the error, cast err to awserr.Error to get the Code and
1621			// Message from an error.
1622			fmt.Println(err.Error())
1623		}
1624		return
1625	}
1626
1627	fmt.Println(result)
1628}
1629
1630// Set replication configuration on a bucket
1631//
1632// The following example sets replication configuration on a bucket.
1633func ExampleS3_PutBucketReplication_shared00() {
1634	svc := s3.New(session.New())
1635	input := &s3.PutBucketReplicationInput{
1636		Bucket: aws.String("examplebucket"),
1637		ReplicationConfiguration: &s3.ReplicationConfiguration{
1638			Role: aws.String("arn:aws:iam::123456789012:role/examplerole"),
1639			Rules: []*s3.ReplicationRule{
1640				{
1641					Destination: &s3.Destination{
1642						Bucket:       aws.String("arn:aws:s3:::destinationbucket"),
1643						StorageClass: aws.String("STANDARD"),
1644					},
1645					Prefix: aws.String(""),
1646					Status: aws.String("Enabled"),
1647				},
1648			},
1649		},
1650	}
1651
1652	result, err := svc.PutBucketReplication(input)
1653	if err != nil {
1654		if aerr, ok := err.(awserr.Error); ok {
1655			switch aerr.Code() {
1656			default:
1657				fmt.Println(aerr.Error())
1658			}
1659		} else {
1660			// Print the error, cast err to awserr.Error to get the Code and
1661			// Message from an error.
1662			fmt.Println(err.Error())
1663		}
1664		return
1665	}
1666
1667	fmt.Println(result)
1668}
1669
1670// Set request payment configuration on a bucket.
1671//
1672// The following example sets request payment configuration on a bucket so that person
1673// requesting the download is charged.
1674func ExampleS3_PutBucketRequestPayment_shared00() {
1675	svc := s3.New(session.New())
1676	input := &s3.PutBucketRequestPaymentInput{
1677		Bucket: aws.String("examplebucket"),
1678		RequestPaymentConfiguration: &s3.RequestPaymentConfiguration{
1679			Payer: aws.String("Requester"),
1680		},
1681	}
1682
1683	result, err := svc.PutBucketRequestPayment(input)
1684	if err != nil {
1685		if aerr, ok := err.(awserr.Error); ok {
1686			switch aerr.Code() {
1687			default:
1688				fmt.Println(aerr.Error())
1689			}
1690		} else {
1691			// Print the error, cast err to awserr.Error to get the Code and
1692			// Message from an error.
1693			fmt.Println(err.Error())
1694		}
1695		return
1696	}
1697
1698	fmt.Println(result)
1699}
1700
1701// Set tags on a bucket
1702//
1703// The following example sets tags on a bucket. Any existing tags are replaced.
1704func ExampleS3_PutBucketTagging_shared00() {
1705	svc := s3.New(session.New())
1706	input := &s3.PutBucketTaggingInput{
1707		Bucket: aws.String("examplebucket"),
1708		Tagging: &s3.Tagging{
1709			TagSet: []*s3.Tag{
1710				{
1711					Key:   aws.String("Key1"),
1712					Value: aws.String("Value1"),
1713				},
1714				{
1715					Key:   aws.String("Key2"),
1716					Value: aws.String("Value2"),
1717				},
1718			},
1719		},
1720	}
1721
1722	result, err := svc.PutBucketTagging(input)
1723	if err != nil {
1724		if aerr, ok := err.(awserr.Error); ok {
1725			switch aerr.Code() {
1726			default:
1727				fmt.Println(aerr.Error())
1728			}
1729		} else {
1730			// Print the error, cast err to awserr.Error to get the Code and
1731			// Message from an error.
1732			fmt.Println(err.Error())
1733		}
1734		return
1735	}
1736
1737	fmt.Println(result)
1738}
1739
1740// Set versioning configuration on a bucket
1741//
1742// The following example sets versioning configuration on bucket. The configuration
1743// enables versioning on the bucket.
1744func ExampleS3_PutBucketVersioning_shared00() {
1745	svc := s3.New(session.New())
1746	input := &s3.PutBucketVersioningInput{
1747		Bucket: aws.String("examplebucket"),
1748		VersioningConfiguration: &s3.VersioningConfiguration{
1749			MFADelete: aws.String("Disabled"),
1750			Status:    aws.String("Enabled"),
1751		},
1752	}
1753
1754	result, err := svc.PutBucketVersioning(input)
1755	if err != nil {
1756		if aerr, ok := err.(awserr.Error); ok {
1757			switch aerr.Code() {
1758			default:
1759				fmt.Println(aerr.Error())
1760			}
1761		} else {
1762			// Print the error, cast err to awserr.Error to get the Code and
1763			// Message from an error.
1764			fmt.Println(err.Error())
1765		}
1766		return
1767	}
1768
1769	fmt.Println(result)
1770}
1771
1772// Set website configuration on a bucket
1773//
1774// The following example adds website configuration to a bucket.
1775func ExampleS3_PutBucketWebsite_shared00() {
1776	svc := s3.New(session.New())
1777	input := &s3.PutBucketWebsiteInput{
1778		Bucket: aws.String("examplebucket"),
1779		WebsiteConfiguration: &s3.WebsiteConfiguration{
1780			ErrorDocument: &s3.ErrorDocument{
1781				Key: aws.String("error.html"),
1782			},
1783			IndexDocument: &s3.IndexDocument{
1784				Suffix: aws.String("index.html"),
1785			},
1786		},
1787	}
1788
1789	result, err := svc.PutBucketWebsite(input)
1790	if err != nil {
1791		if aerr, ok := err.(awserr.Error); ok {
1792			switch aerr.Code() {
1793			default:
1794				fmt.Println(aerr.Error())
1795			}
1796		} else {
1797			// Print the error, cast err to awserr.Error to get the Code and
1798			// Message from an error.
1799			fmt.Println(err.Error())
1800		}
1801		return
1802	}
1803
1804	fmt.Println(result)
1805}
1806
1807// To upload an object and specify server-side encryption and object tags
1808//
1809// The following example uploads and object. The request specifies the optional server-side
1810// encryption option. The request also specifies optional object tags. If the bucket
1811// is versioning enabled, S3 returns version ID in response.
1812func ExampleS3_PutObject_shared00() {
1813	svc := s3.New(session.New())
1814	input := &s3.PutObjectInput{
1815		Body:                 aws.ReadSeekCloser(strings.NewReader("filetoupload")),
1816		Bucket:               aws.String("examplebucket"),
1817		Key:                  aws.String("exampleobject"),
1818		ServerSideEncryption: aws.String("AES256"),
1819		Tagging:              aws.String("key1=value1&key2=value2"),
1820	}
1821
1822	result, err := svc.PutObject(input)
1823	if err != nil {
1824		if aerr, ok := err.(awserr.Error); ok {
1825			switch aerr.Code() {
1826			default:
1827				fmt.Println(aerr.Error())
1828			}
1829		} else {
1830			// Print the error, cast err to awserr.Error to get the Code and
1831			// Message from an error.
1832			fmt.Println(err.Error())
1833		}
1834		return
1835	}
1836
1837	fmt.Println(result)
1838}
1839
1840// To upload an object and specify canned ACL.
1841//
1842// The following example uploads and object. The request specifies optional canned ACL
1843// (access control list) to all READ access to authenticated users. If the bucket is
1844// versioning enabled, S3 returns version ID in response.
1845func ExampleS3_PutObject_shared01() {
1846	svc := s3.New(session.New())
1847	input := &s3.PutObjectInput{
1848		ACL:    aws.String("authenticated-read"),
1849		Body:   aws.ReadSeekCloser(strings.NewReader("filetoupload")),
1850		Bucket: aws.String("examplebucket"),
1851		Key:    aws.String("exampleobject"),
1852	}
1853
1854	result, err := svc.PutObject(input)
1855	if err != nil {
1856		if aerr, ok := err.(awserr.Error); ok {
1857			switch aerr.Code() {
1858			default:
1859				fmt.Println(aerr.Error())
1860			}
1861		} else {
1862			// Print the error, cast err to awserr.Error to get the Code and
1863			// Message from an error.
1864			fmt.Println(err.Error())
1865		}
1866		return
1867	}
1868
1869	fmt.Println(result)
1870}
1871
1872// To upload an object
1873//
1874// The following example uploads an object to a versioning-enabled bucket. The source
1875// file is specified using Windows file syntax. S3 returns VersionId of the newly created
1876// object.
1877func ExampleS3_PutObject_shared02() {
1878	svc := s3.New(session.New())
1879	input := &s3.PutObjectInput{
1880		Body:   aws.ReadSeekCloser(strings.NewReader("HappyFace.jpg")),
1881		Bucket: aws.String("examplebucket"),
1882		Key:    aws.String("HappyFace.jpg"),
1883	}
1884
1885	result, err := svc.PutObject(input)
1886	if err != nil {
1887		if aerr, ok := err.(awserr.Error); ok {
1888			switch aerr.Code() {
1889			default:
1890				fmt.Println(aerr.Error())
1891			}
1892		} else {
1893			// Print the error, cast err to awserr.Error to get the Code and
1894			// Message from an error.
1895			fmt.Println(err.Error())
1896		}
1897		return
1898	}
1899
1900	fmt.Println(result)
1901}
1902
1903// To create an object.
1904//
1905// The following example creates an object. If the bucket is versioning enabled, S3
1906// returns version ID in response.
1907func ExampleS3_PutObject_shared03() {
1908	svc := s3.New(session.New())
1909	input := &s3.PutObjectInput{
1910		Body:   aws.ReadSeekCloser(strings.NewReader("filetoupload")),
1911		Bucket: aws.String("examplebucket"),
1912		Key:    aws.String("objectkey"),
1913	}
1914
1915	result, err := svc.PutObject(input)
1916	if err != nil {
1917		if aerr, ok := err.(awserr.Error); ok {
1918			switch aerr.Code() {
1919			default:
1920				fmt.Println(aerr.Error())
1921			}
1922		} else {
1923			// Print the error, cast err to awserr.Error to get the Code and
1924			// Message from an error.
1925			fmt.Println(err.Error())
1926		}
1927		return
1928	}
1929
1930	fmt.Println(result)
1931}
1932
1933// To upload an object and specify optional tags
1934//
1935// The following example uploads an object. The request specifies optional object tags.
1936// The bucket is versioned, therefore S3 returns version ID of the newly created object.
1937func ExampleS3_PutObject_shared04() {
1938	svc := s3.New(session.New())
1939	input := &s3.PutObjectInput{
1940		Body:    aws.ReadSeekCloser(strings.NewReader("c:\\HappyFace.jpg")),
1941		Bucket:  aws.String("examplebucket"),
1942		Key:     aws.String("HappyFace.jpg"),
1943		Tagging: aws.String("key1=value1&key2=value2"),
1944	}
1945
1946	result, err := svc.PutObject(input)
1947	if err != nil {
1948		if aerr, ok := err.(awserr.Error); ok {
1949			switch aerr.Code() {
1950			default:
1951				fmt.Println(aerr.Error())
1952			}
1953		} else {
1954			// Print the error, cast err to awserr.Error to get the Code and
1955			// Message from an error.
1956			fmt.Println(err.Error())
1957		}
1958		return
1959	}
1960
1961	fmt.Println(result)
1962}
1963
1964// To upload object and specify user-defined metadata
1965//
1966// The following example creates an object. The request also specifies optional metadata.
1967// If the bucket is versioning enabled, S3 returns version ID in response.
1968func ExampleS3_PutObject_shared05() {
1969	svc := s3.New(session.New())
1970	input := &s3.PutObjectInput{
1971		Body:   aws.ReadSeekCloser(strings.NewReader("filetoupload")),
1972		Bucket: aws.String("examplebucket"),
1973		Key:    aws.String("exampleobject"),
1974		Metadata: map[string]*string{
1975			"metadata1": aws.String("value1"),
1976			"metadata2": aws.String("value2"),
1977		},
1978	}
1979
1980	result, err := svc.PutObject(input)
1981	if err != nil {
1982		if aerr, ok := err.(awserr.Error); ok {
1983			switch aerr.Code() {
1984			default:
1985				fmt.Println(aerr.Error())
1986			}
1987		} else {
1988			// Print the error, cast err to awserr.Error to get the Code and
1989			// Message from an error.
1990			fmt.Println(err.Error())
1991		}
1992		return
1993	}
1994
1995	fmt.Println(result)
1996}
1997
1998// To upload an object (specify optional headers)
1999//
2000// The following example uploads an object. The request specifies optional request headers
2001// to directs S3 to use specific storage class and use server-side encryption.
2002func ExampleS3_PutObject_shared06() {
2003	svc := s3.New(session.New())
2004	input := &s3.PutObjectInput{
2005		Body:                 aws.ReadSeekCloser(strings.NewReader("HappyFace.jpg")),
2006		Bucket:               aws.String("examplebucket"),
2007		Key:                  aws.String("HappyFace.jpg"),
2008		ServerSideEncryption: aws.String("AES256"),
2009		StorageClass:         aws.String("STANDARD_IA"),
2010	}
2011
2012	result, err := svc.PutObject(input)
2013	if err != nil {
2014		if aerr, ok := err.(awserr.Error); ok {
2015			switch aerr.Code() {
2016			default:
2017				fmt.Println(aerr.Error())
2018			}
2019		} else {
2020			// Print the error, cast err to awserr.Error to get the Code and
2021			// Message from an error.
2022			fmt.Println(err.Error())
2023		}
2024		return
2025	}
2026
2027	fmt.Println(result)
2028}
2029
2030// To grant permissions using object ACL
2031//
2032// The following example adds grants to an object ACL. The first permission grants user1
2033// and user2 FULL_CONTROL and the AllUsers group READ permission.
2034func ExampleS3_PutObjectAcl_shared00() {
2035	svc := s3.New(session.New())
2036	input := &s3.PutObjectAclInput{
2037		AccessControlPolicy: &s3.AccessControlPolicy{},
2038		Bucket:              aws.String("examplebucket"),
2039		GrantFullControl:    aws.String("emailaddress=user1@example.com,emailaddress=user2@example.com"),
2040		GrantRead:           aws.String("uri=http://acs.amazonaws.com/groups/global/AllUsers"),
2041		Key:                 aws.String("HappyFace.jpg"),
2042	}
2043
2044	result, err := svc.PutObjectAcl(input)
2045	if err != nil {
2046		if aerr, ok := err.(awserr.Error); ok {
2047			switch aerr.Code() {
2048			case s3.ErrCodeNoSuchKey:
2049				fmt.Println(s3.ErrCodeNoSuchKey, aerr.Error())
2050			default:
2051				fmt.Println(aerr.Error())
2052			}
2053		} else {
2054			// Print the error, cast err to awserr.Error to get the Code and
2055			// Message from an error.
2056			fmt.Println(err.Error())
2057		}
2058		return
2059	}
2060
2061	fmt.Println(result)
2062}
2063
2064// To add tags to an existing object
2065//
2066// The following example adds tags to an existing object.
2067func ExampleS3_PutObjectTagging_shared00() {
2068	svc := s3.New(session.New())
2069	input := &s3.PutObjectTaggingInput{
2070		Bucket: aws.String("examplebucket"),
2071		Key:    aws.String("HappyFace.jpg"),
2072		Tagging: &s3.Tagging{
2073			TagSet: []*s3.Tag{
2074				{
2075					Key:   aws.String("Key3"),
2076					Value: aws.String("Value3"),
2077				},
2078				{
2079					Key:   aws.String("Key4"),
2080					Value: aws.String("Value4"),
2081				},
2082			},
2083		},
2084	}
2085
2086	result, err := svc.PutObjectTagging(input)
2087	if err != nil {
2088		if aerr, ok := err.(awserr.Error); ok {
2089			switch aerr.Code() {
2090			default:
2091				fmt.Println(aerr.Error())
2092			}
2093		} else {
2094			// Print the error, cast err to awserr.Error to get the Code and
2095			// Message from an error.
2096			fmt.Println(err.Error())
2097		}
2098		return
2099	}
2100
2101	fmt.Println(result)
2102}
2103
2104// To restore an archived object
2105//
2106// The following example restores for one day an archived copy of an object back into
2107// Amazon S3 bucket.
2108func ExampleS3_RestoreObject_shared00() {
2109	svc := s3.New(session.New())
2110	input := &s3.RestoreObjectInput{
2111		Bucket: aws.String("examplebucket"),
2112		Key:    aws.String("archivedobjectkey"),
2113		RestoreRequest: &s3.RestoreRequest{
2114			Days: aws.Int64(1),
2115			GlacierJobParameters: &s3.GlacierJobParameters{
2116				Tier: aws.String("Expedited"),
2117			},
2118		},
2119	}
2120
2121	result, err := svc.RestoreObject(input)
2122	if err != nil {
2123		if aerr, ok := err.(awserr.Error); ok {
2124			switch aerr.Code() {
2125			case s3.ErrCodeObjectAlreadyInActiveTierError:
2126				fmt.Println(s3.ErrCodeObjectAlreadyInActiveTierError, aerr.Error())
2127			default:
2128				fmt.Println(aerr.Error())
2129			}
2130		} else {
2131			// Print the error, cast err to awserr.Error to get the Code and
2132			// Message from an error.
2133			fmt.Println(err.Error())
2134		}
2135		return
2136	}
2137
2138	fmt.Println(result)
2139}
2140
2141// To upload a part
2142//
2143// The following example uploads part 1 of a multipart upload. The example specifies
2144// a file name for the part data. The Upload ID is same that is returned by the initiate
2145// multipart upload.
2146func ExampleS3_UploadPart_shared00() {
2147	svc := s3.New(session.New())
2148	input := &s3.UploadPartInput{
2149		Body:       aws.ReadSeekCloser(strings.NewReader("fileToUpload")),
2150		Bucket:     aws.String("examplebucket"),
2151		Key:        aws.String("examplelargeobject"),
2152		PartNumber: aws.Int64(1),
2153		UploadId:   aws.String("xadcOB_7YPBOJuoFiQ9cz4P3Pe6FIZwO4f7wN93uHsNBEw97pl5eNwzExg0LAT2dUN91cOmrEQHDsP3WA60CEg--"),
2154	}
2155
2156	result, err := svc.UploadPart(input)
2157	if err != nil {
2158		if aerr, ok := err.(awserr.Error); ok {
2159			switch aerr.Code() {
2160			default:
2161				fmt.Println(aerr.Error())
2162			}
2163		} else {
2164			// Print the error, cast err to awserr.Error to get the Code and
2165			// Message from an error.
2166			fmt.Println(err.Error())
2167		}
2168		return
2169	}
2170
2171	fmt.Println(result)
2172}
2173
2174// To upload a part by copying byte range from an existing object as data source
2175//
2176// The following example uploads a part of a multipart upload by copying a specified
2177// byte range from an existing object as data source.
2178func ExampleS3_UploadPartCopy_shared00() {
2179	svc := s3.New(session.New())
2180	input := &s3.UploadPartCopyInput{
2181		Bucket:          aws.String("examplebucket"),
2182		CopySource:      aws.String("/bucketname/sourceobjectkey"),
2183		CopySourceRange: aws.String("bytes=1-100000"),
2184		Key:             aws.String("examplelargeobject"),
2185		PartNumber:      aws.Int64(2),
2186		UploadId:        aws.String("exampleuoh_10OhKhT7YukE9bjzTPRiuaCotmZM_pFngJFir9OZNrSr5cWa3cq3LZSUsfjI4FI7PkP91We7Nrw--"),
2187	}
2188
2189	result, err := svc.UploadPartCopy(input)
2190	if err != nil {
2191		if aerr, ok := err.(awserr.Error); ok {
2192			switch aerr.Code() {
2193			default:
2194				fmt.Println(aerr.Error())
2195			}
2196		} else {
2197			// Print the error, cast err to awserr.Error to get the Code and
2198			// Message from an error.
2199			fmt.Println(err.Error())
2200		}
2201		return
2202	}
2203
2204	fmt.Println(result)
2205}
2206
2207// To upload a part by copying data from an existing object as data source
2208//
2209// The following example uploads a part of a multipart upload by copying data from an
2210// existing object as data source.
2211func ExampleS3_UploadPartCopy_shared01() {
2212	svc := s3.New(session.New())
2213	input := &s3.UploadPartCopyInput{
2214		Bucket:     aws.String("examplebucket"),
2215		CopySource: aws.String("/bucketname/sourceobjectkey"),
2216		Key:        aws.String("examplelargeobject"),
2217		PartNumber: aws.Int64(1),
2218		UploadId:   aws.String("exampleuoh_10OhKhT7YukE9bjzTPRiuaCotmZM_pFngJFir9OZNrSr5cWa3cq3LZSUsfjI4FI7PkP91We7Nrw--"),
2219	}
2220
2221	result, err := svc.UploadPartCopy(input)
2222	if err != nil {
2223		if aerr, ok := err.(awserr.Error); ok {
2224			switch aerr.Code() {
2225			default:
2226				fmt.Println(aerr.Error())
2227			}
2228		} else {
2229			// Print the error, cast err to awserr.Error to get the Code and
2230			// Message from an error.
2231			fmt.Println(err.Error())
2232		}
2233		return
2234	}
2235
2236	fmt.Println(result)
2237}
2238