Skip to content

Commit

Permalink
update steps to create ecsInstanceRole
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstruck committed Feb 18, 2020
1 parent fe4a992 commit c410a8f
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions cmd/aws/batch/batchsvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ func (b *batchsvc) CreateComputeEnvironment() (*batch.ComputeEnvironmentDetail,
}

var instanceRole string
ip, err := iamCli.GetInstanceProfile(&iam.GetInstanceProfileInput{
InstanceProfileName: aws.String("ecsInstanceRole"),
})
grres, err = iamCli.GetRole(&iam.GetRoleInput{RoleName: aws.String("ecsInstanceRole")})
if err == nil {
instanceRole = *ip.InstanceProfile.Arn
instanceRole = *grres.Role.Arn
} else {
irPolicy := AssumeRolePolicy{
Version: "2012-10-17",
Expand All @@ -131,7 +129,7 @@ func (b *batchsvc) CreateComputeEnvironment() (*batch.ComputeEnvironmentDetail,
if err != nil {
return nil, fmt.Errorf("error marshaling assume role policy for ecsInstanceRole: %v", err)
}
_, err = iamCli.CreateRole(&iam.CreateRoleInput{
cr, err := iamCli.CreateRole(&iam.CreateRoleInput{
AssumeRolePolicyDocument: aws.String(string(irBinary)),
RoleName: aws.String("ecsInstanceRole"),
})
Expand All @@ -145,13 +143,7 @@ func (b *batchsvc) CreateComputeEnvironment() (*batch.ComputeEnvironmentDetail,
if err != nil {
return nil, fmt.Errorf("error attaching policies to ecsInstanceRole: %v", err)
}
ip, err = iamCli.GetInstanceProfile(&iam.GetInstanceProfileInput{
InstanceProfileName: aws.String("ecsInstanceRole"),
})
if err != nil {
return nil, fmt.Errorf("error fetching Intance Profile ARN for ecsInstanceRole: %v", err)
}
instanceRole = *ip.InstanceProfile.Arn
instanceRole = *cr.Role.Arn
}

input := &batch.CreateComputeEnvironmentInput{
Expand Down

0 comments on commit c410a8f

Please sign in to comment.