So, I have deployed an app to lambda using serverless.
When I try to GET my lambda endpoint, this is all I get:
{
"message": "Internal server error"
}
In the console I got error 403 for the favicon, and 502 for the request.
These are my files:
serverless.ts
:
import type { AWS } from '@serverless/typescript';
import functions from './serverless/functions';
const serverlessConfiguration: AWS = {
service: 'lambda-ts',
frameworkVersion: '3',
plugins: ['serverless-esbuild'],
provider: {
name: 'aws',
runtime: 'nodejs14.x',
apiGateway: {
minimumCompressionSize: 1024,
shouldStartNameWithService: true
},
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
NODE_OPTIONS: '--enable-source-maps --stack-trace-limit=1000'
}
},
// import the function via paths
functions,
package: { individually: true },
custom: {
esbuild: {
bundle: true,
minify: false,
sourcemap: true,
exclude: ['aws-sdk'],
target: 'node14',
define: { 'require.resolve': undefined },
platform: 'node',
concurrency: 10
}
}
};
module.exports = serverlessConfiguration;
serverless/functions.ts
:
import { AWS } from '@serverless/typescript';
const functions: AWS['functions'] = {
example: {
handler: 'src/lambdas/example/index.handler',
events: [
{
http: {
method: 'get',
path: 'example',
cors: {
origin: '*'
}
}
}
]
}
};
export default functions;
And this is my src/lambdas/example/index.ts
:
import { APIGatewayProxyEvent, APIGatewayProxyHandler, APIGatewayProxyResult } from 'aws-lambda';
const handler: APIGatewayProxyHandler = async (
event: APIGatewayProxyEvent
): Promise<APIGatewayProxyResult> => {
try {
const { queryStringParameters } = event;
return {
statusCode: 200,
body: JSON.stringify({
queryStringParameters: JSON.stringify(queryStringParameters) || '{}'
})
};
} catch (e) {
return {
statusCode: 500,
body: JSON.stringify({
error: (e as Error).message
})
};
}
};
export default handler;
I hope someone can help me, I have just started learning lambda/serverless.