examples_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
  2. package efs_test
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/aws/aws-sdk-go/aws"
  8. "github.com/aws/aws-sdk-go/aws/awserr"
  9. "github.com/aws/aws-sdk-go/aws/session"
  10. "github.com/aws/aws-sdk-go/service/efs"
  11. )
  12. var _ time.Duration
  13. var _ strings.Reader
  14. var _ aws.Config
  15. func parseTime(layout, value string) *time.Time {
  16. t, err := time.Parse(layout, value)
  17. if err != nil {
  18. panic(err)
  19. }
  20. return &t
  21. }
  22. // To create a new file system
  23. //
  24. // This operation creates a new file system with the default generalpurpose performance
  25. // mode.
  26. func ExampleEFS_CreateFileSystem_shared00() {
  27. svc := efs.New(session.New())
  28. input := &efs.CreateFileSystemInput{
  29. CreationToken: aws.String("tokenstring"),
  30. PerformanceMode: aws.String("generalPurpose"),
  31. }
  32. result, err := svc.CreateFileSystem(input)
  33. if err != nil {
  34. if aerr, ok := err.(awserr.Error); ok {
  35. switch aerr.Code() {
  36. case efs.ErrCodeBadRequest:
  37. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  38. case efs.ErrCodeInternalServerError:
  39. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  40. case efs.ErrCodeFileSystemAlreadyExists:
  41. fmt.Println(efs.ErrCodeFileSystemAlreadyExists, aerr.Error())
  42. case efs.ErrCodeFileSystemLimitExceeded:
  43. fmt.Println(efs.ErrCodeFileSystemLimitExceeded, aerr.Error())
  44. case efs.ErrCodeInsufficientThroughputCapacity:
  45. fmt.Println(efs.ErrCodeInsufficientThroughputCapacity, aerr.Error())
  46. case efs.ErrCodeThroughputLimitExceeded:
  47. fmt.Println(efs.ErrCodeThroughputLimitExceeded, aerr.Error())
  48. default:
  49. fmt.Println(aerr.Error())
  50. }
  51. } else {
  52. // Print the error, cast err to awserr.Error to get the Code and
  53. // Message from an error.
  54. fmt.Println(err.Error())
  55. }
  56. return
  57. }
  58. fmt.Println(result)
  59. }
  60. // To create a new mount target
  61. //
  62. // This operation creates a new mount target for an EFS file system.
  63. func ExampleEFS_CreateMountTarget_shared00() {
  64. svc := efs.New(session.New())
  65. input := &efs.CreateMountTargetInput{
  66. FileSystemId: aws.String("fs-01234567"),
  67. SubnetId: aws.String("subnet-1234abcd"),
  68. }
  69. result, err := svc.CreateMountTarget(input)
  70. if err != nil {
  71. if aerr, ok := err.(awserr.Error); ok {
  72. switch aerr.Code() {
  73. case efs.ErrCodeBadRequest:
  74. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  75. case efs.ErrCodeInternalServerError:
  76. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  77. case efs.ErrCodeFileSystemNotFound:
  78. fmt.Println(efs.ErrCodeFileSystemNotFound, aerr.Error())
  79. case efs.ErrCodeIncorrectFileSystemLifeCycleState:
  80. fmt.Println(efs.ErrCodeIncorrectFileSystemLifeCycleState, aerr.Error())
  81. case efs.ErrCodeMountTargetConflict:
  82. fmt.Println(efs.ErrCodeMountTargetConflict, aerr.Error())
  83. case efs.ErrCodeSubnetNotFound:
  84. fmt.Println(efs.ErrCodeSubnetNotFound, aerr.Error())
  85. case efs.ErrCodeNoFreeAddressesInSubnet:
  86. fmt.Println(efs.ErrCodeNoFreeAddressesInSubnet, aerr.Error())
  87. case efs.ErrCodeIpAddressInUse:
  88. fmt.Println(efs.ErrCodeIpAddressInUse, aerr.Error())
  89. case efs.ErrCodeNetworkInterfaceLimitExceeded:
  90. fmt.Println(efs.ErrCodeNetworkInterfaceLimitExceeded, aerr.Error())
  91. case efs.ErrCodeSecurityGroupLimitExceeded:
  92. fmt.Println(efs.ErrCodeSecurityGroupLimitExceeded, aerr.Error())
  93. case efs.ErrCodeSecurityGroupNotFound:
  94. fmt.Println(efs.ErrCodeSecurityGroupNotFound, aerr.Error())
  95. case efs.ErrCodeUnsupportedAvailabilityZone:
  96. fmt.Println(efs.ErrCodeUnsupportedAvailabilityZone, aerr.Error())
  97. default:
  98. fmt.Println(aerr.Error())
  99. }
  100. } else {
  101. // Print the error, cast err to awserr.Error to get the Code and
  102. // Message from an error.
  103. fmt.Println(err.Error())
  104. }
  105. return
  106. }
  107. fmt.Println(result)
  108. }
  109. // To create a new tag
  110. //
  111. // This operation creates a new tag for an EFS file system.
  112. func ExampleEFS_CreateTags_shared00() {
  113. svc := efs.New(session.New())
  114. input := &efs.CreateTagsInput{
  115. FileSystemId: aws.String("fs-01234567"),
  116. Tags: []*efs.Tag{
  117. {
  118. Key: aws.String("Name"),
  119. Value: aws.String("MyFileSystem"),
  120. },
  121. },
  122. }
  123. result, err := svc.CreateTags(input)
  124. if err != nil {
  125. if aerr, ok := err.(awserr.Error); ok {
  126. switch aerr.Code() {
  127. case efs.ErrCodeBadRequest:
  128. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  129. case efs.ErrCodeInternalServerError:
  130. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  131. case efs.ErrCodeFileSystemNotFound:
  132. fmt.Println(efs.ErrCodeFileSystemNotFound, aerr.Error())
  133. default:
  134. fmt.Println(aerr.Error())
  135. }
  136. } else {
  137. // Print the error, cast err to awserr.Error to get the Code and
  138. // Message from an error.
  139. fmt.Println(err.Error())
  140. }
  141. return
  142. }
  143. fmt.Println(result)
  144. }
  145. // To delete a file system
  146. //
  147. // This operation deletes an EFS file system.
  148. func ExampleEFS_DeleteFileSystem_shared00() {
  149. svc := efs.New(session.New())
  150. input := &efs.DeleteFileSystemInput{
  151. FileSystemId: aws.String("fs-01234567"),
  152. }
  153. result, err := svc.DeleteFileSystem(input)
  154. if err != nil {
  155. if aerr, ok := err.(awserr.Error); ok {
  156. switch aerr.Code() {
  157. case efs.ErrCodeBadRequest:
  158. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  159. case efs.ErrCodeInternalServerError:
  160. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  161. case efs.ErrCodeFileSystemNotFound:
  162. fmt.Println(efs.ErrCodeFileSystemNotFound, aerr.Error())
  163. case efs.ErrCodeFileSystemInUse:
  164. fmt.Println(efs.ErrCodeFileSystemInUse, aerr.Error())
  165. default:
  166. fmt.Println(aerr.Error())
  167. }
  168. } else {
  169. // Print the error, cast err to awserr.Error to get the Code and
  170. // Message from an error.
  171. fmt.Println(err.Error())
  172. }
  173. return
  174. }
  175. fmt.Println(result)
  176. }
  177. // To delete a mount target
  178. //
  179. // This operation deletes a mount target.
  180. func ExampleEFS_DeleteMountTarget_shared00() {
  181. svc := efs.New(session.New())
  182. input := &efs.DeleteMountTargetInput{
  183. MountTargetId: aws.String("fsmt-12340abc"),
  184. }
  185. result, err := svc.DeleteMountTarget(input)
  186. if err != nil {
  187. if aerr, ok := err.(awserr.Error); ok {
  188. switch aerr.Code() {
  189. case efs.ErrCodeBadRequest:
  190. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  191. case efs.ErrCodeInternalServerError:
  192. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  193. case efs.ErrCodeDependencyTimeout:
  194. fmt.Println(efs.ErrCodeDependencyTimeout, aerr.Error())
  195. case efs.ErrCodeMountTargetNotFound:
  196. fmt.Println(efs.ErrCodeMountTargetNotFound, aerr.Error())
  197. default:
  198. fmt.Println(aerr.Error())
  199. }
  200. } else {
  201. // Print the error, cast err to awserr.Error to get the Code and
  202. // Message from an error.
  203. fmt.Println(err.Error())
  204. }
  205. return
  206. }
  207. fmt.Println(result)
  208. }
  209. // To delete tags for an EFS file system
  210. //
  211. // This operation deletes tags for an EFS file system.
  212. func ExampleEFS_DeleteTags_shared00() {
  213. svc := efs.New(session.New())
  214. input := &efs.DeleteTagsInput{
  215. FileSystemId: aws.String("fs-01234567"),
  216. TagKeys: []*string{
  217. aws.String("Name"),
  218. },
  219. }
  220. result, err := svc.DeleteTags(input)
  221. if err != nil {
  222. if aerr, ok := err.(awserr.Error); ok {
  223. switch aerr.Code() {
  224. case efs.ErrCodeBadRequest:
  225. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  226. case efs.ErrCodeInternalServerError:
  227. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  228. case efs.ErrCodeFileSystemNotFound:
  229. fmt.Println(efs.ErrCodeFileSystemNotFound, aerr.Error())
  230. default:
  231. fmt.Println(aerr.Error())
  232. }
  233. } else {
  234. // Print the error, cast err to awserr.Error to get the Code and
  235. // Message from an error.
  236. fmt.Println(err.Error())
  237. }
  238. return
  239. }
  240. fmt.Println(result)
  241. }
  242. // To describe an EFS file system
  243. //
  244. // This operation describes all of the EFS file systems in an account.
  245. func ExampleEFS_DescribeFileSystems_shared00() {
  246. svc := efs.New(session.New())
  247. input := &efs.DescribeFileSystemsInput{}
  248. result, err := svc.DescribeFileSystems(input)
  249. if err != nil {
  250. if aerr, ok := err.(awserr.Error); ok {
  251. switch aerr.Code() {
  252. case efs.ErrCodeBadRequest:
  253. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  254. case efs.ErrCodeInternalServerError:
  255. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  256. case efs.ErrCodeFileSystemNotFound:
  257. fmt.Println(efs.ErrCodeFileSystemNotFound, aerr.Error())
  258. default:
  259. fmt.Println(aerr.Error())
  260. }
  261. } else {
  262. // Print the error, cast err to awserr.Error to get the Code and
  263. // Message from an error.
  264. fmt.Println(err.Error())
  265. }
  266. return
  267. }
  268. fmt.Println(result)
  269. }
  270. // To describe the security groups for a mount target
  271. //
  272. // This operation describes all of the security groups for a file system's mount target.
  273. func ExampleEFS_DescribeMountTargetSecurityGroups_shared00() {
  274. svc := efs.New(session.New())
  275. input := &efs.DescribeMountTargetSecurityGroupsInput{
  276. MountTargetId: aws.String("fsmt-12340abc"),
  277. }
  278. result, err := svc.DescribeMountTargetSecurityGroups(input)
  279. if err != nil {
  280. if aerr, ok := err.(awserr.Error); ok {
  281. switch aerr.Code() {
  282. case efs.ErrCodeBadRequest:
  283. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  284. case efs.ErrCodeInternalServerError:
  285. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  286. case efs.ErrCodeMountTargetNotFound:
  287. fmt.Println(efs.ErrCodeMountTargetNotFound, aerr.Error())
  288. case efs.ErrCodeIncorrectMountTargetState:
  289. fmt.Println(efs.ErrCodeIncorrectMountTargetState, aerr.Error())
  290. default:
  291. fmt.Println(aerr.Error())
  292. }
  293. } else {
  294. // Print the error, cast err to awserr.Error to get the Code and
  295. // Message from an error.
  296. fmt.Println(err.Error())
  297. }
  298. return
  299. }
  300. fmt.Println(result)
  301. }
  302. // To describe the mount targets for a file system
  303. //
  304. // This operation describes all of a file system's mount targets.
  305. func ExampleEFS_DescribeMountTargets_shared00() {
  306. svc := efs.New(session.New())
  307. input := &efs.DescribeMountTargetsInput{
  308. FileSystemId: aws.String("fs-01234567"),
  309. }
  310. result, err := svc.DescribeMountTargets(input)
  311. if err != nil {
  312. if aerr, ok := err.(awserr.Error); ok {
  313. switch aerr.Code() {
  314. case efs.ErrCodeBadRequest:
  315. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  316. case efs.ErrCodeInternalServerError:
  317. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  318. case efs.ErrCodeFileSystemNotFound:
  319. fmt.Println(efs.ErrCodeFileSystemNotFound, aerr.Error())
  320. case efs.ErrCodeMountTargetNotFound:
  321. fmt.Println(efs.ErrCodeMountTargetNotFound, aerr.Error())
  322. default:
  323. fmt.Println(aerr.Error())
  324. }
  325. } else {
  326. // Print the error, cast err to awserr.Error to get the Code and
  327. // Message from an error.
  328. fmt.Println(err.Error())
  329. }
  330. return
  331. }
  332. fmt.Println(result)
  333. }
  334. // To describe the tags for a file system
  335. //
  336. // This operation describes all of a file system's tags.
  337. func ExampleEFS_DescribeTags_shared00() {
  338. svc := efs.New(session.New())
  339. input := &efs.DescribeTagsInput{
  340. FileSystemId: aws.String("fs-01234567"),
  341. }
  342. result, err := svc.DescribeTags(input)
  343. if err != nil {
  344. if aerr, ok := err.(awserr.Error); ok {
  345. switch aerr.Code() {
  346. case efs.ErrCodeBadRequest:
  347. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  348. case efs.ErrCodeInternalServerError:
  349. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  350. case efs.ErrCodeFileSystemNotFound:
  351. fmt.Println(efs.ErrCodeFileSystemNotFound, aerr.Error())
  352. default:
  353. fmt.Println(aerr.Error())
  354. }
  355. } else {
  356. // Print the error, cast err to awserr.Error to get the Code and
  357. // Message from an error.
  358. fmt.Println(err.Error())
  359. }
  360. return
  361. }
  362. fmt.Println(result)
  363. }
  364. // To modify the security groups associated with a mount target for a file system
  365. //
  366. // This operation modifies the security groups associated with a mount target for a
  367. // file system.
  368. func ExampleEFS_ModifyMountTargetSecurityGroups_shared00() {
  369. svc := efs.New(session.New())
  370. input := &efs.ModifyMountTargetSecurityGroupsInput{
  371. MountTargetId: aws.String("fsmt-12340abc"),
  372. SecurityGroups: []*string{
  373. aws.String("sg-abcd1234"),
  374. },
  375. }
  376. result, err := svc.ModifyMountTargetSecurityGroups(input)
  377. if err != nil {
  378. if aerr, ok := err.(awserr.Error); ok {
  379. switch aerr.Code() {
  380. case efs.ErrCodeBadRequest:
  381. fmt.Println(efs.ErrCodeBadRequest, aerr.Error())
  382. case efs.ErrCodeInternalServerError:
  383. fmt.Println(efs.ErrCodeInternalServerError, aerr.Error())
  384. case efs.ErrCodeMountTargetNotFound:
  385. fmt.Println(efs.ErrCodeMountTargetNotFound, aerr.Error())
  386. case efs.ErrCodeIncorrectMountTargetState:
  387. fmt.Println(efs.ErrCodeIncorrectMountTargetState, aerr.Error())
  388. case efs.ErrCodeSecurityGroupLimitExceeded:
  389. fmt.Println(efs.ErrCodeSecurityGroupLimitExceeded, aerr.Error())
  390. case efs.ErrCodeSecurityGroupNotFound:
  391. fmt.Println(efs.ErrCodeSecurityGroupNotFound, aerr.Error())
  392. default:
  393. fmt.Println(aerr.Error())
  394. }
  395. } else {
  396. // Print the error, cast err to awserr.Error to get the Code and
  397. // Message from an error.
  398. fmt.Println(err.Error())
  399. }
  400. return
  401. }
  402. fmt.Println(result)
  403. }