@@ -52,55 +52,56 @@ func GetCommandInvocationResult(context ssmiface.SSMAPI, jobs ...*ssm.SendComman
52
52
53
53
// Concurrently iterate through all items in []instanceIDs and get the invocation status
54
54
for _ , v := range jobs {
55
- wg .Add (len (v .Command .InstanceIds ))
56
- for _ , i := range v .Command .InstanceIds {
57
-
58
- go func (v * ssm.SendCommandOutput , i * string , context ssmiface.SSMAPI ) {
59
- defer wg .Done ()
60
- /*
61
- GetCommandInvocation() requires a GetCommandInvocationInput object, which
62
- has required parameters CommandId and InstanceId. It is important to note
63
- that unlike the execution of the command, you can only retrieve the invocation
64
- results for one instance+command at a time.
65
- */
66
- gciInput := & ssm.GetCommandInvocationInput {
67
- CommandId : v .Command .CommandId ,
68
- InstanceId : i ,
69
- }
70
-
71
- // Retrieve the status of the command invocation
72
- status , err := context .GetCommandInvocation (gciInput )
73
-
74
- // If we get "InvocationDoesNotExist", it just means we tried to check the results too quickly
75
- for awsErr , ok := err .(awserr.Error ); ok && err != nil && awsErr .Code () == "InvocationDoesNotExist" ; {
76
- time .Sleep (1000 * time .Millisecond )
77
- status , err = context .GetCommandInvocation (gciInput )
78
- }
79
-
80
- // If we somehow throw a real error here, something has gone screwy with our invocation or the target instance
81
- // See the docs on ssm.GetCommandInvocation() for error details
82
- if err != nil {
83
- errLog .Errorln (err )
84
- return
85
- }
86
-
87
- // If the invocation is in a pending state, we sleep for a couple seconds before retrying the query
88
- // NOTE: This may need to change based on API limits, but as there is no documentation, we'll have to wait and see.
89
- for * status .StatusDetails == "InProgress" || * status .StatusDetails == "Pending" {
90
- status , err = context .GetCommandInvocation (gciInput )
91
- time .Sleep (2000 * time .Millisecond )
92
- }
93
-
94
- if err != nil {
95
- errLog .Errorln (err )
96
- return
97
- }
98
-
99
- // Append the result to our slice of results
100
- results .Lock ()
101
- results .results = append (results .results , status )
102
- results .Unlock ()
103
- }(v , i , context )
55
+ if v .Command != nil {
56
+ for _ , i := range v .Command .InstanceIds {
57
+ wg .Add (1 )
58
+ go func (v * ssm.SendCommandOutput , i * string , context ssmiface.SSMAPI ) {
59
+ defer wg .Done ()
60
+ /*
61
+ GetCommandInvocation() requires a GetCommandInvocationInput object, which
62
+ has required parameters CommandId and InstanceId. It is important to note
63
+ that unlike the execution of the command, you can only retrieve the invocation
64
+ results for one instance+command at a time.
65
+ */
66
+ gciInput := & ssm.GetCommandInvocationInput {
67
+ CommandId : v .Command .CommandId ,
68
+ InstanceId : i ,
69
+ }
70
+
71
+ // Retrieve the status of the command invocation
72
+ status , err := context .GetCommandInvocation (gciInput )
73
+
74
+ // If we get "InvocationDoesNotExist", it just means we tried to check the results too quickly
75
+ for awsErr , ok := err .(awserr.Error ); ok && err != nil && awsErr .Code () == "InvocationDoesNotExist" ; {
76
+ time .Sleep (1000 * time .Millisecond )
77
+ status , err = context .GetCommandInvocation (gciInput )
78
+ }
79
+
80
+ // If we somehow throw a real error here, something has gone screwy with our invocation or the target instance
81
+ // See the docs on ssm.GetCommandInvocation() for error details
82
+ if err != nil {
83
+ errLog .Errorln (err )
84
+ return
85
+ }
86
+
87
+ // If the invocation is in a pending state, we sleep for a couple seconds before retrying the query
88
+ // NOTE: This may need to change based on API limits, but as there is no documentation, we'll have to wait and see.
89
+ for * status .StatusDetails == "InProgress" || * status .StatusDetails == "Pending" {
90
+ status , err = context .GetCommandInvocation (gciInput )
91
+ time .Sleep (2000 * time .Millisecond )
92
+ }
93
+
94
+ if err != nil {
95
+ errLog .Errorln (err )
96
+ return
97
+ }
98
+
99
+ // Append the result to our slice of results
100
+ results .Lock ()
101
+ results .results = append (results .results , status )
102
+ results .Unlock ()
103
+ }(v , i , context )
104
+ }
104
105
}
105
106
}
106
107
0 commit comments