route/vendor/github.com/aws/aws-sdk-go/service/ecs/examples_test.go

952 lines
29 KiB
Go

// 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 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 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)
}