Lambda works locally but not when deployed

0 votes

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 enter image description here

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!

Feb 16 in AWS by Ashwini
• 3,750 points
71 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In AWS

+1 vote
10 answers
+2 votes
3 answers
+3 votes
3 answers
+1 vote
3 answers

Not able to pass params POST to AWS Lambda from Amazon API Gateway

For this template : application/x-www-form-urlencoded  This line below will ...READ MORE

answered Jun 13, 2018 in AWS by Cloud gunner
• 4,660 points
7,637 views
+1 vote
1 answer

Redirect working from www.xyz.com to https://xyz.com but not from https://www.xyz.com

Make sure you have created the certificate ...READ MORE

answered Aug 28, 2018 in AWS by Priyaj
• 58,100 points
1,144 views
0 votes
1 answer

Why amazon cognito authorizer works just as authenticator not as an authorizer?

Because it is an authenticator. Naming it as ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,100 points
257 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP