I got a take home assessment in this job I applied. They are asking for a CI setup with aws lambda and to be honest I have never done that. I have referred to a dozen tutorials which do it like this but for me it isn’t working. Endpoints return internal server error. I don’t even know if the code has error or if the deploy process is not well setup.
this is the express code in bin/www, and it is the only file apart from a config file which has aws credentials. “main” in package.json is set to bin/www
const express = require('express');
const app = express();
const serverless = require('serverless-http');
const awsServerlessExpress = require('aws-serverless-express');
const port = process.env.PORT || 3000;
const cors = require('cors');
const {DynamoDBClient} = require('@aws-sdk/client-dynamodb');
const {PutCommand, DynamoDBDocumentClient} = require('@aws-sdk/lib-dynamodb');
const config = require('../config/AwsConfig');
app.use(cors());
app.get('/', (req, res) => {
res.status(200).json({message: 'Hello World!'});
});
module.exports = serverless(app);
And this is the github actions workflow
name: Deploy to AWS Lambda
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/[email protected]
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Package Lambda function
run: zip -r function.zip .
- name: Deploy to AWS Lambda
uses: appleboy/[email protected]
with:
function_name: intelebee-backend
zip_file: function.zip
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Deploy completes with no error, the files get copied properly. I have tried both the lambda’s url and api gateway’s url, both return internal server error. not sure if I’m using the serverless library properly.