AWS Lambda deployment not serving files from public/_nuxt folder
See original GitHub issueEnvironment
- Operating System:
Darwin
- Node Version:
v14.19.0
- Nuxt Version:
3.0.0-27447229.20f3171
- Package Manager:
yarn@1.22.17
- Bundler:
Vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
- Create a new project using
npx nuxi init nuxt3-app
- Install the necessary dependencies
- Build using the nitro lambda preset (
export NITRO_PRESET=lambda
) - Create a AWS Lambda function with the build output files
- Connect API Gateway with the Lambda function
Describe the bug
The deployed function will not serve anything from the /_nuxt
path. Either it will return the default welcome page or the 404 error page if you setup pages.
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:20 (3 by maintainers)
Top Results From Across the Web
Troubleshoot deployment issues in Lambda
The Lambda runtime needs permission to read the files in your deployment package. ... Error: fork/exec /var/task/function: no such file or directory.
Read more >Troubleshoot Lambda deployment package upload errors
When I try to upload my AWS Lambda deployment package, I get either a permission ... Confirm which file or folder is the...
Read more >Lambda deployment packages - AWS Documentation
Use a deployment package to deploy your Lambda function code. Lambda supports two types of deployment packages: container images and .zip file archives....
Read more >Configuring file system access for Lambda functions
Configure your Lambda function to access a file system such as an Amazon EFS file system.
Read more >Best practices for working with AWS Lambda functions
Reduce the time it takes Lambda to unpack deployment packages authored in Java by putting your dependency .jar files in a separate /lib...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We faced the same issue today and after many hours looking for the culprit, we found that the ‘aws-lambda’ nitro preset does not support serving static files. This is probably by design, because AWS API Gateway does not support serving binary files by default, as far as I know.
We propose two fixes:
One fix is very simple, just need to extend the ‘aws-lambda’ preset in
nuxt.config.js
enabling theserveStatic
option.Then, if using API Gateway, you’ll likely have to enable binary file serving. Our project is build using Serverless Framework, so we just used serverless-apigw-binary plugin.
We found this option by digging into the source code of the ‘node-server’ preset. You can also find the preset definition for ‘aws-lambda’ in case you want to define your own ‘aws-lambda-static’ or something.
If you don’t include this option, Nitro will not include a handler for static file routes, which will be handled by regular Vue Router handler. Which is the reason you get 404 (it is not that the server can’t find the files).
A (maybe better) second solution is to not serve static files through lambda, because it’s slower and more expensive compared to dedicated static file serving such a CDN. What you do in this case is to not include the
serveStatic: true
config and define your cndUrl innuxt.config.js
:cndUrl
was previously known aspublicPath
in Nuxt 2In this case, you have to upload the content of
.output/public/
intohttps://your-static-host.com/
. When using Serverless Framework, this would mean a manual process, but you could also automate it with serverless-finch (S3 Bucket) or serverless-lift (S3 + CloudFront Distribution) 👍🏻👍🏻👍🏻We found the documentation lacking with regards to serving static files through lambda and Nitro config, so if any of this information is of help, we’d be happy to add it to the docs 🙂
Yes, I’ll have to look into that but I do see a lot of advantages using SST. It’s still relatively new for me, am used to Docker. However this seems like a logical next step for me