Repository: cortexlabs/cortex (language: go)

Issue:
Spot price not reported correctly because of a lack of permissions
#### Description

When `cortex cluster info` is run for the AWS provider, the spot price reported for the existing nodes is incorrect. Instead of showing the spot price of a spot instance, it shows the on-demand instance price.

We resort to using the on-demand price if the spot price can't be retrieved, which is the case for this problem.

#### Expanding on this

Calling the `SpotInstancePrice` function returns an error with the following message: `UnauthorizedOperation: You are not authorized to perform this operation.`.

The AWS function that `SpotInstancePrice` is calling (that is erroring) is `DescribeSpotPriceHistory`:

```go
	result, err := c.EC2().DescribeSpotPriceHistory(&ec2.DescribeSpotPriceHistoryInput{
		InstanceTypes:       []*string{aws.String(instanceType)},
		ProductDescriptions: []*string{aws.String("Linux/UNIX")},
		StartTime:           aws.Time(time.Now()),
	})
```

Where `DescribeSpotPriceHistory` function has these docs:

```text
// DescribeSpotPriceHistory API operation for Amazon Elastic Compute Cloud.
//
// Describes the Spot price history. For more information, see Spot Instance
// pricing history (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances-history.html)
// in the Amazon EC2 User Guide for Linux Instances.
//
// When you specify a start and end time, this operation returns the prices
// of the instance types within the time range that you specified and the time
// when the price changed. The price is valid within the time period that you
// specified; the response merely indicates the last time that the price changed.
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for Amazon Elastic Compute Cloud's
// API operation DescribeSpotPriceHistory for usage and error information.
// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/DescribeSpotPriceHistory
```


Discussion / hints:

Fix patch:
diff --git a/pkg/types/clusterconfig/aws_policy.go b/pkg/types/clusterconfig/aws_policy.go
index d75e9d7686..06d6fe936a 100644
--- a/pkg/types/clusterconfig/aws_policy.go
+++ b/pkg/types/clusterconfig/aws_policy.go
@@ -45,7 +45,8 @@ var _cortexPolicy = `
 				"sts:GetCallerIdentity",
 				"ecr:GetAuthorizationToken",
 				"ecr:BatchGetImage",
-				"sqs:ListQueues"
+				"sqs:ListQueues",
+				"ec2:DescribeSpotPriceHistory"
 			],
 			"Effect": "Allow",
 			"Resource": "*"


Test patch: