Comments (12)
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.
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.
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.
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.
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.
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.
Adding another use case, which requires having a certificate file to communicate with a certain server.
from serverless-rust.
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.
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.
@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.
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.
Thanks a lot @softprops
Appreciate the answer and info 😄
from serverless-rust.
Related Issues (20)
- MacOs dockerless: fork/exec /var/task/bootstrap: permission denied HOT 2
- Custom variables not expanding HOT 1
- Is this project still being developed?
- Release new NPM package version HOT 5
- File permissions in local build (macOS) HOT 2
- as_slice Error
- What's the differences between this and `cargo-lambda`? HOT 1
- Plugin creates a lot of files with root owner
- Support the Lambda ARM target HOT 3
- Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap] Runtime.InvalidEntrypoint
- Failing to build on Windows WSL2 with docker image
- page typo x86_unknown-linux-musl
- Where should I add "dockerless: true" HOT 1
- Support sccache
- Local invokes with dockerless: true fail with permission error
- Musl issue with Diesel HOT 1
- Use Cross for docker builds HOT 1
- Latest npm release inconsistent with latest docker image
- Error: fork/exec /var/task/bootstrap: no such file or directory
- lambda-rust docker image based of al2 whereas the plugin BASE_RUNTIME is al HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-rust.