Skip to content

Conversation

@pokryfka
Copy link
Contributor

@pokryfka pokryfka commented Jul 2, 2020

Motivation:

Allow user to configure LocalLambda.Server to create invocations:

  • mocking different AWS services (for example API Gateway)
  • with custom events (for example AppSync events) or
  • implementing specific use cases (for example injecting Authorization header/logic).

Modifications:

This picks up and updates #83

  • The LocalLambda.Server opens two ports:
    • one to mock HTTP API for lambda custom runtimes - ControlPlaneHandler
    • one to create new invocations - InvokeHandler
  • The ServerState (TODO: rename) encapsulates all the "business" logic
    • queueing incoming requests
    • forwarding them to lambda handler
    • forwarding response from lambda handler back to the InvokeHandler which created them
  • user can provide custom implementation of LocalLambdaInvocationProxy, defaults to InvokeProxy (current behavior)

the main difference from #83 is bootstrap and separation of ProxyType from ServerState;
ServerState provides API to queue new invocations and promises to fulfill them but it has no interest how they were created and what is going to happen with the result

Result:

Allows to setup LocalLambda providing custom implementation of LocalLambdaInvocationProxy, InvokeProxy by default.

#if DEBUG
LocalLambda.bootstrap(InvokeProxy.self)
#endif

Lambda.run(APIGatewayProxyLambda())

If the change is approved I can create APIGatewayV2Proxy in AWSLambdaEvents which could be used to bootstrap LocalLambda:

#if DEBUG
LocalLambda.bootstrap(APIGatewayV2Proxy.self)
#endif

Lambda.run(APIGatewayProxyLambda())

@swift-server-bot
Copy link

Can one of the admins verify this patch?

3 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@pokryfka
Copy link
Contributor Author

pokryfka commented Jul 2, 2020

I missed #83 which defines LocalLambdaInvocationProxy and implements InvokeProxy.

@tomerd
Copy link
Contributor

tomerd commented Jul 6, 2020

@pokryfka should we pursue this further in the context of #83?

Comment on lines +48 to +57
public protocol LocalLambdaInvocationProxy {
init(eventLoop: EventLoop)

// TODO: in most (all?) cases we do not need async interface

/// throws `LocalLambda.InvocationError` if request is invalid
func invocation(from request: LocalLambda.HTTPRequest) -> EventLoopFuture<ByteBuffer>
func processResult(_ result: ByteBuffer?) -> EventLoopFuture<LocalLambda.HTTPResponse>
func processError(_ error: ByteBuffer?) -> EventLoopFuture<LocalLambda.HTTPResponse>
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in most cases there is no need for async calls.

In a typical scenario a HTTP request would be used to create new HTTP request with different payload.

Async interface would be useful in a fairly exotic scenario (as far as local testing/development is concerned); for example, if the LocalLambdaInvocationProxy was connecting with external server to set valid Authorization header.

Comment on lines +301 to +302
// TODO: do we need a circular buffer? there is only (up to) one request at a time
private var pending = CircularBuffer<(head: HTTPRequestHead, body: ByteBuffer?)>()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a circular buffer? there is only (up to) one request at a time

@pokryfka
Copy link
Contributor Author

@tomerd @fabianfett please let me know your thoughts on this, a few comments/questions inline (above)

@tomerd
Copy link
Contributor

tomerd commented Oct 5, 2020

hi @parkera if you want to keep this around, could you please update this PR to be against the main branch so we can delete the old master branch

@tomerd tomerd closed this Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants