Skip to content

Commit 3cf0a25

Browse files
authored
Merge branch 'master' into add-apigateway-and-alb
2 parents 3a1b902 + 7a94606 commit 3cf0a25

File tree

1 file changed

+73
-27
lines changed

1 file changed

+73
-27
lines changed

Sources/AWSLambdaEvents/AWSRegion.swift

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,77 @@
1616
// $ aws ssm get-parameters-by-path --path /aws/service/global-infrastructure/services/lambda/regions --output json
1717

1818
/// Enumeration of the AWS Regions.
19-
public enum AWSRegion: String, Codable {
20-
case ap_northeast_1 = "ap-northeast-1"
21-
case ap_northeast_2 = "ap-northeast-2"
22-
case ap_east_1 = "ap-east-1"
23-
case ap_southeast_1 = "ap-southeast-1"
24-
case ap_southeast_2 = "ap-southeast-2"
25-
case ap_south_1 = "ap-south-1"
26-
27-
case cn_north_1 = "cn-north-1"
28-
case cn_northwest_1 = "cn-northwest-1"
29-
30-
case eu_north_1 = "eu-north-1"
31-
case eu_west_1 = "eu-west-1"
32-
case eu_west_2 = "eu-west-2"
33-
case eu_west_3 = "eu-west-3"
34-
case eu_central_1 = "eu-central-1"
35-
36-
case us_east_1 = "us-east-1"
37-
case us_east_2 = "us-east-2"
38-
case us_west_1 = "us-west-1"
39-
case us_west_2 = "us-west-2"
40-
case us_gov_east_1 = "us-gov-east-1"
41-
case us_gov_west_1 = "us-gov-west-1"
42-
43-
case ca_central_1 = "ca-central-1"
44-
case sa_east_1 = "sa-east-1"
45-
case me_south_1 = "me-south-1"
19+
public struct AWSRegion: RawRepresentable, Equatable {
20+
public typealias RawValue = String
21+
22+
public let rawValue: String
23+
24+
public init?(rawValue: String) {
25+
self.rawValue = rawValue
26+
}
27+
28+
static var all: [AWSRegion] = [
29+
Self.ap_northeast_1,
30+
Self.ap_northeast_2,
31+
Self.ap_east_1,
32+
Self.ap_southeast_1,
33+
Self.ap_southeast_2,
34+
Self.ap_south_1,
35+
Self.cn_north_1,
36+
Self.cn_northwest_1,
37+
Self.eu_north_1,
38+
Self.eu_west_1,
39+
Self.eu_west_2,
40+
Self.eu_west_3,
41+
Self.eu_central_1,
42+
Self.us_east_1,
43+
Self.us_east_2,
44+
Self.us_west_1,
45+
Self.us_west_2,
46+
Self.us_gov_east_1,
47+
Self.us_gov_west_1,
48+
Self.ca_central_1,
49+
Self.sa_east_1,
50+
Self.me_south_1,
51+
]
52+
53+
public static var ap_northeast_1: Self { AWSRegion(rawValue: "ap-northeast-1")! }
54+
public static var ap_northeast_2: Self { AWSRegion(rawValue: "ap-northeast-2")! }
55+
public static var ap_east_1: Self { AWSRegion(rawValue: "ap-east-1")! }
56+
public static var ap_southeast_1: Self { AWSRegion(rawValue: "ap-southeast-1")! }
57+
public static var ap_southeast_2: Self { AWSRegion(rawValue: "ap-southeast-2")! }
58+
public static var ap_south_1: Self { AWSRegion(rawValue: "ap-south-1")! }
59+
60+
public static var cn_north_1: Self { AWSRegion(rawValue: "cn-north-1")! }
61+
public static var cn_northwest_1: Self { AWSRegion(rawValue: "cn-northwest-1")! }
62+
63+
public static var eu_north_1: Self { AWSRegion(rawValue: "eu-north-1")! }
64+
public static var eu_west_1: Self { AWSRegion(rawValue: "eu-west-1")! }
65+
public static var eu_west_2: Self { AWSRegion(rawValue: "eu-west-2")! }
66+
public static var eu_west_3: Self { AWSRegion(rawValue: "eu-west-3")! }
67+
public static var eu_central_1: Self { AWSRegion(rawValue: "eu-central-1")! }
68+
69+
public static var us_east_1: Self { AWSRegion(rawValue: "us-east-1")! }
70+
public static var us_east_2: Self { AWSRegion(rawValue: "us-east-2")! }
71+
public static var us_west_1: Self { AWSRegion(rawValue: "us-west-1")! }
72+
public static var us_west_2: Self { AWSRegion(rawValue: "us-west-2")! }
73+
public static var us_gov_east_1: Self { AWSRegion(rawValue: "us-gov-east-1")! }
74+
public static var us_gov_west_1: Self { AWSRegion(rawValue: "us-gov-west-1")! }
75+
76+
public static var ca_central_1: Self { AWSRegion(rawValue: "ca-central-1")! }
77+
public static var sa_east_1: Self { AWSRegion(rawValue: "sa-east-1")! }
78+
public static var me_south_1: Self { AWSRegion(rawValue: "me-south-1")! }
79+
}
80+
81+
extension AWSRegion: Codable {
82+
public init(from decoder: Decoder) throws {
83+
let container = try decoder.singleValueContainer()
84+
let region = try container.decode(String.self)
85+
self.init(rawValue: region)!
86+
}
87+
88+
public func encode(to encoder: Encoder) throws {
89+
var container = encoder.singleValueContainer()
90+
try container.encode(self.rawValue)
91+
}
4692
}

0 commit comments

Comments
 (0)