How do you test your serverless application (AWS)

Hi Guys!

I’m beginning my journey with serverless applications so I wonder how do you (more experienced or production-experienced guys) locally develop and test your applications.

  1. How do you develop / run your application locally - are you using AWS SAM, Serverless-offline plugin, serverless-localstack, localstack directly or you just have an environment in AWS (and do a lot of sls deploy function)?

Reason why I ask is that for testing those solutions it looks like:

  • AWS SAM and Serverless-ofline are good only for lambdas and API GW.
  • I can’t get serverless-localstack to work for more than a day and it somewhat looks like not very stable at this point,
  • Localstack needs some routines in your production code to say it that you want to run on your localstack and not AWS
  • AWS requires being online all the time and thinking about separation (just basing on naming schema of resources or separate AWS account?)
  1. How do you integration test your application? Do you use localstack or things like moto/boto in Python (or equivalent in NodeJS)?

Thanks in advance for your replies!

1 Like

We use the serverless offline application and also run dynamodb locally. It works surprisingly well. We also rely much on unit tests to prove that our Lambdas work as expected. We use mocking (in python) to mock specific parts of the code so that our unit tests can be run locally.

For integration tests, we don’t run them in the code pipeline (GitLab CI/CD) because we don’t have dynamodb installed there (but we might arrange that later), we only run unit tests in the pipeline. But locally we also run integration tests that actually connect to DynamoDB locally.

Actually it works even better than I expected…

Thanks for reply!

I tried to dig the topic a bit further and this post is a result of it (might be useful for someone):

@montao I wonder, you mention that it works “better than I expected” or “surprisingly well”. Do you mean the serverless-offline or the dynamodb local instance? Can you elaborate a bit on it?

Thanks in advance!

Yes: Since there is no official “development server” for Serverless Framework I did not expect the sls offline to work very well but it did. So we can write and run both unit tests and integration tests locally and in our GitLab code pipeline.

I thought that the environment of AWS Lambda was too complex to reproduce locally and that a community effort could not do it. But it works! And it is a big difference for trying out small changes locally instead of the alternative of deploying and debugging the Lambda functions in the AWS cloud.