0

I have a certain number of APIs which are being migrated to AWS. These APIs are based on Nest.js and for local development, I simply run the application which bootstraps a web server and I can invoke certain end points using swagger or Postman at localhost:3000.

Most of these functions are to be triggered by an event. While it is possible to migrate a Nest.js application to Lambda and bootstrap a webserver upon events, I do not like the idea of running a server in serverless function. I stripped down my functions by removing all the dependencies of Nest.js and made them a simple typescript application which gets invoked upon reception of certain events.

The way, I test this so far is using the console of API gateway or lambda console test events. Both of these approaches need the lambda function to be deployed which takes a significant amount of time because of the CI processes and PR approvals.

In my case, I do not need to simulate AWS environment. I have tried to use serverless offline plugin but the problem is my serverless.yml has references with existing resources on AWS and this reference cannot be resolved. Also I am creating some resources in serverless.yml like secrets and !Ref Secret would also not be resolved.

custom:
  infraStack: cfn-infra-lambda-${opt:stage}

provider:
  deploymentBucket:
    name: ${cf:${self:custom.infraStack}.ServerlessDeploymentBucket}

Also, I do not need to mock any AWS services. For instance, one of the services does the following

  • Take a CSV file as input, process it and update certain fields in DB
  • For my lambda function after deployment, it would connect to RDS
  • For my local testing, it would be enough for me to see my tables updated in a local DB (usually docker)

Removing Nest.js dependencies significantly cut down the deployment size but the ease of local testing had been a issue.

Ideal flow for me would be I can feed a CSV file to my function and it processes the file and updates the local docker based DB.

Is it possible to only invoke the function without trying to mock or resolve the whole infrastructure in serverless.yml either with serverless-offline plugin or any other way?

Parthiva
  • 254
  • 3
  • 21

1 Answers1

0

Perhaps experiment with AWS SAM and local invoke. You can invoke a single lambda or an entire API.

cyberwombat
  • 38,105
  • 35
  • 175
  • 251