Setup CI/CD for your AWS Lambda with Serverless Framework and GitHub Actions

Previously I wrote about how to Create a Serverless backend with AWS Lambda Function, Amazon API Gateway and Serverless Framework. In that tutorial, I showed you how to create, test and deploy your serverless app to AWS Lambda and Amazon API Gateway ma…


This content originally appeared on DEV Community and was authored by Rexben

Previously I wrote about how to Create a Serverless backend with AWS Lambda Function, Amazon API Gateway and Serverless Framework. In that tutorial, I showed you how to create, test and deploy your serverless app to AWS Lambda and Amazon API Gateway manually but in this tutorial, I'll be showing you how to deploy it using CI/CD.

What's CI/CD?

CI/CD stands for continuous integration, continuous deployment and continuous delivery. It's a process that alienates manual processes of doing things. It is the art of automating the process of building, testing, deployment and delivery of apps to your customers. There are different tools used for CI/CD, they include Jenkins, GitHub Actions, GitLab CI, CircleCI, Travis CI, Bitbucket Pipelines, AWS CodeBuild, AWS CodeDeploy, AWS CodePipeline and many more.

In this tutorial, I'll be using AWS, Serverless framework and GitHub Actions

GitHub Actions

GitHub Actions automate, customize, and execute your software development workflows right in your repository with GitHub Actions. You can discover, create, and share actions to perform any job you'd like, including CI/CD, and combine actions in a completely customized workflow.

Prerequisites to follow along:

  • Have a GitHub account
  • Fork and clone this repo (contains code from my previous tutorial)
  • Have an AWS account
  • Create an AWS IAM user that has the following permissions: IAMFullAccess, AmazonS3FullAccess, CloudWatchFullAccess, AWSCloudFormationFullAccess, AWSLambda_FullAccess and AmazonAPIGatewayInvokeFullAccess.
  • Store the AWS user API key and secret key (keep it safe)

Create a main.yml file to define the workflow configuration

After ticking all the prerequisites, create a file called main.yml in folder .github/workflows and paste this code

A workflow is a configurable automated process made up of one or more jobs. 

Workflow syntax

name: the name of the workflow

on: the type of event that can run the workflow. Our workflow will only run when there's a git push to either the master or develop branch. Read more here

jobs: a workflow consists of one or more jobs. Jobs run in parallel unless a needs keyword is used. Each job runs in a runner environment specified by runs-on

steps: sequence of tasks to be carried out

uses: selects an action to run as part of a step in your job. An action is a reusable unit of code. Read more here

with: a map of input parameters

run: runs command-line programs

env: set the environment variables

Add API key and secret key to GitHub secret

Go to settings on the forked repo to add your API Key and Secret key. Click on Secrets on the left side nav and click on New repository secret to add your secrets. The API Key and Secret Key gives us programmatic access to your AWS environment.

GitHub Secrets

Push changes to GitHub to start the workflow

You can now commit your changes locally and push it to GitHub. Navigate the repo on GitHub, click on the actions, you should be able to see your workflows.

GitHub workflows

Extra resources

You can see the full project here
Read the docs to know more about GitHub actions
Read more about Serverless framework here
Learn more about AWS here


This content originally appeared on DEV Community and was authored by Rexben


Print Share Comment Cite Upload Translate Updates
APA

Rexben | Sciencx (2022-02-05T11:36:49+00:00) Setup CI/CD for your AWS Lambda with Serverless Framework and GitHub Actions. Retrieved from https://www.scien.cx/2022/02/05/setup-ci-cd-for-your-aws-lambda-with-serverless-framework-and-github-actions/

MLA
" » Setup CI/CD for your AWS Lambda with Serverless Framework and GitHub Actions." Rexben | Sciencx - Saturday February 5, 2022, https://www.scien.cx/2022/02/05/setup-ci-cd-for-your-aws-lambda-with-serverless-framework-and-github-actions/
HARVARD
Rexben | Sciencx Saturday February 5, 2022 » Setup CI/CD for your AWS Lambda with Serverless Framework and GitHub Actions., viewed ,<https://www.scien.cx/2022/02/05/setup-ci-cd-for-your-aws-lambda-with-serverless-framework-and-github-actions/>
VANCOUVER
Rexben | Sciencx - » Setup CI/CD for your AWS Lambda with Serverless Framework and GitHub Actions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/05/setup-ci-cd-for-your-aws-lambda-with-serverless-framework-and-github-actions/
CHICAGO
" » Setup CI/CD for your AWS Lambda with Serverless Framework and GitHub Actions." Rexben | Sciencx - Accessed . https://www.scien.cx/2022/02/05/setup-ci-cd-for-your-aws-lambda-with-serverless-framework-and-github-actions/
IEEE
" » Setup CI/CD for your AWS Lambda with Serverless Framework and GitHub Actions." Rexben | Sciencx [Online]. Available: https://www.scien.cx/2022/02/05/setup-ci-cd-for-your-aws-lambda-with-serverless-framework-and-github-actions/. [Accessed: ]
rf:citation
» Setup CI/CD for your AWS Lambda with Serverless Framework and GitHub Actions | Rexben | Sciencx | https://www.scien.cx/2022/02/05/setup-ci-cd-for-your-aws-lambda-with-serverless-framework-and-github-actions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.