I'm using serverless framework and my endpoint work locally with sls offline, but when I sls deploy it to AWS I get 502 Bad Gateway in postman
and if I go to AWS Lambda console and click test event to see what comes up I get
{
"errorType": "Runtime.UserCodeSyntaxError",
"errorMessage": "SyntaxError: Unexpected token '??='",
"trace": [
"Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '??='",
" at _loadUserApp (/var/runtime/UserFunction.js:222:13)",
" at Object.module.exports.load (/var/runtime/UserFunction.js:300:17)",
" at Object.<anonymous> (/var/runtime/index.js:43:34)",
" at Module._compile (internal/modules/cjs/loader.js:1085:14)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
" at Module.load (internal/modules/cjs/loader.js:950:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
" at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)",
" at internal/main/run_main_module.js:17:47"
]
}
There's nothing in my code that has ??=' in it so I made my endpoint super simple as a process of elimination and returned a response instantly ie
router.get('/my-api', async (req, res: Response) => {
return res.status(200).json({"message": "success"});
});
but I still get the same error. serverless.yaml
service: my-service
plugins:
- serverless-webpack
- serverless-offline
custom:
env:
default: Sandbox
prod: Production
AWS_REGION: us-east-1
apigwBinary:
types: #list of mime-types
- '*/*'
contentCompression: 14000
webpack:
webpackConfig: ./webpack.config.js
packager: 'npm'
includeModules:
forceExclude:
- aws-sdk
- dotenv
provider:
name: aws
versionFunctions: false
region: ${opt:region, 'us-east-1'}
stage: ${opt:stage, 'staging'}
environment:
STAGE: ${self:provider.stage}
functions:
myApi:
handler: src/handler.service
events:
- http:
path: route/my-api
method: GET
cors: true
handler.ts
import { APIGatewayProxyEvent, Context, ProxyResult } from 'aws-lambda';
import awsServerlessExpress from 'aws-serverless-express';
import app from './app';
const server = awsServerlessExpress.createServer(app);
export function service(event: APIGatewayProxyEvent, context: Context) {
return awsServerlessExpress.proxy(server, event, context);
}
So as a recap, it works locally, but not after sls deploy in AWS in postman or aws console lambda test event. So if it works locally, why isn't it working in aws. I appreciate any help!