-
Notifications
You must be signed in to change notification settings - Fork 113
Add apigateway and alb #52
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
85568a9
Added ALB and APIGateway Events
fabianfett 3984576
Removed all high level stuff.
fabianfett 59e9d8b
MultiValueHeaders and Headers tyealias
fabianfett cf2bc9a
Added APIGateway V2
fabianfett 029c8df
Merge branch 'master' into add-apigateway-and-alb
tomerd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftAWSLambdaRuntime open source project | ||
// | ||
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
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 | ||
} | ||
|
||
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 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 let statusCode: HTTPResponseStatus | ||
public let statusDescription: String? | ||
public let headers: HTTPHeaders? | ||
public let multiValueHeaders: HTTPMultiValueHeaders? | ||
public let body: String | ||
public let 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 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftAWSLambdaRuntime open source project | ||
// | ||
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
extension APIGateway { | ||
public struct V2 {} | ||
} | ||
|
||
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]? | ||
} | ||
|
||
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 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 | ||
} | ||
|
||
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 context: Context | ||
public let stageVariables: [String: String]? | ||
|
||
public let body: String? | ||
public let isBase64Encoded: Bool | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case version | ||
case routeKey | ||
case rawPath | ||
case rawQueryString | ||
|
||
case cookies | ||
case headers | ||
case queryStringParameters | ||
case pathParameters | ||
|
||
case context = "requestContext" | ||
case stageVariables | ||
|
||
case body | ||
case isBase64Encoded | ||
} | ||
} | ||
} | ||
|
||
extension APIGateway.V2 { | ||
public struct Response: Codable { | ||
public let statusCode: HTTPResponseStatus | ||
public let headers: HTTPHeaders? | ||
public let multiValueHeaders: HTTPMultiValueHeaders? | ||
public let body: String? | ||
public let isBase64Encoded: Bool? | ||
public let cookies: [String]? | ||
|
||
public init( | ||
statusCode: HTTPResponseStatus, | ||
headers: HTTPHeaders? = nil, | ||
multiValueHeaders: HTTPMultiValueHeaders? = nil, | ||
body: String? = nil, | ||
isBase64Encoded: Bool? = nil, | ||
cookies: [String]? = nil | ||
) { | ||
self.statusCode = statusCode | ||
self.headers = headers | ||
self.multiValueHeaders = multiValueHeaders | ||
self.body = body | ||
self.isBase64Encoded = isBase64Encoded | ||
self.cookies = cookies | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftAWSLambdaRuntime open source project | ||
// | ||
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import class Foundation.JSONEncoder | ||
|
||
// https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html | ||
|
||
public enum APIGateway { | ||
/// APIGatewayRequest contains data coming from the API Gateway | ||
public struct Request: Codable { | ||
public struct Context: Codable { | ||
public struct Identity: Codable { | ||
public let cognitoIdentityPoolId: String? | ||
|
||
public let apiKey: String? | ||
public let userArn: String? | ||
public let cognitoAuthenticationType: String? | ||
public let caller: String? | ||
public let userAgent: String? | ||
public let user: String? | ||
|
||
public let cognitoAuthenticationProvider: String? | ||
public let sourceIp: String? | ||
public let accountId: String? | ||
} | ||
|
||
public let resourceId: String | ||
public let apiId: String | ||
public let resourcePath: String | ||
public let httpMethod: String | ||
public let requestId: String | ||
public let accountId: String | ||
public let stage: String | ||
|
||
public let identity: Identity | ||
public let extendedRequestId: String? | ||
public let path: String | ||
} | ||
|
||
public let resource: String | ||
public let path: String | ||
public let httpMethod: HTTPMethod | ||
|
||
public let queryStringParameters: [String: String]? | ||
public let multiValueQueryStringParameters: [String: [String]]? | ||
public let headers: HTTPHeaders | ||
public let multiValueHeaders: HTTPMultiValueHeaders | ||
public let pathParameters: [String: String]? | ||
public let stageVariables: [String: String]? | ||
|
||
public let requestContext: Context | ||
public let body: String? | ||
public let isBase64Encoded: Bool | ||
} | ||
} | ||
|
||
// MARK: - Response - | ||
|
||
extension APIGateway { | ||
public struct Response: Codable { | ||
public let statusCode: HTTPResponseStatus | ||
public let headers: HTTPHeaders? | ||
public let multiValueHeaders: HTTPMultiValueHeaders? | ||
public let body: String? | ||
public let isBase64Encoded: Bool? | ||
|
||
public init( | ||
statusCode: HTTPResponseStatus, | ||
headers: HTTPHeaders? = nil, | ||
multiValueHeaders: HTTPMultiValueHeaders? = nil, | ||
body: String? = nil, | ||
isBase64Encoded: Bool? = nil | ||
) { | ||
self.statusCode = statusCode | ||
self.headers = headers | ||
self.multiValueHeaders = multiValueHeaders | ||
self.body = body | ||
self.isBase64Encoded = isBase64Encoded | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you know about API Gateway's v2 integration with lambda? https://aws.amazon.com/blogs/compute/building-better-apis-http-apis-now-generally-available/
By default, it's request/response shape is different, and requires a configuration to be compatible with the "1.0" shape you've got here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomerd let me see what I can do to get this to work today. Since v2 already is GA, there might be a chance for us never to support v1. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomerd Okay I added the API Gateway v2 syntax, which in my opinion is much nicer. I've already tried it with my own lambda quite extensively. Works great and the v2 syntax is much easier to use, if you ask me.