Skip to content

adjustments to sendable #13

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 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct APIGatewayProxyLambda: LambdaHandler {
typealias Event = APIGatewayV2Request
typealias Output = APIGatewayV2Response

init(context: Lambda.InitializationContext) async throws {}
init(context: LambdaInitializationContext) async throws {}

func handle(_ request: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response {
context.logger.debug("hello, api gateway!")
Expand Down
8 changes: 4 additions & 4 deletions Sources/AWSLambdaEvents/ALB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import class Foundation.JSONEncoder

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

Expand All @@ -44,12 +44,12 @@ public struct ALBTargetGroupRequest: Codable {
public let body: String?

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

public struct ALBTargetGroupResponse: Codable {
public struct ALBTargetGroupResponse: AWSLambdaEvent {
public var statusCode: HTTPResponseStatus
public var statusDescription: String?
public var headers: HTTPHeaders?
Expand Down
10 changes: 5 additions & 5 deletions Sources/AWSLambdaEvents/APIGateway+V2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
//===----------------------------------------------------------------------===//

/// APIGatewayV2Request contains data coming from the new HTTP API Gateway
public struct APIGatewayV2Request: Codable {
public struct APIGatewayV2Request: AWSLambdaEvent {
/// Context contains the information to identify the AWS account and resources invoking the Lambda function.
public struct Context: Codable {
public struct HTTP: Codable {
public struct Context: AWSLambdaEvent {
public struct HTTP: AWSLambdaEvent {
public let method: HTTPMethod
public let path: String
public let `protocol`: String
Expand All @@ -25,9 +25,9 @@ public struct APIGatewayV2Request: Codable {
}

/// Authorizer contains authorizer information for the request context.
public struct Authorizer: Codable {
public struct Authorizer: AWSLambdaEvent {
/// JWT contains JWT authorizer information for the request context.
public struct JWT: Codable {
public struct JWT: AWSLambdaEvent {
public let claims: [String: String]?
public let scopes: [String]?
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/AWSLambdaEvents/APIGateway.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import class Foundation.JSONEncoder
// https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html

/// APIGatewayRequest contains data coming from the API Gateway
public struct APIGatewayRequest: Codable {
public struct Context: Codable {
public struct Identity: Codable {
public struct APIGatewayRequest: AWSLambdaEvent {
public struct Context: AWSLambdaEvent {
public struct Identity: AWSLambdaEvent {
public let cognitoIdentityPoolId: String?

public let apiKey: String?
Expand Down
15 changes: 15 additions & 0 deletions Sources/AWSLambdaEvents/AWSLambdaEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftAWSLambdaRuntime open source project
//
// Copyright (c) 2022 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
//
//===----------------------------------------------------------------------===//

public protocol AWSLambdaEvent: Decodable, _AWSLambdaEventsSendable {}
2 changes: 1 addition & 1 deletion Sources/AWSLambdaEvents/AWSRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// $ aws ssm get-parameters-by-path --path /aws/service/global-infrastructure/services/lambda/regions --output json

/// Enumeration of the AWS Regions.
public struct AWSRegion: RawRepresentable, Equatable {
public struct AWSRegion: RawRepresentable, Equatable, _AWSLambdaEventsSendable {
public typealias RawValue = String

public let rawValue: String
Expand Down
24 changes: 7 additions & 17 deletions Sources/AWSLambdaEvents/AppSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
//===----------------------------------------------------------------------===//

// https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html
public struct AppSyncEvent: Decodable {
public struct AppSyncEvent: AWSLambdaEvent {
public let arguments: [String: ArgumentValue]

public enum ArgumentValue: Codable {
public enum ArgumentValue: AWSLambdaEvent {
case string(String)
case dictionary([String: String])

Expand Down Expand Up @@ -46,15 +46,15 @@ public struct AppSyncEvent: Decodable {
}

public let request: Request
public struct Request: Decodable {
public struct Request: AWSLambdaEvent {
let headers: HTTPHeaders
}

public let source: [String: String]?
public let stash: [String: String]?

public let info: Info
public struct Info: Codable {
public struct Info: AWSLambdaEvent {
public var selectionSetList: [String]
public var selectionSetGraphQL: String
public var parentTypeName: String
Expand All @@ -63,11 +63,11 @@ public struct AppSyncEvent: Decodable {
}

public let identity: Identity?
public enum Identity: Codable {
public enum Identity: AWSLambdaEvent {
case iam(IAMIdentity)
case cognitoUserPools(CognitoUserPoolIdentity)

public struct IAMIdentity: Codable {
public struct IAMIdentity: AWSLambdaEvent {
public let accountId: String
public let cognitoIdentityPoolId: String
public let cognitoIdentityId: String
Expand All @@ -78,7 +78,7 @@ public struct AppSyncEvent: Decodable {
public let cognitoIdentityAuthProvider: String
}

public struct CognitoUserPoolIdentity: Codable {
public struct CognitoUserPoolIdentity: AWSLambdaEvent {
public let defaultAuthStrategy: String
public let issuer: String
public let sourceIp: [String]
Expand Down Expand Up @@ -131,16 +131,6 @@ public struct AppSyncEvent: Decodable {
""")
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .iam(let iamIdentity):
try container.encode(iamIdentity)
case .cognitoUserPools(let cognitoUserPool):
try container.encode(cognitoUserPool)
}
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions Sources/AWSLambdaEvents/Cloudwatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.6)
@preconcurrency import struct Foundation.Date
#else
import struct Foundation.Date
#endif

/// EventBridge has the same events/notification types as CloudWatch
typealias EventBridgeEvent = CloudwatchEvent

public protocol CloudwatchDetail: Decodable {
public protocol CloudwatchDetail: AWSLambdaEvent {
static var name: String { get }
}

Expand All @@ -33,7 +37,7 @@ extension CloudwatchDetail {
/// https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html
/// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html
/// https://docs.aws.amazon.com/eventbridge/latest/userguide/event-types.html
public struct CloudwatchEvent<Detail: CloudwatchDetail>: Decodable {
public struct CloudwatchEvent<Detail: CloudwatchDetail>: AWSLambdaEvent {
public let id: String
public let source: String
public let accountId: String
Expand Down Expand Up @@ -89,7 +93,7 @@ public enum CloudwatchDetails {
public struct InstanceStateChangeNotification: CloudwatchDetail {
public static let name = "EC2 Instance State-change Notification"

public enum State: String, Codable {
public enum State: String, AWSLambdaEvent {
case running
case shuttingDown = "shutting-down"
case stopped
Expand All @@ -109,7 +113,7 @@ public enum CloudwatchDetails {
public struct SpotInstanceInterruptionNotice: CloudwatchDetail {
public static let name = "EC2 Spot Instance Interruption Warning"

public enum Action: String, Codable {
public enum Action: String, AWSLambdaEvent {
case hibernate
case stop
case terminate
Expand Down
22 changes: 13 additions & 9 deletions Sources/AWSLambdaEvents/DynamoDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,32 @@
//
//===----------------------------------------------------------------------===//

#if compiler(>=5.6)
@preconcurrency import struct Foundation.Date
#else
import struct Foundation.Date
#endif

// https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html
public struct DynamoDBEvent: Decodable {
public struct DynamoDBEvent: AWSLambdaEvent {
public let records: [EventRecord]

public enum CodingKeys: String, CodingKey {
case records = "Records"
}

public enum KeyType: String, Codable {
public enum KeyType: String, AWSLambdaEvent {
case hash = "HASH"
case range = "RANGE"
}

public enum OperationType: String, Codable {
public enum OperationType: String, AWSLambdaEvent {
case insert = "INSERT"
case modify = "MODIFY"
case remove = "REMOVE"
}

public enum SharedIteratorType: String, Codable {
public enum SharedIteratorType: String, AWSLambdaEvent {
case trimHorizon = "TRIM_HORIZON"
case latest = "LATEST"
case atSequenceNumber = "AT_SEQUENCE_NUMBER"
Expand All @@ -47,7 +51,7 @@ public struct DynamoDBEvent: Decodable {
case disabled = "DISABLED"
}

public enum StreamViewType: String, Codable {
public enum StreamViewType: String, AWSLambdaEvent {
/// the entire item, as it appeared after it was modified.
case newImage = "NEW_IMAGE"
/// the entire item, as it appeared before it was modified.
Expand All @@ -58,7 +62,7 @@ public struct DynamoDBEvent: Decodable {
case keysOnly = "KEYS_ONLY"
}

public struct EventRecord: Decodable {
public struct EventRecord: AWSLambdaEvent {
/// The region in which the GetRecords request was received.
public let awsRegion: AWSRegion

Expand Down Expand Up @@ -113,7 +117,7 @@ public struct DynamoDBEvent: Decodable {
}
}

public struct StreamRecord {
public struct StreamRecord: AWSLambdaEvent {
/// The approximate date and time when the stream record was created, in UNIX
/// epoch time (http://www.epochconverter.com/) format.
public let approximateCreationDateTime: Date?
Expand All @@ -138,7 +142,7 @@ public struct DynamoDBEvent: Decodable {
public let streamViewType: StreamViewType
}

public struct UserIdentity: Codable {
public struct UserIdentity: AWSLambdaEvent {
public let type: String
public let principalId: String
}
Expand Down Expand Up @@ -187,7 +191,7 @@ extension DynamoDBEvent.StreamRecord: Decodable {
// MARK: - AttributeValue -

extension DynamoDBEvent {
public enum AttributeValue {
public enum AttributeValue: AWSLambdaEvent {
case boolean(Bool)
case binary([UInt8])
case binarySet([[UInt8]])
Expand Down
14 changes: 7 additions & 7 deletions Sources/AWSLambdaEvents/S3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import struct Foundation.Date

// https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html

public struct S3Event: Decodable {
public struct Record: Decodable {
public struct S3Event: AWSLambdaEvent {
public struct Record: AWSLambdaEvent {
public let eventVersion: String
public let eventSource: String
public let awsRegion: AWSRegion
Expand All @@ -37,15 +37,15 @@ public struct S3Event: Decodable {
case records = "Records"
}

public struct RequestParameters: Codable, Equatable {
public struct RequestParameters: AWSLambdaEvent, Equatable {
public let sourceIPAddress: String
}

public struct UserIdentity: Codable, Equatable {
public struct UserIdentity: AWSLambdaEvent, Equatable {
public let principalId: String
}

public struct Entity: Codable {
public struct Entity: AWSLambdaEvent {
public let configurationId: String
public let schemaVersion: String
public let bucket: Bucket
Expand All @@ -59,13 +59,13 @@ public struct S3Event: Decodable {
}
}

public struct Bucket: Codable {
public struct Bucket: AWSLambdaEvent {
public let name: String
public let ownerIdentity: UserIdentity
public let arn: String
}

public struct Object: Codable {
public struct Object: AWSLambdaEvent {
public let key: String
/// The object's size in bytes.
///
Expand Down
Loading