-
Notifications
You must be signed in to change notification settings - Fork 118
Allow specifying port for local server #99
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
Conversation
|
Can one of the admins verify this patch? |
3 similar comments
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @eneko, for the proposed change. This is something that we should definitely support, since it will make local development much easier.
We do have a problem however: Just changing the port of the server where the lambda is invoked is not enough. The Lambda uses the same port for the local control plane. That's why we also need to instruct the lambda to look for the control plane at the new specified port.
We could do this by locally setting the AWS_LAMBDA_RUNTIME_API env variable. @tomerd wdyt?
|
thanks @eneko as @fabianfett points out changing the server is not enough, as we need to coordinate the configuration between the lambda (client) and the mock server. we chose to expose this woth an env variable that can be set in Xcode (scheme menu) or command line and is also how aws communicates the desired configuration.
|
|
Thanks for the feedback, @fabianfett & @tomerd. While having the environment variable is a great for a single lambda (both release and debug), it is not trivial when running multiple lambdas. The goal for this PR was to make this trivial, very easy todo. While Xcode schemes allow for defining environment variables for each scheme, this might be harder to achieve without using Xcode. For example, I'd like to do: How about replacing: With something like: let ipPort = env("AWS_LAMBDA_RUNTIME_API")?.split(separator: ":") ?? [DefaultIPPort.ip, DefaultIPPort.port]Then, somewhere accessible: // Somewhere accessible
struct DefaultIPPort {
static var ip: String = "127.0.0.1"
static var port: String = "7000"
}Usage would be: DefaultIPPort.port = "7001"
try Lambda.withLocalServer {
Lambda.run { (_, request: Request, callback) in
callback(.success(Response(message: "Hello, \(request.name)!")))
}
}Or like on the PR changes: try Lambda.withLocalServer(port: 7001) { // DefaultIPPort.port set to "7001" inside Lambda.withLocalServer
Lambda.run { (_, request: Request, callback) in
callback(.success(Response(message: "Hello, \(request.name)!")))
}
}Thoughts? |
|
hi @eneko, you can set an env variable on the terminal pretty easy: $ AWS_LAMBDA_RUNTIME_API="localhost:7001" swift run lambda1
$ AWS_LAMBDA_RUNTIME_API="localhost:7002" swift run lambda2should do the trick! |
|
Yep, I'm aware of that, is just not pretty, or trivial, nor have the desire to type it each time. If there is no interest on finding a better solution, I'll go ahead and close the PR, no worries. Thank you! |
Don't get me wrong here. I just wanted to ensure that you have a quick fix for the situation at hand. As I stated above, I think this is something that we should address. We just need to make sure that we find a good solution... And we should be able to support this going forward. As you may have seen in #83, we have some plans for the local server and we need to make sure that all stars align. |
Enhancements
Usage