'aws lambda function with dockerized node.js express app not working - "message: Internal Error"
I'm pretty new to AWS Lambda, and can't seem to get a dockerized Node.JS express app to work correctly. Here are the steps I took:
- Deployed my Docker image to AWS ECR. This worked correctly and I can see my images in ECR.
- Created a Lambda Function in AWS Lambda and used my container image for the function.
- Created a trigger for the Lambda function using API Gateway (HTTP), which gave me an endpoint URL that I assumed would be the host for my express endpoints.
When I hit that endpoint, I get a "message: Internal Error". Am I going about this totally wrong? Here's some code snippets. (very new to AWS in general)
Dockerfile
# Dockerfile
FROM node:16-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5001
CMD [ "npm", "run", "docker:start" ]
Express endpoint
// Creates a school in the db
schoolApi.post("/create", async (req: Request, res: Response) => {
try {
const {
id,
gradeDistribution,
name,
logo,
rateMyProfessorId,
totalSections,
averageGPA,
totalStudents,
}: {
id: string;
gradeDistribution: GradeDistributionObject;
name: string;
logo: string;
rateMyProfessorId: number;
totalSections: number;
averageGPA: number;
totalStudents: number;
} = req.body;
const gradeDistributionEntity = await createGradeDistribution(
db,
gradeDistribution,
averageGPA,
totalStudents
);
const school = await createSchool(
db,
id,
gradeDistributionEntity,
name,
logo,
rateMyProfessorId,
totalSections,
averageGPA,
totalStudents
);
res.status(200).send(school);
} catch (error) {
res.status(500).send(SchoolErrorCodes.SCHOOL_CREATION_ERROR);
}
});
Sample endpoint format that I'm hitting
https://xxxxxx.execute-api.us-west-2.amazonaws.com/default/myFunction/school/create
Response for above endpoint
{
"message": "Internal Server Error"
}
CloudWatch Logs when I click Test in AWS Lambda Console
2022-04-05T12:20:45.015-07:00 > [email protected] docker:start
2022-04-05T12:20:45.015-07:00 > concurrently "tsc -w" "nodemon src/index.ts"
2022-04-05T12:20:47.706-07:00 [0] c7:20:47 PM - Starting compilation in watch mode...
2022-04-05T12:20:47.706-07:00 [0]
2022-04-05T12:20:47.751-07:00 [1] [33m[nodemon] 2.0.15[39m
2022-04-05T12:20:47.752-07:00 [1] [33m[nodemon] to restart at any time, enter `rs`[39m
2022-04-05T12:20:47.753-07:00 [1] [33m[nodemon] watching path(s): *.*[39m
2022-04-05T12:20:47.753-07:00 [1] [33m[nodemon] watching extensions: ts,json[39m
2022-04-05T12:20:47.754-07:00 [1] [32m[nodemon] starting `ts-node src/index.ts`[39m
2022-04-05T12:20:49.541-07:00 START RequestId: 8eeeffa3-86ee-4a6f-8c12-cc61bdaa0b66 Version: $LATEST
2022-04-05T12:20:52.552-07:00 END RequestId: 8eeeffa3-86ee-4a6f-8c12-cc61bdaa0b66
2022-04-05T12:20:52.552-07:00 REPORT RequestId: 8eeeffa3-86ee-4a6f-8c12-cc61bdaa0b66 Duration: 3009.12 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 56 MB
2022-04-05T12:20:52.552-07:00 2022-04-05T19:20:52.551Z 8eeeffa3-86ee-4a6f-8c12-cc61bdaa0b66 Task timed out after 3.01 seconds
2022-04-05T12:20:53.130-07:00 > [email protected] docker:start
2022-04-05T12:20:53.130-07:00 > concurrently "tsc -w" "nodemon src/index.ts"
2022-04-05T12:20:53.872-07:00 [1] [33m[nodemon] 2.0.15[39m
2022-04-05T12:20:53.873-07:00 [1] [33m[nodemon] to restart at any time, enter `rs`[39m
2022-04-05T12:20:53.873-07:00 [1] [33m[nodemon] watching path(s): *.*[39m
2022-04-05T12:20:53.873-07:00 [1] [33m[nodemon] watching extensions: ts,json[39m
2022-04-05T12:20:53.873-07:00 [1] [32m[nodemon] starting `ts-node src/index.ts`[39m
2022-04-05T12:20:54.129-07:00 [0] c7:20:54 PM - Starting compilation in watch mode...
2022-04-05T12:20:54.129-07:00 [0]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
