/
endpoints.ts
83 lines (80 loc) · 2.51 KB
/
endpoints.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { RegionInfo, RegionInfoProvider } from "@aws-sdk/types";
// Partition default templates
const AWS_TEMPLATE = "codeguru-profiler.{region}.amazonaws.com";
const AWS_CN_TEMPLATE = "codeguru-profiler.{region}.amazonaws.com.cn";
const AWS_ISO_TEMPLATE = "codeguru-profiler.{region}.c2s.ic.gov";
const AWS_ISO_B_TEMPLATE = "codeguru-profiler.{region}.sc2s.sgov.gov";
const AWS_US_GOV_TEMPLATE = "codeguru-profiler.{region}.amazonaws.com";
// Partition regions
const AWS_REGIONS = new Set([
"af-south-1",
"ap-east-1",
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1",
"ap-southeast-2",
"ca-central-1",
"eu-central-1",
"eu-north-1",
"eu-south-1",
"eu-west-1",
"eu-west-2",
"eu-west-3",
"me-south-1",
"sa-east-1",
"us-east-1",
"us-east-2",
"us-west-1",
"us-west-2",
]);
const AWS_CN_REGIONS = new Set(["cn-north-1", "cn-northwest-1"]);
const AWS_ISO_REGIONS = new Set(["us-iso-east-1"]);
const AWS_ISO_B_REGIONS = new Set(["us-isob-east-1"]);
const AWS_US_GOV_REGIONS = new Set(["us-gov-east-1", "us-gov-west-1"]);
export const defaultRegionInfoProvider: RegionInfoProvider = (region: string, options?: any) => {
let regionInfo: RegionInfo | undefined = undefined;
switch (region) {
// First, try to match exact region names.
// Next, try to match partition endpoints.
default:
if (AWS_REGIONS.has(region)) {
regionInfo = {
hostname: AWS_TEMPLATE.replace("{region}", region),
partition: "aws",
};
}
if (AWS_CN_REGIONS.has(region)) {
regionInfo = {
hostname: AWS_CN_TEMPLATE.replace("{region}", region),
partition: "aws-cn",
};
}
if (AWS_ISO_REGIONS.has(region)) {
regionInfo = {
hostname: AWS_ISO_TEMPLATE.replace("{region}", region),
partition: "aws-iso",
};
}
if (AWS_ISO_B_REGIONS.has(region)) {
regionInfo = {
hostname: AWS_ISO_B_TEMPLATE.replace("{region}", region),
partition: "aws-iso-b",
};
}
if (AWS_US_GOV_REGIONS.has(region)) {
regionInfo = {
hostname: AWS_US_GOV_TEMPLATE.replace("{region}", region),
partition: "aws-us-gov",
};
}
// Finally, assume it's an AWS partition endpoint.
if (regionInfo === undefined) {
regionInfo = {
hostname: AWS_TEMPLATE.replace("{region}", region),
partition: "aws",
};
}
}
return Promise.resolve({ signingService: "codeguruprofiler", ...regionInfo });
};