Skip to content
This repository was archived by the owner on Jul 14, 2020. It is now read-only.

Removed @_exported imports for LambdaEvents. #25

Closed
wants to merge 1 commit into from

Conversation

m-housh
Copy link

@m-housh m-housh commented Jan 15, 2020

This allows prevention of name clashes if import AWSSDKSwift along with LambdaRuntime. It requires explicit imports of the LambdaEvents package when using.

@fabianfett
Copy link
Owner

fabianfett commented Jan 15, 2020

Hi @m-housh, thanks so much for your contribution. Could you please add a small snippet as a comment here that makes the problem reproduceable for me?

If I can reproduce the problem, we should probably revert #22, because I don’t want users to have to import both libraries. The hassle isn’t worth it.

@m-housh
Copy link
Author

m-housh commented Jan 16, 2020

import DynamoDB
import NIO
import LambdaRuntime

func configureDynamoDB(group: EventLoopGroup, environment: Environment) -> DynamoDB {
    return DynamoDB(
         accessKeyId: environment.accessKeyId,
         secretAccessKey: environment.secretAccessKey,
         sessionToken: environment.sessionToken,
         region: Region(rawValue: environment.region),
         eventLoopGroupProvider: .shared(group)
    )
}

@m-housh
Copy link
Author

m-housh commented Jan 16, 2020

I haven't really explored the 0.4.0, so it may not be that big of an issue if I properly learned how to use the LambdaEvents, but new to Serverless and have been playing around with this runtime.

@fabianfett
Copy link
Owner

@m-housh I'm afraid your proposed solution doesn't really solve the problem at hand. Considering your code you solve the problem by putting LambdaEvents in a separate Library that needs to imported, and not importing this library in this code:

import DynamoDB
import NIO
import LambdaRuntime

func configureDynamoDB(group: EventLoopGroup, environment: Environment) -> DynamoDB {
    return DynamoDB(
         accessKeyId: environment.accessKeyId,
         secretAccessKey: environment.secretAccessKey,
         sessionToken: environment.sessionToken,
         region: Region(rawValue: environment.region),
         eventLoopGroupProvider: .shared(group)
    )
}

You would be back at the issue as soon as you imported LambdaEvents. For that reason, I dug deeper and created an issue that will solve the problem of not being able to access the namespace of LambdaRuntime (See #26). Also I opened an issue on aws-sdk-swift that faces the same problem (See soto-project/soto#218).

For the time being, I would advice you to not import LambdaRuntime and an AWSSDKSwift in the same package. For creating your DataStore you could use a pattern like this:

https://github.com/fabianfett/swift-lambda-runtime/blob/master/examples/TodoAPIGateway/Sources/TodoService/DynamoTodoStore.swift

Does that sound good to you?

@m-housh
Copy link
Author

m-housh commented Jan 16, 2020

I think renaming to have access to the LambdaRuntime.DynamoDB namespace will work well enough and hopefully AWSSDKSwift will follow suit. I was trying to not create a DynamoStore and handle that specific code inside the lambda as it seems the best practice is to keep them as small executables.

@m-housh m-housh closed this Jan 16, 2020
@fabianfett
Copy link
Owner

@m-housh Thanks for your understanding in the issue. But I can ensure you one thing:

I was trying to not create a DynamoStore and handle that specific code inside the lambda as it seems the best practice is to keep them as small executables.

The executables are linked statically and only contain what is needed to be executed (the swift compiler does take care of this). My lambdas rarely exceed 5mb in size zipped.

And thanks again for bringing up the issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants