examples_test.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
  2. package sts_test
  3. import (
  4. "bytes"
  5. "fmt"
  6. "time"
  7. "github.com/aws/aws-sdk-go/aws"
  8. "github.com/aws/aws-sdk-go/aws/session"
  9. "github.com/aws/aws-sdk-go/service/sts"
  10. )
  11. var _ time.Duration
  12. var _ bytes.Buffer
  13. func ExampleSTS_AssumeRole() {
  14. sess, err := session.NewSession()
  15. if err != nil {
  16. fmt.Println("failed to create session,", err)
  17. return
  18. }
  19. svc := sts.New(sess)
  20. params := &sts.AssumeRoleInput{
  21. RoleArn: aws.String("arnType"), // Required
  22. RoleSessionName: aws.String("roleSessionNameType"), // Required
  23. DurationSeconds: aws.Int64(1),
  24. ExternalId: aws.String("externalIdType"),
  25. Policy: aws.String("sessionPolicyDocumentType"),
  26. SerialNumber: aws.String("serialNumberType"),
  27. TokenCode: aws.String("tokenCodeType"),
  28. }
  29. resp, err := svc.AssumeRole(params)
  30. if err != nil {
  31. // Print the error, cast err to awserr.Error to get the Code and
  32. // Message from an error.
  33. fmt.Println(err.Error())
  34. return
  35. }
  36. // Pretty-print the response data.
  37. fmt.Println(resp)
  38. }
  39. func ExampleSTS_AssumeRoleWithSAML() {
  40. sess, err := session.NewSession()
  41. if err != nil {
  42. fmt.Println("failed to create session,", err)
  43. return
  44. }
  45. svc := sts.New(sess)
  46. params := &sts.AssumeRoleWithSAMLInput{
  47. PrincipalArn: aws.String("arnType"), // Required
  48. RoleArn: aws.String("arnType"), // Required
  49. SAMLAssertion: aws.String("SAMLAssertionType"), // Required
  50. DurationSeconds: aws.Int64(1),
  51. Policy: aws.String("sessionPolicyDocumentType"),
  52. }
  53. resp, err := svc.AssumeRoleWithSAML(params)
  54. if err != nil {
  55. // Print the error, cast err to awserr.Error to get the Code and
  56. // Message from an error.
  57. fmt.Println(err.Error())
  58. return
  59. }
  60. // Pretty-print the response data.
  61. fmt.Println(resp)
  62. }
  63. func ExampleSTS_AssumeRoleWithWebIdentity() {
  64. sess, err := session.NewSession()
  65. if err != nil {
  66. fmt.Println("failed to create session,", err)
  67. return
  68. }
  69. svc := sts.New(sess)
  70. params := &sts.AssumeRoleWithWebIdentityInput{
  71. RoleArn: aws.String("arnType"), // Required
  72. RoleSessionName: aws.String("roleSessionNameType"), // Required
  73. WebIdentityToken: aws.String("clientTokenType"), // Required
  74. DurationSeconds: aws.Int64(1),
  75. Policy: aws.String("sessionPolicyDocumentType"),
  76. ProviderId: aws.String("urlType"),
  77. }
  78. resp, err := svc.AssumeRoleWithWebIdentity(params)
  79. if err != nil {
  80. // Print the error, cast err to awserr.Error to get the Code and
  81. // Message from an error.
  82. fmt.Println(err.Error())
  83. return
  84. }
  85. // Pretty-print the response data.
  86. fmt.Println(resp)
  87. }
  88. func ExampleSTS_DecodeAuthorizationMessage() {
  89. sess, err := session.NewSession()
  90. if err != nil {
  91. fmt.Println("failed to create session,", err)
  92. return
  93. }
  94. svc := sts.New(sess)
  95. params := &sts.DecodeAuthorizationMessageInput{
  96. EncodedMessage: aws.String("encodedMessageType"), // Required
  97. }
  98. resp, err := svc.DecodeAuthorizationMessage(params)
  99. if err != nil {
  100. // Print the error, cast err to awserr.Error to get the Code and
  101. // Message from an error.
  102. fmt.Println(err.Error())
  103. return
  104. }
  105. // Pretty-print the response data.
  106. fmt.Println(resp)
  107. }
  108. func ExampleSTS_GetCallerIdentity() {
  109. sess, err := session.NewSession()
  110. if err != nil {
  111. fmt.Println("failed to create session,", err)
  112. return
  113. }
  114. svc := sts.New(sess)
  115. var params *sts.GetCallerIdentityInput
  116. resp, err := svc.GetCallerIdentity(params)
  117. if err != nil {
  118. // Print the error, cast err to awserr.Error to get the Code and
  119. // Message from an error.
  120. fmt.Println(err.Error())
  121. return
  122. }
  123. // Pretty-print the response data.
  124. fmt.Println(resp)
  125. }
  126. func ExampleSTS_GetFederationToken() {
  127. sess, err := session.NewSession()
  128. if err != nil {
  129. fmt.Println("failed to create session,", err)
  130. return
  131. }
  132. svc := sts.New(sess)
  133. params := &sts.GetFederationTokenInput{
  134. Name: aws.String("userNameType"), // Required
  135. DurationSeconds: aws.Int64(1),
  136. Policy: aws.String("sessionPolicyDocumentType"),
  137. }
  138. resp, err := svc.GetFederationToken(params)
  139. if err != nil {
  140. // Print the error, cast err to awserr.Error to get the Code and
  141. // Message from an error.
  142. fmt.Println(err.Error())
  143. return
  144. }
  145. // Pretty-print the response data.
  146. fmt.Println(resp)
  147. }
  148. func ExampleSTS_GetSessionToken() {
  149. sess, err := session.NewSession()
  150. if err != nil {
  151. fmt.Println("failed to create session,", err)
  152. return
  153. }
  154. svc := sts.New(sess)
  155. params := &sts.GetSessionTokenInput{
  156. DurationSeconds: aws.Int64(1),
  157. SerialNumber: aws.String("serialNumberType"),
  158. TokenCode: aws.String("tokenCodeType"),
  159. }
  160. resp, err := svc.GetSessionToken(params)
  161. if err != nil {
  162. // Print the error, cast err to awserr.Error to get the Code and
  163. // Message from an error.
  164. fmt.Println(err.Error())
  165. return
  166. }
  167. // Pretty-print the response data.
  168. fmt.Println(resp)
  169. }