@@ -31,9 +31,10 @@ import (
31
31
)
32
32
33
33
var (
34
- ec2MetaDataServiceUrl = "http://169.254.169.254/latest/dynamic/instance-identity/document"
35
- ec2PricingServiceUrlTemplate = "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/%s/index.json"
36
- staticListLastUpdateTime = "2019-10-14"
34
+ ec2MetaDataServiceUrl = "http://169.254.169.254/latest/dynamic/instance-identity/document"
35
+ ec2PricingServiceUrlTemplate = "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/%s/index.json"
36
+ ec2PricingServiceUrlTemplateCN = "https://pricing.cn-north-1.amazonaws.com.cn/offers/v1.0/cn/AmazonEC2/current/%s/index.json"
37
+ staticListLastUpdateTime = "2019-10-14"
37
38
)
38
39
39
40
type response struct {
@@ -53,6 +54,13 @@ type productAttributes struct {
53
54
54
55
// GenerateEC2InstanceTypes returns a map of ec2 resources
55
56
func GenerateEC2InstanceTypes (region string ) (map [string ]* InstanceType , error ) {
57
+ var pricingUrlTemplate string
58
+ if strings .HasPrefix (region , "cn-" ) {
59
+ pricingUrlTemplate = ec2PricingServiceUrlTemplateCN
60
+ } else {
61
+ pricingUrlTemplate = ec2PricingServiceUrlTemplate
62
+ }
63
+
56
64
instanceTypes := make (map [string ]* InstanceType )
57
65
58
66
resolver := endpoints .DefaultResolver ()
@@ -64,7 +72,7 @@ func GenerateEC2InstanceTypes(region string) (map[string]*InstanceType, error) {
64
72
continue
65
73
}
66
74
67
- url := fmt .Sprintf (ec2PricingServiceUrlTemplate , r .ID ())
75
+ url := fmt .Sprintf (pricingUrlTemplate , r .ID ())
68
76
klog .V (1 ).Infof ("fetching %s\n " , url )
69
77
res , err := http .Get (url )
70
78
if err != nil {
0 commit comments