Swift implementation of AWS Lambda Events

Overview

Swift AWS Lambda Events

Overview

Swift AWS Lambda Runtime was designed to make building Lambda functions in Swift simple and safe. The library is an implementation of the AWS Lambda Runtime API and uses an embedded asynchronous HTTP Client based on SwiftNIO that is fine-tuned for performance in the AWS Runtime context. The library provides a multi-tier API that allows building a range of Lambda functions: From quick and simple closures to complex, performance-sensitive event handlers.

Swift AWS Lambda Events is a supporting library for the Swift AWS Lambda Runtime library, providing abstractions for popular AWS events.

Integration with AWS Platform Events

AWS Lambda functions can be invoked directly from the AWS Lambda console UI, AWS Lambda API, AWS SDKs, AWS CLI, and AWS toolkits. More commonly, they are invoked as a reaction to an events coming from the AWS platform. To make it easier to integrate with AWS platform events, this library includes an AWSLambdaEvents target which provides abstractions for many commonly used events. Additional events can be easily modeled when needed following the same patterns set by AWSLambdaEvents. Integration points with the AWS Platform include:

Note: Each one of the integration points mentioned above includes a set of Codable structs that mirror AWS' data model for these APIs.

Getting started

If you have never used AWS Lambda or Docker before, check out this getting started guide which helps you with every step from zero to a running Lambda.

Swift AWS Lambda Events is a supporting library for the Swift AWS Lambda Runtime library, where you can find further documentation and examples.

Project status

This is the beginning of a community-driven open-source project actively seeking contributions. While the core API is considered stable, the API may still evolve as we get closer to a 1.0 version. There are several areas which need additional attention, including but not limited to:

  • Additional events
  • Additional documentation and best practices
  • Additional examples

Security

Please see SECURITY.md for details on the security process.

Comments
  • feat(cloudformation): request and response models for custom resources

    feat(cloudformation): request and response models for custom resources

    Mapping Request and Response of CustomResource used by Type: AWS::Lambda::Function.

    Motivation:

    Avoid to write repeated code for every Swift Lambda Function where is used a CustomResource to pass properties. Inspired on event.go and response.go from https://github.com/aws/aws-lambda-go.git.

    Modifications:

    Added two new structs: Request and Response for Lambda event triggered by CloudFormation.

    Result:

    New models to be shared between Swift Lambda Functions that use CustomResource.

    opened by renatoaguimaraes 17
  • feature: Create LambdaProxyEvent Type

    feature: Create LambdaProxyEvent Type

    Create LambdaProxyEvent

    previous PR with original template https://github.com/swift-server/swift-aws-lambda-events/pull/16

    Motivation:

    I was getting Decoding errors when invoking my lambda using APIGateway Event Request. I looked at the AWS Documentation and Serverless documentation and notice a different object from what is currently in the package

    Modifications:

    Edit a couple of the properties in the APIGatewayV2Request

    Result:

    My lambda is able to receive the Event from APIGateway along with the body I included in my http request

    opened by idelfonsog2 12
  • Add support for bare Lambda function URLs

    Add support for bare Lambda function URLs

    Add request and response object models for invoking Lambda function URLs.

    Motivation:

    Instead of having to spin up (and pay for) API Gateway endpoints, Lambdas can spin up bare URLs for public access. There are no existing request or response objects for these requests like there are for other event types.

    Modifications:

    These payloads are very similar (but not identical to) API Gateway V1 requests, so this is mostly just forked from that and tested until it works with simple requests. Note that I have only tested completely public endpoints, and cannot speak for the accuracy of the Authorizer sub-type.

    Result:

    After this change, users will be able to write:

    struct FunctionURLHandler: LambdaHandler {
    	typealias Event  = FunctionURLRequest
    	typealias Output = FunctionURLResponse
    
    	func handle(_ event: Event, context: LambdaContext) async throws -> Output {
    		...
    	}
    }
    

    and then be able to simply invoke their Lambdas without API Gateway:

    curl https://abcd1234.lambda-url.{region}.on.aws
    
    opened by MPLew-is 10
  • chore: Edit APIGatewayV2Request per

    chore: Edit APIGatewayV2Request per "LAMBDA-PROXY" event

    Edit a couple of the properties in the APIGatewayV2Request

    Motivation:

    I was getting Decoding errors when invoking my lambda using APIGateway Event Request. I looked at the AWS Documentation and Serverless documentation and notice a different object from what is currently in the package

    Modifications:

    Edit a couple of the properties in the APIGatewayV2Request

    Result:

    My lambda is able to receive the Event from APIGateway along with the body I included in my http request

    opened by idelfonsog2 9
  • Add `domainName` property to API Gateway V1 event

    Add `domainName` property to API Gateway V1 event

    Add support for the existing domainName property to API Gateway V1 events in Swift.

    Motivation:

    According to AWS example events and documentation, this seems to be included in all requests. We should be able to access this seamlessly in Swift.

    Modifications:

    • Added domainName property to requestContext in APIGatewayRequest object
    • Added example values for domainName to corresponding tests

    Result:

    After this change, users can access the domain name with:

    struct ApiGatewayHandler: LambdaHandler {
    	typealias Event  = APIGatewayRequest
    	typealias Output = APIGatewayResponse
    
    	func handle(_ event: Event, context: LambdaContext) async throws -> Output {
    		...
    		let domainName: String = event.domainName
    		...
    	}
    }
    
    opened by MPLew-is 8
  • feat(cloudformation): make properties public

    feat(cloudformation): make properties public

    Make properties of CloudFormation templates public to be accessed by other modules that import the AWSLambdaEvents module.

    Motivation:

    The properties of CloudFormation templates (request and response) have the default internal access, making it impossible for other modules to use them.

    Modifications:

    Add public access level to properties.

    Result:

    The properties will be visible by other modules.

    opened by renatoaguimaraes 7
  • Make APIGatewayV2Request authorizer claims optional

    Make APIGatewayV2Request authorizer claims optional

    Make APIGatewayV2Request authorizer claims optional.

    Motivation:

    The current non-optional claims property is not compatible with the Lambda Runtime Interface Emulator.

    Aside from this, the AWS Docs specify a null value in this example: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format

    Modifications:

    Make APIGatewayV2Request authorizer claims optional.

    Result:

    APIGatewayV2Request authorizer claims is optional, allowing a nil value so that the Lambda Runtime Interface Emulator works with this library and so it's in accordance with the AWS docs.

    opened by StefanNienhuis 7
  • Expose Authorizer claims

    Expose Authorizer claims

    Expose Authorizer claims

    Motivation:

    Currecnt version doesn't expose Cognito signed user details

    Modifications:

    Added an option field, that doesnt break existing code

    Result:

    APIGateway.Request.requestContext.authorizer? is now available

    opened by audente 6
  • Updated incorrect sns event fields to match correct format

    Updated incorrect sns event fields to match correct format

    Updated incorrect sns event fields to match correct format

    Motivation:

    Issue: #25

    Modifications:

    Updated incorrect sns event fields to match correct format. Correct format can be seen here

    Result:

    Correct parsing of a SNS Event

    opened by mufumade 5
  • Fix event namespacing problems

    Fix event namespacing problems

    Motivation

    We have potential name clashes with existing AWS libraries, if we namespace our events under the service name. For example S3.Event. This problem has been documented here: https://github.com/swift-server/swift-aws-lambda-runtime/issues/119

    Changes

    This PR picks up the fix, that was initially intended to land in the runtime repo directly: https://github.com/swift-server/swift-aws-lambda-runtime/pull/203

    Result:

    No more namespace issues with AWS libraries.

    opened by fabianfett 3
  • adjustments to sendable

    adjustments to sendable

    motivation: events may be used in an async context and as such musct conform to Sendable

    changes:

    • define common abstraction for Sendable & Codable
    • conform all events Sendable
    opened by tomerd 1
  • Initial cognito trigger support

    Initial cognito trigger support

    Support for one Cognito Lambda Trigger (PreSignUp_SignUp), with infrastructure to support all 20 others.

    Motivation:

    I've been playing around with implementing WebAuthn (passkeys) using only Swift. It turned out to be complex, because Cognito doesn't support it yet, and requires the use of 3/4 lambda triggers.

    Modifications:

    Added a basic Cognito trigger enum that should be able to model all 21 lambda trigger types. Made some tests for the single trigger I've currently actually used.

    Result:

    Cognito triggers are a little funny in that they all have a common shape, but differ in some ways depending on the type. And, because there are so many (21 as of right now), I didn't want to create a bunch of duplicate structs. So, I opted for a enum that stores the trigger-specific data.

    I think this change is potentially useful, even though it is far from a complete implementation. I figured I'd propose it in PR form just to see what you all think. Happy to entertain suggestions!

    opened by mattmassicotte 6
  • Issue parsing SNS Event

    Issue parsing SNS Event

    Expected behavior

    Correct parsing using JSONDecoder().decode(SNS.Message.self, from: data)

    Actual behavior

    Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"SigningCertUrl\", intValue: nil) (\"SigningCertUrl\").", underlyingError: nil))

    SigningCertUrl and SubscribeUrl will result in parsing error

    Steps to reproduce

    1. Create a Lambda and parse a SNS Event.

    SNS Message Structure

    SwiftAWSLambdaRuntime version/commit hash

    main branch

    Swift & OS version (output of swift --version && uname -a)

    swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)

    opened by mufumade 0
  • Issue parsing APIGateway Event

    Issue parsing APIGateway Event

    Expected behavior

    Expected my lambda to return a APIGatewayV2Response along with my body

    Actual behavior

    Found the following in the CloudWatch Logs

    2022-04-25T15:40:54+0000 warning Lambda : lifecycleIteration=1 lambda handler returned an error: requestDecoding(Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "version", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"version\", intValue: nil) (\"version\").", underlyingError: nil)))
    
    

    Steps to reproduce

    1. Use the Deployment Lambda found in the Examples dir and deployed to AWS using APIGateway with a Lambda_PROXY
    2. make an HTTP call to your APIGateway
    3. Observe the errors in the CloudWatch Log

    If possible, minimal yet complete reproducer code (or URL to code)

    serverless.yml

    service: helloworld-swift-aws
    
    provider:
        name: aws
        runtime: provided
        region: us-east-2
        
    package:
        artifact: .build/lambda/HelloWorld/lambda.zip
    
    functions:
        hello:
            handler: HelloWorld
            memorySize: 128
            events:
              - http:
                  method: ANY
                  path: /{proxy+}
                  cors: true
    

    SwiftAWSLambdaRuntime version/commit hash

    main branch

    Swift & OS version (output of swift --version && uname -a)

    Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8) MacOS Monterrey 12.3.1

    opened by idelfonsog2 1
  • Update SNS.swift

    Update SNS.swift

    Received SNS object has uppercased "URL" coding keys.

    Motivation:

    The received SNS object has uppercased "URL" coding keys. The object can not be decoded otherwise. Currently, the coding keys contain a lower case "Url", for example "SigningCertUrl" but should be "SigningCertURL".

    {
      "Timestamp": "2021-10-08T11:18:40.043Z",
      "SigningCertURL": "https://sns.eu ****",
      "MessageId": "776e6308-8c44-5ee ****",
      "Type": "Notification",
      "SignatureVersion": "1",
      "Signature": "s71McLg8d9OP86E4a *****",
      "TopicArn": "arn:aws:sns:eu-west-1:06 *****",
      "UnsubscribeURL": "https://sns.eu-w****",
      "Message": "{\"action\":\"upload_document_version\",\"entityId\":\"1633691914791-1796da229943***aace80d5e023f3***c\",\"entityType\":\"DocumentVersion\",\"organizationId\":\"d-9367073c36\",\"parentEntityId\":\"516d7ab0537aff5d39a469439c*****2d0d4\",\"parentEntityType\":\"Document\"}"
    }
    

    Modifications:

    The coding keys string value has been changed.

    Result:

    We can now use the decoded object with dot notation.

    opened by WayneEld 7
  • Missing git tags.

    Missing git tags.

    Expected behavior

    Package is correctly installed.

    Actual behavior

    error: Dependencies could not be resolved because no versions of 'swift-aws-lambda-events' match the requirement 0.1.0..<1.0.0 and root depends on 'swift-aws-lambda-events' 0.1.0..<1.0.0.
    

    There are no appropriate git tags on the repository.

    Steps to reproduce

    1. Add as dependency to Package.swift
    2. Attempt install/build/etc.

    If possible, minimal yet complete reproducer code (or URL to code)

    SwiftAWSLambdaRuntime version/commit hash

    Swift & OS version (output of swift --version && uname -a)

    Apple Swift version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57). Darwin breathwork.local 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64

    opened by justinmcp 2
Owner
Swift on Server
Swift on Server
Swift AWS Lambda to automatically assign engineers to pull requests with a Slack integration

PR Assigner A Swift AWS Lambda to automatically assign engineers to pull requests with a Slack integration. Features ??

Just Eat 28 Oct 18, 2022
ResponderChain is a library that passes events using the responder chain.

ResponderChain ResponderChain is a library that passes events using the responder chain.

GodL 21 Aug 11, 2021
Hammer is a touch, stylus and keyboard synthesis library for emulating user interaction events

Hammer is a touch, stylus and keyboard synthesis library for emulating user interaction events. It enables better ways of triggering UI actions in unit tests, replicating a real world environment as much as possible.

Lyft 626 Dec 23, 2022
iOS Logs, Events, And Plist Parser

iLEAPP iOS Logs, Events, And Plists Parser Details in blog post here: https://abrignoni.blogspot.com/2019/12/ileapp-ios-logs-events-and-properties.htm

Brigs 421 Jan 5, 2023
Implementation of x-callback-url (Inter app communication) in swift

CallbackURLKit - Inter app communication Starting to integrate URL scheme in an app, why not be compliant with x-callback-url. CallbackURLKit.register

Eric Marchand 318 Nov 14, 2022
Swift implementation of the package url spec

PackageURL Swift implementation of the package url specification. Requirements Swift 5.3+ Usage import PackageURL let purl: PackageURL = "pkg:swift/a

Mattt 21 Jun 14, 2022
SwiftRedux is a Swift implementation of the Redux state container

SwiftRedux is a Swift implementation of the Redux state container. It relies on the same concepts and provides familiar Hooks through property wrappers.

Lucas Lima 8 Feb 1, 2022
Swift implementation of the QOI Format

Swift-QOI Swift implementation of the QOI Format. Contains extensions for AppKit and UIKit to integrate into your projects with ease. Documentation //

Amy While 18 Oct 21, 2022
Swift implementation of the QOI Format

Swift-QOI Swift implementation of the QOI Format. Contains extensions for AppKit and UIKit to integrate into your projects with ease. Documentation //

Amy While 1 Dec 9, 2021
The sample implementation of zip-archived document for a macOS AppKit platform.

The sample implementation of zip-archived document for a macOS AppKit platform. You can implement NSDocument-based I/O of archived document in your application like .sketch or .key.

usagimaru 4 Nov 12, 2022
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Apple 2k Dec 28, 2022
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Swift - ✏️Swift 공부 저장소✏️

Swift 스위프트의 기초 1. Swift의 기본 2. 변수와 상수 [3. 데이터 타입 기본] [4. 데이터 타입 고급] 5. 연산자 6. 흐름 제어 7. 함수 8. 옵셔널 객체지향 프로그래밍과 스위프트 9. 구조체와 클래스 10. 프로퍼티와 메서드 11. 인스턴스 생

Jiwon 0 Mar 9, 2022
Swift-ndi - Swift wrapper around NewTek's NDI SDK

swift-ndi Swift wrapper around NewTek's NDI SDK. Make sure you extracted latest

Alessio Nossa 12 Dec 29, 2022
__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

Tatsuya Hirose 86 Jun 29, 2022
SNTabBarDemo-Swift - Cool TabBar With Swift

SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu

iAnchor 3 Sep 29, 2022
Swift-when - Expression switch support in Swift

Swift When - supporting switch expressions in Swift! What is it? Basically, it a

Gordan Glavaš 7 Nov 24, 2022