Skip to content

[core] user can create multiple instances of the Lambda Runtime #507

Open
@sebsto

Description

@sebsto

Now that user controls the main function with the runtime v2, nothing prevents users to create multiple runtimes.

I tested the code below on Lambda and it works. Any of the two runtimes can pickup the invocation and respond. In my exemple, they're booth taking the same input parameter and there is not too much consequences. But if the user codes the two handler with different input types, the Lambda function will crash when the "incorrect" runtime picks up the event.

We should enforce the runtime as a singleton.

demo code

import AWSLambdaRuntime

let runtime1 = LambdaRuntime {
    (event: String, context: LambdaContext) in
    "Hello1 \(event)"
}

let runtime2 = LambdaRuntime {
    (event: String, context: LambdaContext) in
    "Hello2 \(event)"
}

try await withThrowingTaskGroup(of: Void.self) { group in
    group.addTask {
        try await runtime1.run()
    }
    group.addTask {
        try await runtime2.run()
    }

    try await group.waitForAll()
}

Metadata

Metadata

Assignees

Labels

kind/bugFeature doesn't work as expected.🆕 semver/minorAdds new public API.

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions