Closed darylteo closed 4 months ago
Hello @darylteo Are you thinking about a SwiftPM plugin to would generate a Serverless deployment descriptor ? Or a serverless plugin to scaffold a Swift project and its associate resources.
I am currently working on a SPM plugin that generates a SAM deployment descriptor. That work / approach could be extended to Serverless too.
Have a look at this PR (https://github.com/swift-server/swift-aws-lambda-runtime/pull/291) and let me know what you think.
Hello @darylteo @sebsto,
I've prepared an example of the output required with Serverless using Breeze
the library I'm developing: https://github.com/swift-sprinter/Breeze/tree/main/Example.
Using Breeze
it's very easy to create a Serverless business logic for APIGateway, Lambda, Dynamo. The difficult part is to help users in the deployment.
That code has been generated by a command line, but it's still in development.
Not sure what could be the best approach: 1 - Have a SPM plugin, but it's not clear how to add additional resources (DynamoDB, ....) 2 - Use a dedicate command line 3 - Have a Plugin in Serverless
Maybe we need all the approaches, happy to contribute.
@Andrea-Scuderi the approach I used for SAM is to let the function developer describe its environment in Swift (like a SwiftUI struct) and generate the YAML based on that.
Example :
import AWSLambdaDeploymentDescriptor
DeploymentDescriptor {
// a mandatory description
"Description of this deployment descriptor"
// the lambda function
Function(name: "HttpApiLambda") {
EventSources {
HttpApi(method: .GET, path: "/test") // example of an API for a specific HTTP verb and path
}
// optional environment variables
EnvironmentVariables {
[ "NAME1": "VALUE1" ]
}
}
}
The same file could be generated for SAM or Serverless. It can have DynamoDB, IAM Policies, SQS queues ... The long part is to write the Swift struct that models all SAM/Serverless constructs.
@sebsto @darylteo
Here the dedicated command line I've prepared for 💨Breeze
https://github.com/swift-sprinter/Breeze/pull/6
The command line relies on a new library I've prepared to load serverless.yml. https://github.com/swift-sprinter/swift-sls-adapter.git
Once the solution [1] is ready, I can add the plugin for Serverless
Happy to get suggestions, comments and contributions.
Are you thinking about a SwiftPM plugin to would generate a Serverless deployment descriptor ? Or a serverless plugin to scaffold a Swift project and its associate resources.
@sebsto sorry I meant a ServerlessFramework plugin. I want to use SLS to do my deployments.
@Andrea-Scuderi Ah I think this is coming from the opposite direction of what I was thinking of. My use case is to use Swift in a mish mash of other runtimes using ServerlessFramework(SLS), so it's imperative that I work in SLS.
As you can see here, https://github.com/serverless/serverless/issues/11840#issuecomment-1481239403 I made a local plugin in SLS for starting a offline server so I can invoke commands into it. There are some minor inconveniences (can't proxy invoke through sls invoke local
, but it works for now.
Sorry for the confusion!
Closing as there is a proposed SLS plugin on the SLS project.
I've opened up an issue here to cross-discuss.
https://github.com/serverless/serverless/issues/11840
It would be awesome if we could support Swift directly in the Serverless Framework as it will handily scaffold the rest of an API infrastructure such as API Gateway, API Authentication etc. , and other nice plugins such as DynamoDB plugin. Personally I'm interested in allowing cross-functional teams to collaborate with each other on the same codebase.
This would probably entail building an officially supported plugin that wraps around SwiftPM.