Skip to content

Instantly share code, notes, and snippets.

@stephencoe
Created December 21, 2018 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephencoe/5d123137217a3a45d03f76690c58daf3 to your computer and use it in GitHub Desktop.
Save stephencoe/5d123137217a3a45d03f76690c58daf3 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"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"
)
func main() {
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"),
Secrets: []*ecs.Secret{},
},
},
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment