Git Product home page Git Product logo

Comments (12)

nickspell avatar nickspell commented on May 29, 2024 10

An alternative solution to the static file packaging problem is to use AWS Lambda Layers.
Just put your static files into some directory at the root of your project and create a layer from that.

Example:

myservice
├── static
│   ├── foo.json
├── src
├── serverless.yml

In your serverless.yml insert:

layers:
  mydata:
    path: static
    description: My static json data

In your function you can put the dependency on your layer as a title cased reference:

functions:
  myfunction:
    handler: #...
    layers: 
       - {Ref: MydataLambdaLayer}
     # .....

You can now access your files as if they are located in the "/opt" folder of your lambda, e.g.:

let file = File::open("/opt/foo.json")?;

This solution is quite useful especially when you want to share your static data between different lambdas.

from serverless-rust.

softprops avatar softprops commented on May 29, 2024 2

Without more expertise in opencv I cant gaurantee this will work but to answer the question about using layers to package host dependencies, that's almost the sole use of layers https://aws.amazon.com/blogs/aws/new-for-aws-lambda-use-any-programming-language-and-share-common-components/

That said this is likely an easier case for interpreted languages im not sure if you can package and dynamically link via env var with rust. I glanced through the opencv docs and there was some suggestions that you could

from serverless-rust.

softprops avatar softprops commented on May 29, 2024 1

This looks a bit involved but possibly doable. A lambda layer might be a useful approach here. Heres an example from the python world of setting up a layer https://www.bigendiandata.com/2019-04-15-OpenCV_AWS_Lambda/

I'm not familiar with the opencv project enough myself to know why there might not be an off the shelf layer available https://github.com/mthenw/awesome-layers

from serverless-rust.

softprops avatar softprops commented on May 29, 2024

That's a good point. I've deferred in adding features until they are needed or asked for. I'll look into this

from serverless-rust.

nosideeffects avatar nosideeffects commented on May 29, 2024

I was under the impression that this was already supported. How would I add this capability myself for my current serverless project?

from serverless-rust.

cecton avatar cecton commented on May 29, 2024

I think we could use the "include" attribute of a function and "add" the files to the zip after the build in the container succeeded.

from serverless-rust.

vim-zz avatar vim-zz commented on May 29, 2024

Adding another use case, which requires having a certificate file to communicate with a certain server.

from serverless-rust.

sachaarbonel avatar sachaarbonel commented on May 29, 2024

I just wanted to point out that the workaround of @nickspell doesnt work for my use case which is opening a sqlite db. For some reason I'm getting a SqliteError "attempt to write a readonly database". I guess the /opt folder is read only. EDIT : nevermind I copied the file to the /tmp folder (which is the only writable folder in aws lambda) and it did the trick.

from serverless-rust.

softprops avatar softprops commented on May 29, 2024

I think the most appropriate way to approach this is the suggestion original mentioned. Use the built in include / exclude packaging options.

from serverless-rust.

kahlil29 avatar kahlil29 commented on May 29, 2024

@softprops Could you tell me if it would be possible to use a rust program that has an OpenCV dependency?
I'm currently using this crate
Any thoughts about this? I'm guessing I need to introduce the opencv files (statically linked?) into the Lambda somehow?

from serverless-rust.

kahlil29 avatar kahlil29 commented on May 29, 2024

Thanks for the informative and helpful reply @softprops
I had tried earlier (not using Layers) but could not get it working.
I guess it's time to give Lambda Layers a go.
So in your experience, it's common/acceptable to use Lambda Layers to package in dependencies for Lambdas? It's known to work without (many) issues?

from serverless-rust.

kahlil29 avatar kahlil29 commented on May 29, 2024

Thanks a lot @softprops
Appreciate the answer and info 😄

from serverless-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.