-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package resources | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
) | ||
|
||
type EC2SpotInstanceRequest struct { | ||
svc *ec2.EC2 | ||
id string | ||
state string | ||
} | ||
|
||
func init() { | ||
register("EC2SpotInstanceRequest", ListEC2SpotInstanceRequests) | ||
} | ||
|
||
func ListEC2SpotInstanceRequests(sess *session.Session) ([]Resource, error) { | ||
svc := ec2.New(sess) | ||
|
||
resp, err := svc.DescribeSpotInstanceRequests(nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resources := make([]Resource, 0) | ||
for _, config := range resp.SpotInstanceRequestConfigs { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
resources = append(resources, &EC2SpotInstanceRequest{ | ||
svc: svc, | ||
id: *config.SpotInstanceRequestId, | ||
state: *config.SpotInstanceRequestState, | ||
This comment has been minimized.
Sorry, something went wrong.
ximena9201
Collaborator
|
||
}) | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (i *EC2SpotInstanceRequest) Filter() error { | ||
if i.state == "cancelled" { | ||
return fmt.Errorf("already cancelled") | ||
} | ||
return nil | ||
} | ||
|
||
func (i *EC2SpotInstanceRequest) Remove() error { | ||
params := &ec2.CancelSpotInstanceRequestsInput{ | ||
TerminateInstances: aws.Bool(true), | ||
This comment has been minimized.
Sorry, something went wrong.
ximena9201
Collaborator
|
||
SpotInstanceRequestIds: []*string{ | ||
&i.id, | ||
}, | ||
} | ||
|
||
_, err := i.svc.CancelSpotInstanceRequests(params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (i *EC2SpotInstanceRequest) String() string { | ||
return i.id | ||
} |
instead of
SpotInstanceRequestConfigs
, putSpotInstanceRequests
. Looks like this parameter doesn't exist.https://docs.aws.amazon.com/cli/latest/reference/ec2/cancel-spot-instance-requests.html