I had a simple Serverless website running in AWS lambda using node serverless deploy
, I then added more stuff to the site and updated to the latest version of serverless, now when I deploy the site and visit the URL I get:
{"message": "Internal server error"}
When I visit the lambda console I get:
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module './dist/server'",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module './dist/server'",
" at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
" at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
" at Object.<anonymous> (/var/runtime/index.js:45:30)",
" at Module._compile (internal/modules/cjs/loader.js:778:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)",
" at Module.load (internal/modules/cjs/loader.js:653:32)",
" at tryModuleLoad (internal/modules/cjs/loader.js:593:12)",
" at Function.Module._load (internal/modules/cjs/loader.js:585:3)",
" at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)",
" at startup (internal/bootstrap/node.js:283:19)"
]
}
Any idea how to fix this?
More Info
Based on @Amit Baranes comment below which references this SO post here is a Angular site. I don't quite understand what I need to change the handler name to to match my site structure. I am not bundling the files into a .zip myself, but am running the serverless deploy
command through node:
Here is the website serverless.yml
# generated by @ng-toolkit/serverless
service: serverless-site
plugins:
- serverless-apigw-binary
provider:
name: aws
runtime: nodejs10.x
memorySize: 192
timeout: 10
stage: production
region: us-east-1
package:
exclude:
- src/**
- node_modules/**
- firebug-lite/**
- e2e/**
- coverage/**
- '!node_modules/aws-serverless-express/**'
- '!node_modules/binary-case/**'
- '!node_modules/type-is/**'
- '!node_modules/media-typer/**'
- '!node_modules/mime-types/**'
- '!node_modules/mime-db/**'
custom:
apigwBinary:
types:
- '*/*'
functions:
api:
handler: lambda.universal
events:
- http: ANY {proxy+}
- http: ANY /
Here is my project file structure (starting inside the src directory) for the website.
Here is the website lambda function when it is deployed:
Since the function didn't have a server.js. I attempted to create is by modifying server.ts and putting it in the folder with no luck:
// generated by Paul
//import 'zone.js/dist/zone-node';
//import 'reflect-metadata';
var express =require('express');
var cors= require('cors');
var compression =require('compression');
var join=require('path').join;
export const app = express();
app.use(compression());
app.use(cors());
const DIST_FOLDER = join(process.cwd(), 'dist/serverless-site');
app.get('*.*', express.static(join(DIST_FOLDER), {
maxAge: '1y'
}));
app.get('/*', (req, res) => {
res.sendFile(join(DIST_FOLDER + '/index.html'));
});