Howdy! I’m new on SST, coming from Serverless Fram...
# guide
j
Howdy! I’m new on SST, coming from Serverless Framework and now considering if I should go with SST or pure CDK. One thing I’m wondering about is how SST sees the difference of monolith lambdas vs microservice? I couldn’t find any comments on it in the documentation. My aim is to primarily code in python. So if I wanna deploy say 5 different functions, is there a nice structure on how to manage this to get separate requirements.txt files for them etc? Or am I overocmplicating things.
I guess I could just split each lambda into it’s own stack to get this separation?
ping @Frank
Background for the design question is something like. https://docs.aws.amazon.com/lambda/latest/operatorguide/monolith.html
f
Hey @Jan Nylund, Welcome! SST at its core does two things: 1. high level constructs on top of CDK for common patterns (ie. Apis, Sites, Cron job, etc), so ur code is likely to be a lot more concise 2. Live Lambda dev - a local environment allowing u to iterate on ur lambda code quickly It’s up to u how to structure ur Lambdas monolith vs microservice. That’s outside the concern of SST.
how to manage this to get separate requirements.txt
Imagine u r creating an Api, u can structure ur functions like this:
Copy code
/
  sst.json
  stack/
    ApiStack.ts
  backend/
    function1/
      requirements.txt
      handler.py
    function2/
      requirements.txt
      handler.py
    ...
And in ur ApiStack, u can do
Copy code
new Api(stack, "Api", {
  routes: {
    "GET /route1": {
      srcPath: "backend/function1",
      handler: "handler.main",
    },
    "GET /route2": {
      srcPath: "backend/function2",
      handler: "handler.main",
    },
    ...
  },
});
Let me know if that makes sense.
j
Thanks, yeah, sounds reasonable.
What about having an api stack and also a cron call to one endpoint, is that possible? 🤔
Seems there is no defaults available for
new Cron
stack, so how do I pass in a reference ot a dynamodb table that is to be populated by a cron job?
ping @Frank again 🙈
My google-fu gave me this which seems to be exactly what I’m trying to do. https://github.com/serverless-stack/serverless-stack/issues/1779
ok, found out how to do it. works like this.
Copy code
const cron = new Cron(stack, "Cron", {
        schedule: "rate(1 minute)",
        job: {
            function: {
                permissions: [table],
                environment: {
                    TABLE_NAME: table.tableName,
                },
                handler: "main.handler"
            }
        }
    });
Ok, next issue. How do I easily and quickly define an apikey for a “kickstart” endpoint. I can of coruse do it in code, but would be nicer to just use the apigateway.