Created
December 21, 2018 10:48
-
-
Save stephencoe/5d123137217a3a45d03f76690c58daf3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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