Skip to content

Commit 9267050

Browse files
committed
Fixes Event namespacing problems
1 parent edbfa79 commit 9267050

21 files changed

+496
-521
lines changed

Examples/LambdaFunctions/Sources/APIGateway/main.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Lambda.run(APIGatewayProxyLambda())
2424

2525
// FIXME: Use proper Event abstractions once added to AWSLambdaRuntime
2626
struct APIGatewayProxyLambda: EventLoopLambdaHandler {
27-
public typealias In = APIGateway.V2.Request
28-
public typealias Out = APIGateway.V2.Response
27+
public typealias In = APIGatewayV2Request
28+
public typealias Out = APIGatewayV2Response
2929

3030
public func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<APIGateway.V2.Response> {
3131
context.logger.debug("hello, api gateway!")

Sources/AWSLambdaEvents/ALB.swift

+46-48
Original file line numberDiff line numberDiff line change
@@ -15,63 +15,61 @@
1515
import class Foundation.JSONEncoder
1616

1717
// https://github.com/aws/aws-lambda-go/blob/master/events/alb.go
18-
public enum ALB {
19-
/// ALBTargetGroupRequest contains data originating from the ALB Lambda target group integration
20-
public struct TargetGroupRequest: Codable {
21-
/// ALBTargetGroupRequestContext contains the information to identify the load balancer invoking the lambda
22-
public struct Context: Codable {
23-
public let elb: ELBContext
24-
}
18+
/// ALBTargetGroupRequest contains data originating from the ALB Lambda target group integration
19+
public struct ALBTargetGroupRequest: Codable {
20+
/// ALBTargetGroupRequestContext contains the information to identify the load balancer invoking the lambda
21+
public struct Context: Codable {
22+
public let elb: ELBContext
23+
}
2524

26-
public let httpMethod: HTTPMethod
27-
public let path: String
28-
public let queryStringParameters: [String: String]
25+
public let httpMethod: HTTPMethod
26+
public let path: String
27+
public let queryStringParameters: [String: String]
2928

30-
/// Depending on your configuration of your target group either `headers` or `multiValueHeaders`
31-
/// are set.
32-
///
33-
/// For more information visit:
34-
/// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers
35-
public let headers: HTTPHeaders?
29+
/// Depending on your configuration of your target group either `headers` or `multiValueHeaders`
30+
/// are set.
31+
///
32+
/// For more information visit:
33+
/// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers
34+
public let headers: HTTPHeaders?
3635

37-
/// Depending on your configuration of your target group either `headers` or `multiValueHeaders`
38-
/// are set.
39-
///
40-
/// For more information visit:
41-
/// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers
42-
public let multiValueHeaders: HTTPMultiValueHeaders?
43-
public let requestContext: Context
44-
public let isBase64Encoded: Bool
45-
public let body: String?
46-
}
36+
/// Depending on your configuration of your target group either `headers` or `multiValueHeaders`
37+
/// are set.
38+
///
39+
/// For more information visit:
40+
/// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers
41+
public let multiValueHeaders: HTTPMultiValueHeaders?
42+
public let requestContext: Context
43+
public let isBase64Encoded: Bool
44+
public let body: String?
4745

4846
/// ELBContext contains the information to identify the ARN invoking the lambda
4947
public struct ELBContext: Codable {
5048
public let targetGroupArn: String
5149
}
50+
}
5251

53-
public struct TargetGroupResponse: Codable {
54-
public var statusCode: HTTPResponseStatus
55-
public var statusDescription: String?
56-
public var headers: HTTPHeaders?
57-
public var multiValueHeaders: HTTPMultiValueHeaders?
58-
public var body: String
59-
public var isBase64Encoded: Bool
52+
public struct ALBTargetGroupResponse: Codable {
53+
public var statusCode: HTTPResponseStatus
54+
public var statusDescription: String?
55+
public var headers: HTTPHeaders?
56+
public var multiValueHeaders: HTTPMultiValueHeaders?
57+
public var body: String
58+
public var isBase64Encoded: Bool
6059

61-
public init(
62-
statusCode: HTTPResponseStatus,
63-
statusDescription: String? = nil,
64-
headers: HTTPHeaders? = nil,
65-
multiValueHeaders: HTTPMultiValueHeaders? = nil,
66-
body: String = "",
67-
isBase64Encoded: Bool = false
68-
) {
69-
self.statusCode = statusCode
70-
self.statusDescription = statusDescription
71-
self.headers = headers
72-
self.multiValueHeaders = multiValueHeaders
73-
self.body = body
74-
self.isBase64Encoded = isBase64Encoded
75-
}
60+
public init(
61+
statusCode: HTTPResponseStatus,
62+
statusDescription: String? = nil,
63+
headers: HTTPHeaders? = nil,
64+
multiValueHeaders: HTTPMultiValueHeaders? = nil,
65+
body: String = "",
66+
isBase64Encoded: Bool = false
67+
) {
68+
self.statusCode = statusCode
69+
self.statusDescription = statusDescription
70+
self.headers = headers
71+
self.multiValueHeaders = multiValueHeaders
72+
self.body = body
73+
self.isBase64Encoded = isBase64Encoded
7674
}
7775
}

Sources/AWSLambdaEvents/APIGateway+V2.swift

+75-83
Original file line numberDiff line numberDiff line change
@@ -12,105 +12,97 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
extension APIGateway {
16-
public struct V2 {}
17-
}
15+
/// APIGatewayV2Request contains data coming from the new HTTP API Gateway
16+
struct APIGatewayV2Request: Codable {
17+
/// Context contains the information to identify the AWS account and resources invoking the Lambda function.
18+
public struct Context: Codable {
19+
public struct HTTP: Codable {
20+
public let method: HTTPMethod
21+
public let path: String
22+
public let `protocol`: String
23+
public let sourceIp: String
24+
public let userAgent: String
25+
}
1826

19-
extension APIGateway.V2 {
20-
/// APIGateway.V2.Request contains data coming from the new HTTP API Gateway
21-
public struct Request: Codable {
22-
/// Context contains the information to identify the AWS account and resources invoking the Lambda function.
23-
public struct Context: Codable {
24-
public struct HTTP: Codable {
25-
public let method: HTTPMethod
26-
public let path: String
27-
public let `protocol`: String
28-
public let sourceIp: String
29-
public let userAgent: String
27+
/// Authorizer contains authorizer information for the request context.
28+
public struct Authorizer: Codable {
29+
/// JWT contains JWT authorizer information for the request context.
30+
public struct JWT: Codable {
31+
public let claims: [String: String]
32+
public let scopes: [String]?
3033
}
3134

32-
/// Authorizer contains authorizer information for the request context.
33-
public struct Authorizer: Codable {
34-
/// JWT contains JWT authorizer information for the request context.
35-
public struct JWT: Codable {
36-
public let claims: [String: String]
37-
public let scopes: [String]?
38-
}
39-
40-
public let jwt: JWT
41-
}
35+
public let jwt: JWT
36+
}
4237

43-
public let accountId: String
44-
public let apiId: String
45-
public let domainName: String
46-
public let domainPrefix: String
47-
public let stage: String
48-
public let requestId: String
38+
public let accountId: String
39+
public let apiId: String
40+
public let domainName: String
41+
public let domainPrefix: String
42+
public let stage: String
43+
public let requestId: String
4944

50-
public let http: HTTP
51-
public let authorizer: Authorizer?
45+
public let http: HTTP
46+
public let authorizer: Authorizer?
5247

53-
/// The request time in format: 23/Apr/2020:11:08:18 +0000
54-
public let time: String
55-
public let timeEpoch: UInt64
56-
}
48+
/// The request time in format: 23/Apr/2020:11:08:18 +0000
49+
public let time: String
50+
public let timeEpoch: UInt64
51+
}
5752

58-
public let version: String
59-
public let routeKey: String
60-
public let rawPath: String
61-
public let rawQueryString: String
53+
public let version: String
54+
public let routeKey: String
55+
public let rawPath: String
56+
public let rawQueryString: String
6257

63-
public let cookies: [String]?
64-
public let headers: HTTPHeaders
65-
public let queryStringParameters: [String: String]?
66-
public let pathParameters: [String: String]?
58+
public let cookies: [String]?
59+
public let headers: HTTPHeaders
60+
public let queryStringParameters: [String: String]?
61+
public let pathParameters: [String: String]?
6762

68-
public let context: Context
69-
public let stageVariables: [String: String]?
63+
public let context: Context
64+
public let stageVariables: [String: String]?
7065

71-
public let body: String?
72-
public let isBase64Encoded: Bool
66+
public let body: String?
67+
public let isBase64Encoded: Bool
7368

74-
enum CodingKeys: String, CodingKey {
75-
case version
76-
case routeKey
77-
case rawPath
78-
case rawQueryString
69+
enum CodingKeys: String, CodingKey {
70+
case version
71+
case routeKey
72+
case rawPath
73+
case rawQueryString
7974

80-
case cookies
81-
case headers
82-
case queryStringParameters
83-
case pathParameters
75+
case cookies
76+
case headers
77+
case queryStringParameters
78+
case pathParameters
8479

85-
case context = "requestContext"
86-
case stageVariables
80+
case context = "requestContext"
81+
case stageVariables
8782

88-
case body
89-
case isBase64Encoded
90-
}
83+
case body
84+
case isBase64Encoded
9185
}
9286
}
9387

94-
extension APIGateway.V2 {
95-
public struct Response: Codable {
96-
public var statusCode: HTTPResponseStatus
97-
public var headers: HTTPHeaders?
98-
public var body: String?
99-
public var isBase64Encoded: Bool?
100-
public var cookies: [String]?
101-
102-
public init(
103-
statusCode: HTTPResponseStatus,
104-
headers: HTTPHeaders? = nil,
105-
body: String? = nil,
106-
isBase64Encoded: Bool? = nil,
107-
cookies: [String]? = nil
108-
) {
109-
self.statusCode = statusCode
110-
self.headers = headers
111-
self.body = body
112-
self.isBase64Encoded = isBase64Encoded
113-
self.cookies = cookies
114-
}
88+
public struct APIGatewayV2Response: Codable {
89+
public var statusCode: HTTPResponseStatus
90+
public var headers: HTTPHeaders?
91+
public var body: String?
92+
public var isBase64Encoded: Bool?
93+
public var cookies: [String]?
94+
95+
public init(
96+
statusCode: HTTPResponseStatus,
97+
headers: HTTPHeaders? = nil,
98+
body: String? = nil,
99+
isBase64Encoded: Bool? = nil,
100+
cookies: [String]? = nil
101+
) {
102+
self.statusCode = statusCode
103+
self.headers = headers
104+
self.body = body
105+
self.isBase64Encoded = isBase64Encoded
106+
self.cookies = cookies
115107
}
116108
}

0 commit comments

Comments
 (0)