2
votes

Usecase

I have cloudformation stack which has around 25 lambda functions. Before deploying into production i need to test all the functions locally.

I know aws has SAM Cli to test serverless functions which has completely different syntax when compare to cloudformation lambdas.

Is there any possible tool from aws that solves my usecase ?

Because it gonna take quite a lot of time for converting cfn lambdas to sam syntax and also sam dont have that much options as cloudformation has.

Any help is appreciated Thanks

1
Are the handlers, rte and event triggers same for all the functions? You can always use aws console to test your lambda functions. medium.com/@reginald.johnson/…Sushant Sonker
@SushantSonker , yeah you are right we can use aws console always, but for testing over there we need to deploy the lambda functions. Where in SAM we dont deploy in aws but it is done in a docker container , i am asking is any that type of tool present for cloudformation lambdas.Private
From what I know, you have 2 options - 1. which you already refer to in your question (write serverless yaml) 2. same as @SushantSonkerasr9
@ASR You are right . Right now i am using Option 1. But hoping i may find a better option than that :)Private
@ASR for converting cloudformation lambdas to sam i am using lambda console export feature. SAM local is doing okay for now..Private

1 Answers

-1
votes

I know you have picked SAM cli to build your templates, but I would suggest you to move to Serverless (npm i serverless -g) as they are more advanced. Serverless is a framework which has been built by engineers and has no Cloud Provider attached/dependent to it, hence you would be able to easily switch from Azure to AWS from your template.

Because it is supported by a big dev community the framework has a variety of plugins, including serverless offline plugin which will allow you to run your API locally as if you were just running node index.js. There are also plugins like "serverless-jest" or "serverless-mocha" for unit tests, but I ended up using the normal "Jest" running integration test (I use cognito user pool and need to check the auth token).

If you really want to test your code of cloudformation architecture, you can have a JS file with your function and run it with node locally and instead of having the code in your cloudformation template, you will need to zip ip, upload on S3 and then inform the path on your template.

In summary, I know you asked how to test your SAM Serverless, but since you would like to have a proper development flow (local execution, unit test, pipeline, etc) switching to Serverless framework would be the solution. You can simulate the functions through node, but this will increase your manual management of something which a framework already does.