Build, Zip, Update a .NET Core 3.1 AWS Lambda, and Run a Test, with a Single Command

I’ve been working on a Lambda that has required a lot of trial and error, running unit tests locally was not good enough because my problem was around how serialization worked up AWS. I am working on a few blogs about this.

I was repeatedly building the code in VS Code, using Total Commander to zip the files, then moving to the AWS UI to upload the zip, and finally hit test.

Here is a simple batch file that does it all, save it to a file called UploadAndTest.bat -

dotnet build 
rm .\bin\Debug\netcoreapp3.1\
7za.exe a .\bin\Debug\netcoreapp3.1\ .\bin\Debug\netcoreapp3.1\*
aws lambda invoke --function-name ApiCaller  --cli-binary-format raw-in-base64-out --payload %2 response.json 

I run it by calling -

UploadAndTest.bat ApiCaller '"{ \"Uri\": \"\" }"'

If you don’t have 7Zip installed see here - Zipping Files From the Command Line in Windows 10

comments powered by Disqus