Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What’s the best way to deploy multiple lambda functions from a single github repo onto AWS?

I have a single repository that hosts my lambda functions on github. I would like to be able to deploy the new versions whenever new logic is pushed to master.

I did a lot of reasearch and found a few different approaches, but nothing really clear. Would like to know what others feel would be the best way to go about this, and maybe some detail (if possible) into how that pipeline is setup.

Thanks

like image 968
Saad Siddiqui Avatar asked Mar 14 '19 14:03

Saad Siddiqui


People also ask

What are the three different ways you can deploy your code to Lambda?

Summary. There are three common ways to edit Lambda functions: in the Lambda console, Cloud 9, and locally. There are advantages and disadvantages of all three methods, but personally I think the best choice is to write the function locally and deploy it using a deployment script.

Can AWS Lambda have multiple functions?

You can have multiple functions in a single class. It's just that you have to set the required function as a handler for a particular API gateway on AWS which you are using it for the lambda function that you created.

How do I deploy a GitHub code to AWS Lambda?

You can use GitHub actions to set up automatic deployment for AWS Lambda from a Github repository. You need to push a commit to the main or master branch of your repository, then let GitHub actions create the deployment package, and deploy your code to AWS Lambda.


2 Answers

Welcome to StackOverflow. You can improve your question by reading this page.

You can setup a CI/CD pipeline using CircleCI with its GitHub integration (which is an online Service, so you don't need to maintain anything, like a Jenkins server, for example)

Upon every commit to your repository, a CircleCI build will be triggered. Once the build process is over, you can declare sls deploy, sam deploy, use Terraform or even create a script to upload the .zip file from your GitHub repo to an S3 Bucket and then, within your script, invoke the create-function command. There's an example how to deploy Serverless applications using CircleCI along with the Serverless Framework here

Other options include TravisCI, AWS Code Deploy or even maintain your own CI/CD Server. The same logic applies to all of these tools though: commit -> build -> deploy (using one of the tools you've chosen).

EDIT: After @Matt's answer, it clicked that the OP never mentioned the Serverless Framework (I, somehow, thought he was already using it, so I pointed the OP to tutorials using the Serverless Framework already). I then decided to update my answer with a few other options for serverless deployment

like image 109
Thales Minussi Avatar answered Oct 03 '22 00:10

Thales Minussi


I know that this isn't exactly what you asked for but I use Serverless Framework (https://serverless.com) for deployment and I love it. I don't do my deployments when I push to my repo. Instead I push to my repo after I've deployed. I like this flow because a deployment can fail due to so many things and pushing to GitHub is much less likely to fail. I this way, I prevent pushing code that failed to deploy to my master branch.

I don't know if you're familiar with the framework but it is super simple. The website describes the simple steps to creating and deploy a function like this.

1     # Step 1. Install serverless globally
2     $ npm install serverless -g
3
4     # Step 2. Create a serverless function
5     $ serverless create --template hello-world
6 
7     # Step 3. deploy to cloud provider
8     $ serverless deploy
9
10   # Your function is deployed!
11   $ http://xyz.amazonaws.com/hello-world

There are also a number of plugins you can use to integrate easily with custom domains on APIGateway, prune older versions of lambda functions that might be filling up your limits, etc...

Overall, I've found it to be the easiest way to manage and deploy my lambdas. Hope it helps!

like image 42
Matt Clevenger Avatar answered Oct 03 '22 00:10

Matt Clevenger