| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069 |
- // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
- package ecs_test
- import (
- "fmt"
- "strings"
- "time"
- "github.com/aws/aws-sdk-go/aws"
- "github.com/aws/aws-sdk-go/aws/awserr"
- "github.com/aws/aws-sdk-go/aws/session"
- "github.com/aws/aws-sdk-go/service/ecs"
- )
- var _ time.Duration
- var _ strings.Reader
- var _ aws.Config
- func parseTime(layout, value string) *time.Time {
- t, err := time.Parse(layout, value)
- if err != nil {
- panic(err)
- }
- return &t
- }
- // To create a new cluster
- //
- // This example creates a cluster in your default region.
- func ExampleECS_CreateCluster_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.CreateClusterInput{
- ClusterName: aws.String("my_cluster"),
- }
- result, err := svc.CreateCluster(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To create a new service
- //
- // This example creates a service in your default region called ``ecs-simple-service``.
- // The service uses the ``hello_world`` task definition and it maintains 10 copies of
- // that task.
- func ExampleECS_CreateService_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.CreateServiceInput{
- DesiredCount: aws.Int64(10),
- ServiceName: aws.String("ecs-simple-service"),
- TaskDefinition: aws.String("hello_world"),
- }
- result, err := svc.CreateService(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeUnsupportedFeatureException:
- fmt.Println(ecs.ErrCodeUnsupportedFeatureException, aerr.Error())
- case ecs.ErrCodePlatformUnknownException:
- fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
- case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
- fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
- case ecs.ErrCodeAccessDeniedException:
- fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To create a new service behind a load balancer
- //
- // This example creates a service in your default region called ``ecs-simple-service-elb``.
- // The service uses the ``ecs-demo`` task definition and it maintains 10 copies of that
- // task. You must reference an existing load balancer in the same region by its name.
- func ExampleECS_CreateService_shared01() {
- svc := ecs.New(session.New())
- input := &ecs.CreateServiceInput{
- DesiredCount: aws.Int64(10),
- LoadBalancers: []*ecs.LoadBalancer{
- {
- ContainerName: aws.String("simple-app"),
- ContainerPort: aws.Int64(80),
- LoadBalancerName: aws.String("EC2Contai-EcsElast-15DCDAURT3ZO2"),
- },
- },
- Role: aws.String("ecsServiceRole"),
- ServiceName: aws.String("ecs-simple-service-elb"),
- TaskDefinition: aws.String("console-sample-app-static"),
- }
- result, err := svc.CreateService(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeUnsupportedFeatureException:
- fmt.Println(ecs.ErrCodeUnsupportedFeatureException, aerr.Error())
- case ecs.ErrCodePlatformUnknownException:
- fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
- case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
- fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
- case ecs.ErrCodeAccessDeniedException:
- fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To delete an empty cluster
- //
- // This example deletes an empty cluster in your default region.
- func ExampleECS_DeleteCluster_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.DeleteClusterInput{
- Cluster: aws.String("my_cluster"),
- }
- result, err := svc.DeleteCluster(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeClusterContainsContainerInstancesException:
- fmt.Println(ecs.ErrCodeClusterContainsContainerInstancesException, aerr.Error())
- case ecs.ErrCodeClusterContainsServicesException:
- fmt.Println(ecs.ErrCodeClusterContainsServicesException, aerr.Error())
- case ecs.ErrCodeClusterContainsTasksException:
- fmt.Println(ecs.ErrCodeClusterContainsTasksException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To delete a service
- //
- // This example deletes the my-http-service service. The service must have a desired
- // count and running count of 0 before you can delete it.
- func ExampleECS_DeleteService_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.DeleteServiceInput{
- Service: aws.String("my-http-service"),
- }
- result, err := svc.DeleteService(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeServiceNotFoundException:
- fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To deregister a container instance from a cluster
- //
- // This example deregisters a container instance from the specified cluster in your
- // default region. If there are still tasks running on the container instance, you must
- // either stop those tasks before deregistering, or use the force option.
- func ExampleECS_DeregisterContainerInstance_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.DeregisterContainerInstanceInput{
- Cluster: aws.String("default"),
- ContainerInstance: aws.String("container_instance_UUID"),
- Force: aws.Bool(true),
- }
- result, err := svc.DeregisterContainerInstance(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To describe a cluster
- //
- // This example provides a description of the specified cluster in your default region.
- func ExampleECS_DescribeClusters_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.DescribeClustersInput{
- Clusters: []*string{
- aws.String("default"),
- },
- }
- result, err := svc.DescribeClusters(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To describe container instance
- //
- // This example provides a description of the specified container instance in your default
- // region, using the container instance UUID as an identifier.
- func ExampleECS_DescribeContainerInstances_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.DescribeContainerInstancesInput{
- Cluster: aws.String("default"),
- ContainerInstances: []*string{
- aws.String("f2756532-8f13-4d53-87c9-aed50dc94cd7"),
- },
- }
- result, err := svc.DescribeContainerInstances(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To describe a service
- //
- // This example provides descriptive information about the service named ``ecs-simple-service``.
- func ExampleECS_DescribeServices_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.DescribeServicesInput{
- Services: []*string{
- aws.String("ecs-simple-service"),
- },
- }
- result, err := svc.DescribeServices(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To describe a task definition
- //
- // This example provides a description of the specified task definition.
- func ExampleECS_DescribeTaskDefinition_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.DescribeTaskDefinitionInput{
- TaskDefinition: aws.String("hello_world:8"),
- }
- result, err := svc.DescribeTaskDefinition(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To describe a task
- //
- // This example provides a description of the specified task, using the task UUID as
- // an identifier.
- func ExampleECS_DescribeTasks_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.DescribeTasksInput{
- Tasks: []*string{
- aws.String("c5cba4eb-5dad-405e-96db-71ef8eefe6a8"),
- },
- }
- result, err := svc.DescribeTasks(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To list your available clusters
- //
- // This example lists all of your available clusters in your default region.
- func ExampleECS_ListClusters_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.ListClustersInput{}
- result, err := svc.ListClusters(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To list your available container instances in a cluster
- //
- // This example lists all of your available container instances in the specified cluster
- // in your default region.
- func ExampleECS_ListContainerInstances_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.ListContainerInstancesInput{
- Cluster: aws.String("default"),
- }
- result, err := svc.ListContainerInstances(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To list the services in a cluster
- //
- // This example lists the services running in the default cluster for an account.
- func ExampleECS_ListServices_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.ListServicesInput{}
- result, err := svc.ListServices(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To list the tags for a cluster.
- //
- // This example lists the tags for the 'dev' cluster.
- func ExampleECS_ListTagsForResource_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.ListTagsForResourceInput{
- ResourceArn: aws.String("arn:aws:ecs:region:aws_account_id:cluster/dev"),
- }
- result, err := svc.ListTagsForResource(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To list your registered task definition families
- //
- // This example lists all of your registered task definition families.
- func ExampleECS_ListTaskDefinitionFamilies_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.ListTaskDefinitionFamiliesInput{}
- result, err := svc.ListTaskDefinitionFamilies(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To filter your registered task definition families
- //
- // This example lists the task definition revisions that start with "hpcc".
- func ExampleECS_ListTaskDefinitionFamilies_shared01() {
- svc := ecs.New(session.New())
- input := &ecs.ListTaskDefinitionFamiliesInput{
- FamilyPrefix: aws.String("hpcc"),
- }
- result, err := svc.ListTaskDefinitionFamilies(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To list your registered task definitions
- //
- // This example lists all of your registered task definitions.
- func ExampleECS_ListTaskDefinitions_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.ListTaskDefinitionsInput{}
- result, err := svc.ListTaskDefinitions(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To list the registered task definitions in a family
- //
- // This example lists the task definition revisions of a specified family.
- func ExampleECS_ListTaskDefinitions_shared01() {
- svc := ecs.New(session.New())
- input := &ecs.ListTaskDefinitionsInput{
- FamilyPrefix: aws.String("wordpress"),
- }
- result, err := svc.ListTaskDefinitions(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To list the tasks in a cluster
- //
- // This example lists all of the tasks in a cluster.
- func ExampleECS_ListTasks_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.ListTasksInput{
- Cluster: aws.String("default"),
- }
- result, err := svc.ListTasks(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeServiceNotFoundException:
- fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To list the tasks on a particular container instance
- //
- // This example lists the tasks of a specified container instance. Specifying a ``containerInstance``
- // value limits the results to tasks that belong to that container instance.
- func ExampleECS_ListTasks_shared01() {
- svc := ecs.New(session.New())
- input := &ecs.ListTasksInput{
- Cluster: aws.String("default"),
- ContainerInstance: aws.String("f6bbb147-5370-4ace-8c73-c7181ded911f"),
- }
- result, err := svc.ListTasks(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeServiceNotFoundException:
- fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To register a task definition
- //
- // This example registers a task definition to the specified family.
- func ExampleECS_RegisterTaskDefinition_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.RegisterTaskDefinitionInput{
- ContainerDefinitions: []*ecs.ContainerDefinition{
- {
- Command: []*string{
- aws.String("sleep"),
- aws.String("360"),
- },
- Cpu: aws.Int64(10),
- Essential: aws.Bool(true),
- Image: aws.String("busybox"),
- Memory: aws.Int64(10),
- Name: aws.String("sleep"),
- },
- },
- Family: aws.String("sleep360"),
- TaskRoleArn: aws.String(""),
- }
- result, err := svc.RegisterTaskDefinition(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To run a task on your default cluster
- //
- // This example runs the specified task definition on your default cluster.
- func ExampleECS_RunTask_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.RunTaskInput{
- Cluster: aws.String("default"),
- TaskDefinition: aws.String("sleep360:1"),
- }
- result, err := svc.RunTask(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeUnsupportedFeatureException:
- fmt.Println(ecs.ErrCodeUnsupportedFeatureException, aerr.Error())
- case ecs.ErrCodePlatformUnknownException:
- fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
- case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
- fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
- case ecs.ErrCodeAccessDeniedException:
- fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
- case ecs.ErrCodeBlockedException:
- fmt.Println(ecs.ErrCodeBlockedException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To tag a cluster.
- //
- // This example tags the 'dev' cluster with key 'team' and value 'dev'.
- func ExampleECS_TagResource_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.TagResourceInput{
- ResourceArn: aws.String("arn:aws:ecs:region:aws_account_id:cluster/dev"),
- Tags: []*ecs.Tag{
- {
- Key: aws.String("team"),
- Value: aws.String("dev"),
- },
- },
- }
- result, err := svc.TagResource(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeResourceNotFoundException:
- fmt.Println(ecs.ErrCodeResourceNotFoundException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To untag a cluster.
- //
- // This example deletes the 'team' tag from the 'dev' cluster.
- func ExampleECS_UntagResource_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.UntagResourceInput{
- ResourceArn: aws.String("arn:aws:ecs:region:aws_account_id:cluster/dev"),
- TagKeys: []*string{
- aws.String("team"),
- },
- }
- result, err := svc.UntagResource(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeResourceNotFoundException:
- fmt.Println(ecs.ErrCodeResourceNotFoundException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To change the task definition used in a service
- //
- // This example updates the my-http-service service to use the amazon-ecs-sample task
- // definition.
- func ExampleECS_UpdateService_shared00() {
- svc := ecs.New(session.New())
- input := &ecs.UpdateServiceInput{
- Service: aws.String("my-http-service"),
- TaskDefinition: aws.String("amazon-ecs-sample"),
- }
- result, err := svc.UpdateService(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeServiceNotFoundException:
- fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
- case ecs.ErrCodeServiceNotActiveException:
- fmt.Println(ecs.ErrCodeServiceNotActiveException, aerr.Error())
- case ecs.ErrCodePlatformUnknownException:
- fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
- case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
- fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
- case ecs.ErrCodeAccessDeniedException:
- fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
- // To change the number of tasks in a service
- //
- // This example updates the desired count of the my-http-service service to 10.
- func ExampleECS_UpdateService_shared01() {
- svc := ecs.New(session.New())
- input := &ecs.UpdateServiceInput{
- DesiredCount: aws.Int64(10),
- Service: aws.String("my-http-service"),
- }
- result, err := svc.UpdateService(input)
- if err != nil {
- if aerr, ok := err.(awserr.Error); ok {
- switch aerr.Code() {
- case ecs.ErrCodeServerException:
- fmt.Println(ecs.ErrCodeServerException, aerr.Error())
- case ecs.ErrCodeClientException:
- fmt.Println(ecs.ErrCodeClientException, aerr.Error())
- case ecs.ErrCodeInvalidParameterException:
- fmt.Println(ecs.ErrCodeInvalidParameterException, aerr.Error())
- case ecs.ErrCodeClusterNotFoundException:
- fmt.Println(ecs.ErrCodeClusterNotFoundException, aerr.Error())
- case ecs.ErrCodeServiceNotFoundException:
- fmt.Println(ecs.ErrCodeServiceNotFoundException, aerr.Error())
- case ecs.ErrCodeServiceNotActiveException:
- fmt.Println(ecs.ErrCodeServiceNotActiveException, aerr.Error())
- case ecs.ErrCodePlatformUnknownException:
- fmt.Println(ecs.ErrCodePlatformUnknownException, aerr.Error())
- case ecs.ErrCodePlatformTaskDefinitionIncompatibilityException:
- fmt.Println(ecs.ErrCodePlatformTaskDefinitionIncompatibilityException, aerr.Error())
- case ecs.ErrCodeAccessDeniedException:
- fmt.Println(ecs.ErrCodeAccessDeniedException, aerr.Error())
- default:
- fmt.Println(aerr.Error())
- }
- } else {
- // Print the error, cast err to awserr.Error to get the Code and
- // Message from an error.
- fmt.Println(err.Error())
- }
- return
- }
- fmt.Println(result)
- }
|