Can I use sst to simply create a Lambda function, ...
# help
l
Can I use sst to simply create a Lambda function, e.g. one that I want to use in Lambda@Edge contexts? I found Frank's repo here - https://github.com/fwang/sst-edge-lambda-test/blob/main/lib/MyStack.js - which is where I got the code in my screenshot, but it's different from my case. I don't want to create a CF distribution at the same time. What I want is to create and manage several Lambda functions from my SST project that will be used in Lambda@Edge on various existing Cloudfront distributions, without creating them as API endpoints. (The screenshot here doesn't work btw - 'problem linting the source'.)
Ideally every time I update a function a new version of the Lambda will be published
The screenshot is completely wrong because I don't have the lambda import - I've added that now and trying to see if I can make this work I have figured that I need this.addOutputs here
Whoa, that's so cool! Think I got it working
f
Hey @Louis Barclay, currently
sst start
doesn’t support live debugging Lambda@Edge function, but other than that, what you described is doable.
l
That's OK - I'm going to set up my own testing stack for that
How would I do the same as I have here, but to manage multiple Lambda@Edge functions? Because I think that this whole stack will only output one function - I could be wrong though
I guess I could create some function to iterate over every file in the src/edge directory and then create a new EdgeFunction for each one - seems a bit over-the-top though. And not sure if it'll mean that new versions get created even for functions that haven't changed
Aha interesting - so this basically just takes the actual JS files that are in src/edge and sticks them in a Lambda - doesn't care about importing anything
f
yeah the code above just zips up the directory passed into
fromAsset
You’d need to create multiple of these functions, and add all of their Arns to the ouputs
l
Got it. And make sure the directories are set up with all imports right there
I guess maybe I should revert to trying to create Lambda functions a different way, more like the
new sst.Api
way. That is very handy because of how elegantly it packages up dependencies. It's just not suitable for Lambda@Edge because 1) by default it includes an environment variable 'AWS_NODEJS_CONNECTION_REUSE_ENABLED', which means it can't be used with Lambda@Edge (could be some way to prevent that though) 2) it creates the API which I don't need for those functions
I'll keep exploring
f
Functions created using
sst.Api
are not Edge functions. What you did is actually the only way to create a Edge Lambda.
Here’s an issue for Edge Lambda support https://github.com/serverless-stack/serverless-stack/issues/577
Let me know if this is the packaging becomes a blocker for you. I will bump up the priority on this.