Skip to content

Fixes AWS Event namespace problems #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Examples/LambdaFunctions/Sources/APIGateway/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Lambda.run(APIGatewayProxyLambda())

// FIXME: Use proper Event abstractions once added to AWSLambdaRuntime
struct APIGatewayProxyLambda: EventLoopLambdaHandler {
public typealias In = APIGateway.V2.Request
public typealias Out = APIGateway.V2.Response
typealias In = APIGatewayV2Request
typealias Out = APIGatewayV2Response

public func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<APIGateway.V2.Response> {
func handle(context: Lambda.Context, event: APIGatewayV2Request) -> EventLoopFuture<APIGatewayV2Response> {
context.logger.debug("hello, api gateway!")
return context.eventLoop.makeSucceededFuture(APIGateway.V2.Response(statusCode: .ok, body: "hello, world!"))
return context.eventLoop.makeSucceededFuture(APIGatewayV2Response(statusCode: .ok, body: "hello, world!"))
}
}
94 changes: 46 additions & 48 deletions Sources/AWSLambdaEvents/ALB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,61 @@
import class Foundation.JSONEncoder

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

public let httpMethod: HTTPMethod
public let path: String
public let queryStringParameters: [String: String]
public let httpMethod: HTTPMethod
public let path: String
public let queryStringParameters: [String: String]

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

/// Depending on your configuration of your target group either `headers` or `multiValueHeaders`
/// are set.
///
/// For more information visit:
/// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers
public let multiValueHeaders: HTTPMultiValueHeaders?
public let requestContext: Context
public let isBase64Encoded: Bool
public let body: String?
}
/// Depending on your configuration of your target group either `headers` or `multiValueHeaders`
/// are set.
///
/// For more information visit:
/// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers
public let multiValueHeaders: HTTPMultiValueHeaders?
public let requestContext: Context
public let isBase64Encoded: Bool
public let body: String?

/// ELBContext contains the information to identify the ARN invoking the lambda
public struct ELBContext: Codable {
public let targetGroupArn: String
}
}

public struct TargetGroupResponse: Codable {
public var statusCode: HTTPResponseStatus
public var statusDescription: String?
public var headers: HTTPHeaders?
public var multiValueHeaders: HTTPMultiValueHeaders?
public var body: String
public var isBase64Encoded: Bool
public struct ALBTargetGroupResponse: Codable {
public var statusCode: HTTPResponseStatus
public var statusDescription: String?
public var headers: HTTPHeaders?
public var multiValueHeaders: HTTPMultiValueHeaders?
public var body: String
public var isBase64Encoded: Bool

public init(
statusCode: HTTPResponseStatus,
statusDescription: String? = nil,
headers: HTTPHeaders? = nil,
multiValueHeaders: HTTPMultiValueHeaders? = nil,
body: String = "",
isBase64Encoded: Bool = false
) {
self.statusCode = statusCode
self.statusDescription = statusDescription
self.headers = headers
self.multiValueHeaders = multiValueHeaders
self.body = body
self.isBase64Encoded = isBase64Encoded
}
public init(
statusCode: HTTPResponseStatus,
statusDescription: String? = nil,
headers: HTTPHeaders? = nil,
multiValueHeaders: HTTPMultiValueHeaders? = nil,
body: String = "",
isBase64Encoded: Bool = false
) {
self.statusCode = statusCode
self.statusDescription = statusDescription
self.headers = headers
self.multiValueHeaders = multiValueHeaders
self.body = body
self.isBase64Encoded = isBase64Encoded
}
}
158 changes: 75 additions & 83 deletions Sources/AWSLambdaEvents/APIGateway+V2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,105 +12,97 @@
//
//===----------------------------------------------------------------------===//

extension APIGateway {
public struct V2 {}
}
/// APIGatewayV2Request contains data coming from the new HTTP API Gateway
public struct APIGatewayV2Request: Codable {
/// Context contains the information to identify the AWS account and resources invoking the Lambda function.
public struct Context: Codable {
public struct HTTP: Codable {
public let method: HTTPMethod
public let path: String
public let `protocol`: String
public let sourceIp: String
public let userAgent: String
}

extension APIGateway.V2 {
/// APIGateway.V2.Request contains data coming from the new HTTP API Gateway
public struct Request: Codable {
/// Context contains the information to identify the AWS account and resources invoking the Lambda function.
public struct Context: Codable {
public struct HTTP: Codable {
public let method: HTTPMethod
public let path: String
public let `protocol`: String
public let sourceIp: String
public let userAgent: String
/// Authorizer contains authorizer information for the request context.
public struct Authorizer: Codable {
/// JWT contains JWT authorizer information for the request context.
public struct JWT: Codable {
public let claims: [String: String]
public let scopes: [String]?
}

/// Authorizer contains authorizer information for the request context.
public struct Authorizer: Codable {
/// JWT contains JWT authorizer information for the request context.
public struct JWT: Codable {
public let claims: [String: String]
public let scopes: [String]?
}

public let jwt: JWT
}
public let jwt: JWT
}

public let accountId: String
public let apiId: String
public let domainName: String
public let domainPrefix: String
public let stage: String
public let requestId: String
public let accountId: String
public let apiId: String
public let domainName: String
public let domainPrefix: String
public let stage: String
public let requestId: String

public let http: HTTP
public let authorizer: Authorizer?
public let http: HTTP
public let authorizer: Authorizer?

/// The request time in format: 23/Apr/2020:11:08:18 +0000
public let time: String
public let timeEpoch: UInt64
}
/// The request time in format: 23/Apr/2020:11:08:18 +0000
public let time: String
public let timeEpoch: UInt64
}

public let version: String
public let routeKey: String
public let rawPath: String
public let rawQueryString: String
public let version: String
public let routeKey: String
public let rawPath: String
public let rawQueryString: String

public let cookies: [String]?
public let headers: HTTPHeaders
public let queryStringParameters: [String: String]?
public let pathParameters: [String: String]?
public let cookies: [String]?
public let headers: HTTPHeaders
public let queryStringParameters: [String: String]?
public let pathParameters: [String: String]?

public let context: Context
public let stageVariables: [String: String]?
public let context: Context
public let stageVariables: [String: String]?

public let body: String?
public let isBase64Encoded: Bool
public let body: String?
public let isBase64Encoded: Bool

enum CodingKeys: String, CodingKey {
case version
case routeKey
case rawPath
case rawQueryString
enum CodingKeys: String, CodingKey {
case version
case routeKey
case rawPath
case rawQueryString

case cookies
case headers
case queryStringParameters
case pathParameters
case cookies
case headers
case queryStringParameters
case pathParameters

case context = "requestContext"
case stageVariables
case context = "requestContext"
case stageVariables

case body
case isBase64Encoded
}
case body
case isBase64Encoded
}
}

extension APIGateway.V2 {
public struct Response: Codable {
public var statusCode: HTTPResponseStatus
public var headers: HTTPHeaders?
public var body: String?
public var isBase64Encoded: Bool?
public var cookies: [String]?

public init(
statusCode: HTTPResponseStatus,
headers: HTTPHeaders? = nil,
body: String? = nil,
isBase64Encoded: Bool? = nil,
cookies: [String]? = nil
) {
self.statusCode = statusCode
self.headers = headers
self.body = body
self.isBase64Encoded = isBase64Encoded
self.cookies = cookies
}
public struct APIGatewayV2Response: Codable {
public var statusCode: HTTPResponseStatus
public var headers: HTTPHeaders?
public var body: String?
public var isBase64Encoded: Bool?
public var cookies: [String]?

public init(
statusCode: HTTPResponseStatus,
headers: HTTPHeaders? = nil,
body: String? = nil,
isBase64Encoded: Bool? = nil,
cookies: [String]? = nil
) {
self.statusCode = statusCode
self.headers = headers
self.body = body
self.isBase64Encoded = isBase64Encoded
self.cookies = cookies
}
}
Loading