Git Product home page Git Product logo

swift-aws-lambda-events's People

Contributors

adam-fowler avatar andrea-scuderi avatar buratti avatar fabianfett avatar hiimtmac avatar idelfonsog2 avatar jbosecker avatar joannis avatar jsonfry avatar mahdibm avatar mattmassicotte avatar maxdesiatov avatar mplew-is avatar mr-j-tree avatar mufumade avatar normanmaurer avatar pmarrufo avatar pokryfka avatar proggeramlug avatar renatoaguimaraes avatar richwolf avatar ro-m avatar sebsto avatar sliemeobn avatar stefannienhuis avatar tachyonics avatar tomerd avatar tonychol avatar weissi avatar yim-lee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-aws-lambda-events's Issues

better representation for numeric sqs-message-attributes

This issue is a carry over from the Lambda runtime project
swift-server/swift-aws-lambda-runtime#53


https://github.com/swift-server/swift-aws-lambda-runtime/pull/46/files#diff-46c15e7ad33f3c55f1eff630cb7c7d6aR30

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-attributes.html under "Message Attribute Data Types"

Number attributes can store positive or negative numerical values. A number can have up to 38 digits of precision, and it can be between 10^-128 and 10^+126.

right now using string as a stop gap, could use Foundation's Decimal or come up with our own BigNumber abstraction

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)

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

Unable to use APIGatewayV2Request with Lambda authorizer

Expected behavior

Ability to process context from a Lambda authorizer in APIGatewayV2Request

Actual behavior

Fails trying to deserialize jwt from the Authorizer struct which isn't present for Lambda authorizers, from CloudWatch logs:

warning Lambda : lifecycleIteration=0 [AWSLambdaRuntimeCore] lambda handler returned an error: requestDecoding(Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "jwt", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "requestContext", intValue: nil), CodingKeys(stringValue: "authorizer", intValue: nil)], debugDescription: "No value associated with key CodingKeys(stringValue: \"jwt\", intValue: nil) (\"jwt\").", underlyingError: nil)))

Also, would be nice to have structs for Lambda authorizer payloads

Steps to reproduce

  1. Create API Gateway (HTTP API)
  2. Create route in gateway and attach both Lambda authorizer (not JWT authorizer) and integration
  3. Call the route

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

Looks like

needs to be made optional (guessing this will be a breaking change because of Swift's type safety when compiling)

SwiftAWSLambdaRuntime version/commit hash

3ac078f4d8fe6d9ae8dd05b680a284a423e1578d

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

swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0
Darwin 192.168.1.121 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 arm64

APIGatewayV2Request doesn't support AWS_IAM authorizers

Expected behavior

APIGatwewayV2Request should support iam authorizers.

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

Actual behavior

Fail to decode to JSON

Steps to reproduce

  1. Create a Lambda Function + hook it up to an API Gateway with IAM authorization enabled.

Here is a SAM snippet

Resources:
  # Lambda function
  MyLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Events:
        # pass through all HTTP verbs and paths
        Api:
          Type: HttpApi
          Properties:
            Auth:
              Authorizer: AWS_IAM            
    Metadata:
      BuildMethod: makefile

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

Here is the payload received that fails to decode :

{
    "version": "2.0",
    "routeKey": "$default",
    "rawPath": "/liveness",
    "rawQueryString": "",
    "headers": {
        "accept": "*/*",
        "authorization": "AWS4-HMAC-SHA256 Credential=ASIA-redacted/us-east-1/execute-api/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=289b5fcef3d1156f019cc1140cb5565cc052880a5a0d5586c753e3e3c75556f9",
        "content-length": "0",
        "host": "74bxj8iqjc.execute-api.us-east-1.amazonaws.com",
        "user-agent": "curl/8.4.0",
        "x-amz-date": "20231214T203121Z",
        "x-amz-security-token": "IQoJb3JpZ2luX2VjEO3//////////-redacted",
        "x-amzn-trace-id": "Root=1-657b6619-3222de40051925dd66e1fd72",
        "x-forwarded-for": "191.95.150.52",
        "x-forwarded-port": "443",
        "x-forwarded-proto": "https"
    },
    "requestContext": {
        "accountId": "012345678912",
        "apiId": "74bxj8iqjc",
        "authorizer": {
            "iam": {
                "accessKey": "ASIA-redacted",
                "accountId": "486652066693",
                "callerId": "AIDA-redacted",
                "cognitoIdentity": null,
                "principalOrgId": "aws:PrincipalOrgID",
                "userArn": "arn:aws:iam::012345678912:user/sst",
                "userId": "AIDA-redacted"
            }
        },
        "domainName": "74bxj8iqjc.execute-api.us-east-1.amazonaws.com",
        "domainPrefix": "74bxj8iqjc",
        "http": {
            "method": "GET",
            "path": "/liveness",
            "protocol": "HTTP/1.1",
            "sourceIp": "191.95.150.52",
            "userAgent": "curl/8.4.0"
        },
        "requestId": "P8zkDiQ8oAMEJsQ=",
        "routeKey": "$default",
        "stage": "$default",
        "time": "14/Dec/2023:20:31:21 +0000",
        "timeEpoch": 1702585881671
    },
    "isBase64Encoded": false
}

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

AWSLambdaEvents.AppSync.Event incorrect

Expected behavior

I am using swift as a appsync lambda resolver with the following GraphQL schema.

input TestInput {
  ids: [String]
}

testMutation(input: TestInput!): String

According to the GraphQL Documentation arrays are allowed. So a correct JSON Decode should happen.

Actual behavior

By setting the message to type of AWSLambdaEvents.AppSync.Event leads to a Unexpected AppSync argument. Expected a String or a Dictionary. error.

Steps to reproduce

{
    "field": "testMutation",
    "arguments": {
        "input": {
            "ids": [
                "id1",
                "id2"
            ]
        }
    }
}

This is a the json payload I get from appsync.

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

Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)
Target: x86_64-apple-darwin20.4.0
Darwin xx-MacBook-Pro.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

Allow APIGatewayV2Request to created for testing

Expected behavior

I'm trying to test a LambdaHandler

struct MyHandler: LambdaHandler {

    init(context: LambdaInitializationContext) async throws { }

    func handle(_ request: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response {
        ...
    }

}

using Lambda.test(MyHandler.self, with: <APIGatewayV2Request>)

but I can't create an APIGatewayV2Request to test with because init isn't public.

Actual behavior

I would expect to be able to create an APIGatewayV2Request via init or some convenience method so that I can write tests for my LambdaHandler.

Steps to reproduce

  1. Create a LambdaHandler whose Event is of type APIGatewayV2Request
  2. Attempt to write a test using Lambda.test from the AWSLambdaTesting library.

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

Handler

import AWSLambdaEvents
import AWSLambdaRuntime
import Foundation

struct MyHandler: LambdaHandler {

    init(context: LambdaInitializationContext) async throws { }

    func handle(_ request: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response {
        let response = APIGatewayV2Response(statusCode: .ok, body: "Hello World!")
        return response
    }

}

Test

import AWSLambdaEvents
import AWSLambdaRuntime
import AWSLambdaTesting
@testable import <MyLambda Target>
import XCTest

final class MyHandlerTests: XCTestCase {

    func testOKResponse() async throws {
        let request = APIGatewayV2Request() // Can't create this

        let response = try await Lambda.test(MyHandler.self, with: request)

        XCTAssertEqual(response.statusCode, .ok)
    }

}

SwiftAWSLambdaRuntime version/commit hash

1.0.0-alpha.2

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

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
Darwin xxx.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020 arm64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.