examples_test.go 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
  2. package ecs_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/ecs"
  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 cluster
  23. //
  24. // This example creates a cluster in your default region.
  25. func ExampleECS_CreateCluster_shared00() {
  26. svc := ecs.New(session.New())
  27. input := &ecs.CreateClusterInput{
  28. ClusterName: aws.String("my_cluster"),
  29. }
  30. result, err := svc.CreateCluster(input)
  31. if err != nil {
  32. if aerr, ok := err.(awserr.Error); ok {
  33. switch aerr.Code() {
  34. case ecs.ErrCodeServerException:
  35. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  36. case ecs.ErrCodeClientException:
  37. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  38. case ecs.ErrCodeInvalidParameterException:
  39. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  40. default:
  41. fmt.Println(aerr.Error())
  42. }
  43. } else {
  44. // Print the error, cast err to awserr.Error to get the Code and
  45. // Message from an error.
  46. fmt.Println(err.Error())
  47. }
  48. return
  49. }
  50. fmt.Println(result)
  51. }
  52. // To create a new service
  53. //
  54. // This example creates a service in your default region called ``ecs-simple-service``.
  55. // The service uses the ``hello_world`` task definition and it maintains 10 copies of
  56. // that task.
  57. func ExampleECS_CreateService_shared00() {
  58. svc := ecs.New(session.New())
  59. input := &ecs.CreateServiceInput{
  60. DesiredCount: aws.Int64(10),
  61. ServiceName: aws.String("ecs-simple-service"),
  62. TaskDefinition: aws.String("hello_world"),
  63. }
  64. result, err := svc.CreateService(input)
  65. if err != nil {
  66. if aerr, ok := err.(awserr.Error); ok {
  67. switch aerr.Code() {
  68. case ecs.ErrCodeServerException:
  69. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  70. case ecs.ErrCodeClientException:
  71. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  72. case ecs.ErrCodeInvalidParameterException:
  73. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  74. case ecs.ErrCodeClusterNotFoundException:
  75. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  76. case ecs.ErrCodeUnsupportedFeatureException:
  77. fmt.Println(ecs.ErrCodeUnsupportedFeatureException, aerr.Error())
  78. case ecs.ErrCodePlatformUnknownException:
  79. fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
  80. case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
  81. fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
  82. case ecs.ErrCodeAccessDeniedException:
  83. fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
  84. default:
  85. fmt.Println(aerr.Error())
  86. }
  87. } else {
  88. // Print the error, cast err to awserr.Error to get the Code and
  89. // Message from an error.
  90. fmt.Println(err.Error())
  91. }
  92. return
  93. }
  94. fmt.Println(result)
  95. }
  96. // To create a new service behind a load balancer
  97. //
  98. // This example creates a service in your default region called ``ecs-simple-service-elb``.
  99. // The service uses the ``ecs-demo`` task definition and it maintains 10 copies of that
  100. // task. You must reference an existing load balancer in the same region by its name.
  101. func ExampleECS_CreateService_shared01() {
  102. svc := ecs.New(session.New())
  103. input := &ecs.CreateServiceInput{
  104. DesiredCount: aws.Int64(10),
  105. LoadBalancers: []*ecs.LoadBalancer{
  106. {
  107. ContainerName: aws.String("simple-app"),
  108. ContainerPort: aws.Int64(80),
  109. LoadBalancerName: aws.String("EC2Contai-EcsElast-15DCDAURT3ZO2"),
  110. },
  111. },
  112. Role: aws.String("ecsServiceRole"),
  113. ServiceName: aws.String("ecs-simple-service-elb"),
  114. TaskDefinition: aws.String("console-sample-app-static"),
  115. }
  116. result, err := svc.CreateService(input)
  117. if err != nil {
  118. if aerr, ok := err.(awserr.Error); ok {
  119. switch aerr.Code() {
  120. case ecs.ErrCodeServerException:
  121. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  122. case ecs.ErrCodeClientException:
  123. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  124. case ecs.ErrCodeInvalidParameterException:
  125. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  126. case ecs.ErrCodeClusterNotFoundException:
  127. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  128. case ecs.ErrCodeUnsupportedFeatureException:
  129. fmt.Println(ecs.ErrCodeUnsupportedFeatureException, aerr.Error())
  130. case ecs.ErrCodePlatformUnknownException:
  131. fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
  132. case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
  133. fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
  134. case ecs.ErrCodeAccessDeniedException:
  135. fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
  136. default:
  137. fmt.Println(aerr.Error())
  138. }
  139. } else {
  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. }
  144. return
  145. }
  146. fmt.Println(result)
  147. }
  148. // To delete an empty cluster
  149. //
  150. // This example deletes an empty cluster in your default region.
  151. func ExampleECS_DeleteCluster_shared00() {
  152. svc := ecs.New(session.New())
  153. input := &ecs.DeleteClusterInput{
  154. Cluster: aws.String("my_cluster"),
  155. }
  156. result, err := svc.DeleteCluster(input)
  157. if err != nil {
  158. if aerr, ok := err.(awserr.Error); ok {
  159. switch aerr.Code() {
  160. case ecs.ErrCodeServerException:
  161. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  162. case ecs.ErrCodeClientException:
  163. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  164. case ecs.ErrCodeInvalidParameterException:
  165. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  166. case ecs.ErrCodeClusterNotFoundException:
  167. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  168. case ecs.ErrCodeClusterContainsContainerInstancesException:
  169. fmt.Println(ecs.ErrCodeClusterContainsContainerInstancesException, aerr.Error())
  170. case ecs.ErrCodeClusterContainsServicesException:
  171. fmt.Println(ecs.ErrCodeClusterContainsServicesException, aerr.Error())
  172. case ecs.ErrCodeClusterContainsTasksException:
  173. fmt.Println(ecs.ErrCodeClusterContainsTasksException, aerr.Error())
  174. default:
  175. fmt.Println(aerr.Error())
  176. }
  177. } else {
  178. // Print the error, cast err to awserr.Error to get the Code and
  179. // Message from an error.
  180. fmt.Println(err.Error())
  181. }
  182. return
  183. }
  184. fmt.Println(result)
  185. }
  186. // To delete a service
  187. //
  188. // This example deletes the my-http-service service. The service must have a desired
  189. // count and running count of 0 before you can delete it.
  190. func ExampleECS_DeleteService_shared00() {
  191. svc := ecs.New(session.New())
  192. input := &ecs.DeleteServiceInput{
  193. Service: aws.String("my-http-service"),
  194. }
  195. result, err := svc.DeleteService(input)
  196. if err != nil {
  197. if aerr, ok := err.(awserr.Error); ok {
  198. switch aerr.Code() {
  199. case ecs.ErrCodeServerException:
  200. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  201. case ecs.ErrCodeClientException:
  202. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  203. case ecs.ErrCodeInvalidParameterException:
  204. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  205. case ecs.ErrCodeClusterNotFoundException:
  206. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  207. case ecs.ErrCodeServiceNotFoundException:
  208. fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
  209. default:
  210. fmt.Println(aerr.Error())
  211. }
  212. } else {
  213. // Print the error, cast err to awserr.Error to get the Code and
  214. // Message from an error.
  215. fmt.Println(err.Error())
  216. }
  217. return
  218. }
  219. fmt.Println(result)
  220. }
  221. // To deregister a container instance from a cluster
  222. //
  223. // This example deregisters a container instance from the specified cluster in your
  224. // default region. If there are still tasks running on the container instance, you must
  225. // either stop those tasks before deregistering, or use the force option.
  226. func ExampleECS_DeregisterContainerInstance_shared00() {
  227. svc := ecs.New(session.New())
  228. input := &ecs.DeregisterContainerInstanceInput{
  229. Cluster: aws.String("default"),
  230. ContainerInstance: aws.String("container_instance_UUID"),
  231. Force: aws.Bool(true),
  232. }
  233. result, err := svc.DeregisterContainerInstance(input)
  234. if err != nil {
  235. if aerr, ok := err.(awserr.Error); ok {
  236. switch aerr.Code() {
  237. case ecs.ErrCodeServerException:
  238. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  239. case ecs.ErrCodeClientException:
  240. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  241. case ecs.ErrCodeInvalidParameterException:
  242. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  243. case ecs.ErrCodeClusterNotFoundException:
  244. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  245. default:
  246. fmt.Println(aerr.Error())
  247. }
  248. } else {
  249. // Print the error, cast err to awserr.Error to get the Code and
  250. // Message from an error.
  251. fmt.Println(err.Error())
  252. }
  253. return
  254. }
  255. fmt.Println(result)
  256. }
  257. // To describe a cluster
  258. //
  259. // This example provides a description of the specified cluster in your default region.
  260. func ExampleECS_DescribeClusters_shared00() {
  261. svc := ecs.New(session.New())
  262. input := &ecs.DescribeClustersInput{
  263. Clusters: []*string{
  264. aws.String("default"),
  265. },
  266. }
  267. result, err := svc.DescribeClusters(input)
  268. if err != nil {
  269. if aerr, ok := err.(awserr.Error); ok {
  270. switch aerr.Code() {
  271. case ecs.ErrCodeServerException:
  272. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  273. case ecs.ErrCodeClientException:
  274. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  275. case ecs.ErrCodeInvalidParameterException:
  276. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  277. default:
  278. fmt.Println(aerr.Error())
  279. }
  280. } else {
  281. // Print the error, cast err to awserr.Error to get the Code and
  282. // Message from an error.
  283. fmt.Println(err.Error())
  284. }
  285. return
  286. }
  287. fmt.Println(result)
  288. }
  289. // To describe container instance
  290. //
  291. // This example provides a description of the specified container instance in your default
  292. // region, using the container instance UUID as an identifier.
  293. func ExampleECS_DescribeContainerInstances_shared00() {
  294. svc := ecs.New(session.New())
  295. input := &ecs.DescribeContainerInstancesInput{
  296. Cluster: aws.String("default"),
  297. ContainerInstances: []*string{
  298. aws.String("f2756532-8f13-4d53-87c9-aed50dc94cd7"),
  299. },
  300. }
  301. result, err := svc.DescribeContainerInstances(input)
  302. if err != nil {
  303. if aerr, ok := err.(awserr.Error); ok {
  304. switch aerr.Code() {
  305. case ecs.ErrCodeServerException:
  306. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  307. case ecs.ErrCodeClientException:
  308. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  309. case ecs.ErrCodeInvalidParameterException:
  310. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  311. case ecs.ErrCodeClusterNotFoundException:
  312. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  313. default:
  314. fmt.Println(aerr.Error())
  315. }
  316. } else {
  317. // Print the error, cast err to awserr.Error to get the Code and
  318. // Message from an error.
  319. fmt.Println(err.Error())
  320. }
  321. return
  322. }
  323. fmt.Println(result)
  324. }
  325. // To describe a service
  326. //
  327. // This example provides descriptive information about the service named ``ecs-simple-service``.
  328. func ExampleECS_DescribeServices_shared00() {
  329. svc := ecs.New(session.New())
  330. input := &ecs.DescribeServicesInput{
  331. Services: []*string{
  332. aws.String("ecs-simple-service"),
  333. },
  334. }
  335. result, err := svc.DescribeServices(input)
  336. if err != nil {
  337. if aerr, ok := err.(awserr.Error); ok {
  338. switch aerr.Code() {
  339. case ecs.ErrCodeServerException:
  340. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  341. case ecs.ErrCodeClientException:
  342. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  343. case ecs.ErrCodeInvalidParameterException:
  344. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  345. case ecs.ErrCodeClusterNotFoundException:
  346. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  347. default:
  348. fmt.Println(aerr.Error())
  349. }
  350. } else {
  351. // Print the error, cast err to awserr.Error to get the Code and
  352. // Message from an error.
  353. fmt.Println(err.Error())
  354. }
  355. return
  356. }
  357. fmt.Println(result)
  358. }
  359. // To describe a task definition
  360. //
  361. // This example provides a description of the specified task definition.
  362. func ExampleECS_DescribeTaskDefinition_shared00() {
  363. svc := ecs.New(session.New())
  364. input := &ecs.DescribeTaskDefinitionInput{
  365. TaskDefinition: aws.String("hello_world:8"),
  366. }
  367. result, err := svc.DescribeTaskDefinition(input)
  368. if err != nil {
  369. if aerr, ok := err.(awserr.Error); ok {
  370. switch aerr.Code() {
  371. case ecs.ErrCodeServerException:
  372. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  373. case ecs.ErrCodeClientException:
  374. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  375. case ecs.ErrCodeInvalidParameterException:
  376. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  377. default:
  378. fmt.Println(aerr.Error())
  379. }
  380. } else {
  381. // Print the error, cast err to awserr.Error to get the Code and
  382. // Message from an error.
  383. fmt.Println(err.Error())
  384. }
  385. return
  386. }
  387. fmt.Println(result)
  388. }
  389. // To describe a task
  390. //
  391. // This example provides a description of the specified task, using the task UUID as
  392. // an identifier.
  393. func ExampleECS_DescribeTasks_shared00() {
  394. svc := ecs.New(session.New())
  395. input := &ecs.DescribeTasksInput{
  396. Tasks: []*string{
  397. aws.String("c5cba4eb-5dad-405e-96db-71ef8eefe6a8"),
  398. },
  399. }
  400. result, err := svc.DescribeTasks(input)
  401. if err != nil {
  402. if aerr, ok := err.(awserr.Error); ok {
  403. switch aerr.Code() {
  404. case ecs.ErrCodeServerException:
  405. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  406. case ecs.ErrCodeClientException:
  407. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  408. case ecs.ErrCodeInvalidParameterException:
  409. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  410. case ecs.ErrCodeClusterNotFoundException:
  411. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  412. default:
  413. fmt.Println(aerr.Error())
  414. }
  415. } else {
  416. // Print the error, cast err to awserr.Error to get the Code and
  417. // Message from an error.
  418. fmt.Println(err.Error())
  419. }
  420. return
  421. }
  422. fmt.Println(result)
  423. }
  424. // To list your available clusters
  425. //
  426. // This example lists all of your available clusters in your default region.
  427. func ExampleECS_ListClusters_shared00() {
  428. svc := ecs.New(session.New())
  429. input := &ecs.ListClustersInput{}
  430. result, err := svc.ListClusters(input)
  431. if err != nil {
  432. if aerr, ok := err.(awserr.Error); ok {
  433. switch aerr.Code() {
  434. case ecs.ErrCodeServerException:
  435. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  436. case ecs.ErrCodeClientException:
  437. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  438. case ecs.ErrCodeInvalidParameterException:
  439. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  440. default:
  441. fmt.Println(aerr.Error())
  442. }
  443. } else {
  444. // Print the error, cast err to awserr.Error to get the Code and
  445. // Message from an error.
  446. fmt.Println(err.Error())
  447. }
  448. return
  449. }
  450. fmt.Println(result)
  451. }
  452. // To list your available container instances in a cluster
  453. //
  454. // This example lists all of your available container instances in the specified cluster
  455. // in your default region.
  456. func ExampleECS_ListContainerInstances_shared00() {
  457. svc := ecs.New(session.New())
  458. input := &ecs.ListContainerInstancesInput{
  459. Cluster: aws.String("default"),
  460. }
  461. result, err := svc.ListContainerInstances(input)
  462. if err != nil {
  463. if aerr, ok := err.(awserr.Error); ok {
  464. switch aerr.Code() {
  465. case ecs.ErrCodeServerException:
  466. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  467. case ecs.ErrCodeClientException:
  468. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  469. case ecs.ErrCodeInvalidParameterException:
  470. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  471. case ecs.ErrCodeClusterNotFoundException:
  472. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  473. default:
  474. fmt.Println(aerr.Error())
  475. }
  476. } else {
  477. // Print the error, cast err to awserr.Error to get the Code and
  478. // Message from an error.
  479. fmt.Println(err.Error())
  480. }
  481. return
  482. }
  483. fmt.Println(result)
  484. }
  485. // To list the services in a cluster
  486. //
  487. // This example lists the services running in the default cluster for an account.
  488. func ExampleECS_ListServices_shared00() {
  489. svc := ecs.New(session.New())
  490. input := &ecs.ListServicesInput{}
  491. result, err := svc.ListServices(input)
  492. if err != nil {
  493. if aerr, ok := err.(awserr.Error); ok {
  494. switch aerr.Code() {
  495. case ecs.ErrCodeServerException:
  496. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  497. case ecs.ErrCodeClientException:
  498. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  499. case ecs.ErrCodeInvalidParameterException:
  500. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  501. case ecs.ErrCodeClusterNotFoundException:
  502. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  503. default:
  504. fmt.Println(aerr.Error())
  505. }
  506. } else {
  507. // Print the error, cast err to awserr.Error to get the Code and
  508. // Message from an error.
  509. fmt.Println(err.Error())
  510. }
  511. return
  512. }
  513. fmt.Println(result)
  514. }
  515. // To list the tags for a cluster.
  516. //
  517. // This example lists the tags for the 'dev' cluster.
  518. func ExampleECS_ListTagsForResource_shared00() {
  519. svc := ecs.New(session.New())
  520. input := &ecs.ListTagsForResourceInput{
  521. ResourceArn: aws.String("arn:aws:ecs:region:aws_account_id:cluster/dev"),
  522. }
  523. result, err := svc.ListTagsForResource(input)
  524. if err != nil {
  525. if aerr, ok := err.(awserr.Error); ok {
  526. switch aerr.Code() {
  527. case ecs.ErrCodeServerException:
  528. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  529. case ecs.ErrCodeClientException:
  530. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  531. case ecs.ErrCodeClusterNotFoundException:
  532. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  533. case ecs.ErrCodeInvalidParameterException:
  534. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  535. default:
  536. fmt.Println(aerr.Error())
  537. }
  538. } else {
  539. // Print the error, cast err to awserr.Error to get the Code and
  540. // Message from an error.
  541. fmt.Println(err.Error())
  542. }
  543. return
  544. }
  545. fmt.Println(result)
  546. }
  547. // To list your registered task definition families
  548. //
  549. // This example lists all of your registered task definition families.
  550. func ExampleECS_ListTaskDefinitionFamilies_shared00() {
  551. svc := ecs.New(session.New())
  552. input := &ecs.ListTaskDefinitionFamiliesInput{}
  553. result, err := svc.ListTaskDefinitionFamilies(input)
  554. if err != nil {
  555. if aerr, ok := err.(awserr.Error); ok {
  556. switch aerr.Code() {
  557. case ecs.ErrCodeServerException:
  558. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  559. case ecs.ErrCodeClientException:
  560. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  561. case ecs.ErrCodeInvalidParameterException:
  562. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  563. default:
  564. fmt.Println(aerr.Error())
  565. }
  566. } else {
  567. // Print the error, cast err to awserr.Error to get the Code and
  568. // Message from an error.
  569. fmt.Println(err.Error())
  570. }
  571. return
  572. }
  573. fmt.Println(result)
  574. }
  575. // To filter your registered task definition families
  576. //
  577. // This example lists the task definition revisions that start with "hpcc".
  578. func ExampleECS_ListTaskDefinitionFamilies_shared01() {
  579. svc := ecs.New(session.New())
  580. input := &ecs.ListTaskDefinitionFamiliesInput{
  581. FamilyPrefix: aws.String("hpcc"),
  582. }
  583. result, err := svc.ListTaskDefinitionFamilies(input)
  584. if err != nil {
  585. if aerr, ok := err.(awserr.Error); ok {
  586. switch aerr.Code() {
  587. case ecs.ErrCodeServerException:
  588. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  589. case ecs.ErrCodeClientException:
  590. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  591. case ecs.ErrCodeInvalidParameterException:
  592. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  593. default:
  594. fmt.Println(aerr.Error())
  595. }
  596. } else {
  597. // Print the error, cast err to awserr.Error to get the Code and
  598. // Message from an error.
  599. fmt.Println(err.Error())
  600. }
  601. return
  602. }
  603. fmt.Println(result)
  604. }
  605. // To list your registered task definitions
  606. //
  607. // This example lists all of your registered task definitions.
  608. func ExampleECS_ListTaskDefinitions_shared00() {
  609. svc := ecs.New(session.New())
  610. input := &ecs.ListTaskDefinitionsInput{}
  611. result, err := svc.ListTaskDefinitions(input)
  612. if err != nil {
  613. if aerr, ok := err.(awserr.Error); ok {
  614. switch aerr.Code() {
  615. case ecs.ErrCodeServerException:
  616. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  617. case ecs.ErrCodeClientException:
  618. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  619. case ecs.ErrCodeInvalidParameterException:
  620. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  621. default:
  622. fmt.Println(aerr.Error())
  623. }
  624. } else {
  625. // Print the error, cast err to awserr.Error to get the Code and
  626. // Message from an error.
  627. fmt.Println(err.Error())
  628. }
  629. return
  630. }
  631. fmt.Println(result)
  632. }
  633. // To list the registered task definitions in a family
  634. //
  635. // This example lists the task definition revisions of a specified family.
  636. func ExampleECS_ListTaskDefinitions_shared01() {
  637. svc := ecs.New(session.New())
  638. input := &ecs.ListTaskDefinitionsInput{
  639. FamilyPrefix: aws.String("wordpress"),
  640. }
  641. result, err := svc.ListTaskDefinitions(input)
  642. if err != nil {
  643. if aerr, ok := err.(awserr.Error); ok {
  644. switch aerr.Code() {
  645. case ecs.ErrCodeServerException:
  646. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  647. case ecs.ErrCodeClientException:
  648. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  649. case ecs.ErrCodeInvalidParameterException:
  650. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  651. default:
  652. fmt.Println(aerr.Error())
  653. }
  654. } else {
  655. // Print the error, cast err to awserr.Error to get the Code and
  656. // Message from an error.
  657. fmt.Println(err.Error())
  658. }
  659. return
  660. }
  661. fmt.Println(result)
  662. }
  663. // To list the tasks in a cluster
  664. //
  665. // This example lists all of the tasks in a cluster.
  666. func ExampleECS_ListTasks_shared00() {
  667. svc := ecs.New(session.New())
  668. input := &ecs.ListTasksInput{
  669. Cluster: aws.String("default"),
  670. }
  671. result, err := svc.ListTasks(input)
  672. if err != nil {
  673. if aerr, ok := err.(awserr.Error); ok {
  674. switch aerr.Code() {
  675. case ecs.ErrCodeServerException:
  676. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  677. case ecs.ErrCodeClientException:
  678. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  679. case ecs.ErrCodeInvalidParameterException:
  680. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  681. case ecs.ErrCodeClusterNotFoundException:
  682. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  683. case ecs.ErrCodeServiceNotFoundException:
  684. fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
  685. default:
  686. fmt.Println(aerr.Error())
  687. }
  688. } else {
  689. // Print the error, cast err to awserr.Error to get the Code and
  690. // Message from an error.
  691. fmt.Println(err.Error())
  692. }
  693. return
  694. }
  695. fmt.Println(result)
  696. }
  697. // To list the tasks on a particular container instance
  698. //
  699. // This example lists the tasks of a specified container instance. Specifying a ``containerInstance``
  700. // value limits the results to tasks that belong to that container instance.
  701. func ExampleECS_ListTasks_shared01() {
  702. svc := ecs.New(session.New())
  703. input := &ecs.ListTasksInput{
  704. Cluster: aws.String("default"),
  705. ContainerInstance: aws.String("f6bbb147-5370-4ace-8c73-c7181ded911f"),
  706. }
  707. result, err := svc.ListTasks(input)
  708. if err != nil {
  709. if aerr, ok := err.(awserr.Error); ok {
  710. switch aerr.Code() {
  711. case ecs.ErrCodeServerException:
  712. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  713. case ecs.ErrCodeClientException:
  714. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  715. case ecs.ErrCodeInvalidParameterException:
  716. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  717. case ecs.ErrCodeClusterNotFoundException:
  718. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  719. case ecs.ErrCodeServiceNotFoundException:
  720. fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
  721. default:
  722. fmt.Println(aerr.Error())
  723. }
  724. } else {
  725. // Print the error, cast err to awserr.Error to get the Code and
  726. // Message from an error.
  727. fmt.Println(err.Error())
  728. }
  729. return
  730. }
  731. fmt.Println(result)
  732. }
  733. // To register a task definition
  734. //
  735. // This example registers a task definition to the specified family.
  736. func ExampleECS_RegisterTaskDefinition_shared00() {
  737. svc := ecs.New(session.New())
  738. input := &ecs.RegisterTaskDefinitionInput{
  739. ContainerDefinitions: []*ecs.ContainerDefinition{
  740. {
  741. Command: []*string{
  742. aws.String("sleep"),
  743. aws.String("360"),
  744. },
  745. Cpu: aws.Int64(10),
  746. Essential: aws.Bool(true),
  747. Image: aws.String("busybox"),
  748. Memory: aws.Int64(10),
  749. Name: aws.String("sleep"),
  750. },
  751. },
  752. Family: aws.String("sleep360"),
  753. TaskRoleArn: aws.String(""),
  754. }
  755. result, err := svc.RegisterTaskDefinition(input)
  756. if err != nil {
  757. if aerr, ok := err.(awserr.Error); ok {
  758. switch aerr.Code() {
  759. case ecs.ErrCodeServerException:
  760. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  761. case ecs.ErrCodeClientException:
  762. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  763. case ecs.ErrCodeInvalidParameterException:
  764. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  765. default:
  766. fmt.Println(aerr.Error())
  767. }
  768. } else {
  769. // Print the error, cast err to awserr.Error to get the Code and
  770. // Message from an error.
  771. fmt.Println(err.Error())
  772. }
  773. return
  774. }
  775. fmt.Println(result)
  776. }
  777. // To run a task on your default cluster
  778. //
  779. // This example runs the specified task definition on your default cluster.
  780. func ExampleECS_RunTask_shared00() {
  781. svc := ecs.New(session.New())
  782. input := &ecs.RunTaskInput{
  783. Cluster: aws.String("default"),
  784. TaskDefinition: aws.String("sleep360:1"),
  785. }
  786. result, err := svc.RunTask(input)
  787. if err != nil {
  788. if aerr, ok := err.(awserr.Error); ok {
  789. switch aerr.Code() {
  790. case ecs.ErrCodeServerException:
  791. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  792. case ecs.ErrCodeClientException:
  793. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  794. case ecs.ErrCodeInvalidParameterException:
  795. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  796. case ecs.ErrCodeClusterNotFoundException:
  797. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  798. case ecs.ErrCodeUnsupportedFeatureException:
  799. fmt.Println(ecs.ErrCodeUnsupportedFeatureException, aerr.Error())
  800. case ecs.ErrCodePlatformUnknownException:
  801. fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
  802. case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
  803. fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
  804. case ecs.ErrCodeAccessDeniedException:
  805. fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
  806. case ecs.ErrCodeBlockedException:
  807. fmt.Println(ecs.ErrCodeBlockedException, aerr.Error())
  808. default:
  809. fmt.Println(aerr.Error())
  810. }
  811. } else {
  812. // Print the error, cast err to awserr.Error to get the Code and
  813. // Message from an error.
  814. fmt.Println(err.Error())
  815. }
  816. return
  817. }
  818. fmt.Println(result)
  819. }
  820. // To tag a cluster.
  821. //
  822. // This example tags the 'dev' cluster with key 'team' and value 'dev'.
  823. func ExampleECS_TagResource_shared00() {
  824. svc := ecs.New(session.New())
  825. input := &ecs.TagResourceInput{
  826. ResourceArn: aws.String("arn:aws:ecs:region:aws_account_id:cluster/dev"),
  827. Tags: []*ecs.Tag{
  828. {
  829. Key: aws.String("team"),
  830. Value: aws.String("dev"),
  831. },
  832. },
  833. }
  834. result, err := svc.TagResource(input)
  835. if err != nil {
  836. if aerr, ok := err.(awserr.Error); ok {
  837. switch aerr.Code() {
  838. case ecs.ErrCodeServerException:
  839. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  840. case ecs.ErrCodeClientException:
  841. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  842. case ecs.ErrCodeClusterNotFoundException:
  843. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  844. case ecs.ErrCodeResourceNotFoundException:
  845. fmt.Println(ecs.ErrCodeResourceNotFoundException, aerr.Error())
  846. case ecs.ErrCodeInvalidParameterException:
  847. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  848. default:
  849. fmt.Println(aerr.Error())
  850. }
  851. } else {
  852. // Print the error, cast err to awserr.Error to get the Code and
  853. // Message from an error.
  854. fmt.Println(err.Error())
  855. }
  856. return
  857. }
  858. fmt.Println(result)
  859. }
  860. // To untag a cluster.
  861. //
  862. // This example deletes the 'team' tag from the 'dev' cluster.
  863. func ExampleECS_UntagResource_shared00() {
  864. svc := ecs.New(session.New())
  865. input := &ecs.UntagResourceInput{
  866. ResourceArn: aws.String("arn:aws:ecs:region:aws_account_id:cluster/dev"),
  867. TagKeys: []*string{
  868. aws.String("team"),
  869. },
  870. }
  871. result, err := svc.UntagResource(input)
  872. if err != nil {
  873. if aerr, ok := err.(awserr.Error); ok {
  874. switch aerr.Code() {
  875. case ecs.ErrCodeServerException:
  876. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  877. case ecs.ErrCodeClientException:
  878. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  879. case ecs.ErrCodeClusterNotFoundException:
  880. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  881. case ecs.ErrCodeResourceNotFoundException:
  882. fmt.Println(ecs.ErrCodeResourceNotFoundException, aerr.Error())
  883. case ecs.ErrCodeInvalidParameterException:
  884. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  885. default:
  886. fmt.Println(aerr.Error())
  887. }
  888. } else {
  889. // Print the error, cast err to awserr.Error to get the Code and
  890. // Message from an error.
  891. fmt.Println(err.Error())
  892. }
  893. return
  894. }
  895. fmt.Println(result)
  896. }
  897. // To change the task definition used in a service
  898. //
  899. // This example updates the my-http-service service to use the amazon-ecs-sample task
  900. // definition.
  901. func ExampleECS_UpdateService_shared00() {
  902. svc := ecs.New(session.New())
  903. input := &ecs.UpdateServiceInput{
  904. Service: aws.String("my-http-service"),
  905. TaskDefinition: aws.String("amazon-ecs-sample"),
  906. }
  907. result, err := svc.UpdateService(input)
  908. if err != nil {
  909. if aerr, ok := err.(awserr.Error); ok {
  910. switch aerr.Code() {
  911. case ecs.ErrCodeServerException:
  912. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  913. case ecs.ErrCodeClientException:
  914. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  915. case ecs.ErrCodeInvalidParameterException:
  916. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  917. case ecs.ErrCodeClusterNotFoundException:
  918. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  919. case ecs.ErrCodeServiceNotFoundException:
  920. fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
  921. case ecs.ErrCodeServiceNotActiveException:
  922. fmt.Println(ecs.ErrCodeServiceNotActiveException, aerr.Error())
  923. case ecs.ErrCodePlatformUnknownException:
  924. fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
  925. case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
  926. fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
  927. case ecs.ErrCodeAccessDeniedException:
  928. fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
  929. default:
  930. fmt.Println(aerr.Error())
  931. }
  932. } else {
  933. // Print the error, cast err to awserr.Error to get the Code and
  934. // Message from an error.
  935. fmt.Println(err.Error())
  936. }
  937. return
  938. }
  939. fmt.Println(result)
  940. }
  941. // To change the number of tasks in a service
  942. //
  943. // This example updates the desired count of the my-http-service service to 10.
  944. func ExampleECS_UpdateService_shared01() {
  945. svc := ecs.New(session.New())
  946. input := &ecs.UpdateServiceInput{
  947. DesiredCount: aws.Int64(10),
  948. Service: aws.String("my-http-service"),
  949. }
  950. result, err := svc.UpdateService(input)
  951. if err != nil {
  952. if aerr, ok := err.(awserr.Error); ok {
  953. switch aerr.Code() {
  954. case ecs.ErrCodeServerException:
  955. fmt.Println(ecs.ErrCodeServerException, aerr.Error())
  956. case ecs.ErrCodeClientException:
  957. fmt.Println(ecs.ErrCodeClientException, aerr.Error())
  958. case ecs.ErrCodeInvalidParameterException:
  959. fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
  960. case ecs.ErrCodeClusterNotFoundException:
  961. fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
  962. case ecs.ErrCodeServiceNotFoundException:
  963. fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
  964. case ecs.ErrCodeServiceNotActiveException:
  965. fmt.Println(ecs.ErrCodeServiceNotActiveException, aerr.Error())
  966. case ecs.ErrCodePlatformUnknownException:
  967. fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
  968. case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
  969. fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
  970. case ecs.ErrCodeAccessDeniedException:
  971. fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
  972. default:
  973. fmt.Println(aerr.Error())
  974. }
  975. } else {
  976. // Print the error, cast err to awserr.Error to get the Code and
  977. // Message from an error.
  978. fmt.Println(err.Error())
  979. }
  980. return
  981. }
  982. fmt.Println(result)
  983. }