GitHub Actions and a C# AWS Lambda

GitHub Actions and a C# AWS Lambda


| October 5, 2021 | in

GitHub is the standard for online source control. It was really the first platform many of us knew about for the hosting of git in the cloud, and we have all used it at some point. At Don’t Panic Labs, we have been using Azure Dev Ops more than GitHub during the last few years.

Periodically, I like to dive into other technologies and see where they are at. This led me to deploy an AWS Lambda using a GitHub action – just to see if I could do it. Previously, I had only used GitHub actions for the deployment of some Firebase work I had done. And in that situation, the GitHub action was already created for me.

But I wanted to create a GitHub action to deploy an AWS Lambda. AWS Lambda is a great way to host an ASP.NET Web API backend, and I have written a blog post about how to build and deploy Lambdas using Azure DevOps.

GitHub actions are a lot like Azure DevOps Pipelines in that you can use them to automate build processes and release code. They both are configured using YAML files, but the structure of these files is different.

Creating a GitHub action is pretty straightforward. Go to the Actions tab and click “New workflow”.

All workflows

GitHub will analyze your code and make suggestions on which workflows are potential options. In my case, I just want to start with the .NET template.

.NET template

The .NET template has many things in place. But for this situation, I really want to focus on deploying a Lambda application.

To support building a .NET Core application to a Lambda, I had to make a few changes.

First, I wanted it to run in a different working directory. This is easy, as you simply change the working directory.

The next change was installing the Amazon Lambda tools. This requires adding another step to our script.

With the AWS tools Installed, we can now build and deploy our C# Lambda.

But if we make the changes above and run our script, it won’t work. Why? Because we need to provide a user key and secret for one of our AWS users. They can be provided as environment variables.

These variables need to be stored in the secrets associated with your GitHub project.

Actions secrets

When we push our code to the “main” branch, it will push the latest build to AWS Lambda. This automates that process so no human has to push the builds manually.

Here’s the script.

Related posts