
CodeBuild Meets GitHub Actions: A Serverless CI Workflow with Lambda
Serverless GitHub Actions? Yes! Learn how to use AWS Lambda/ CodeBuild for Github Actions workflow execution.
- An AWS account with permissions to create CodeBuild projects and Lambda functions
- A GitHub repository where you want to run the actions
- AWS CLI and GitHub CLI installed on your local machine
- An IAM role with necessary permissions for CodeBuild and Lambda execution
- Open the AWS CodeBuild Console
- Click Create build project
- Project Name:
github-actions-runner
- Description:
Self-hosted GitHub Actions runner using AWS CodeBuild Lambda Runner
- Source: Select GitHub and connect to your repository
- Environment Image: Choose Managed Image
- Operating System: Amazon Linux 2
- Runtime: AWS Lambda
- Compute Type: Lambda Execution Environment
- Operating System System: Amazon Linux
- Runtime: Python
- Image & Version: Select the latest
- Choose New Service Role or select an existing role with permissions to execute CodeBuild, interact with GitHub, and access AWS Lambda.
- Attach the following policies if needed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["lambda:InvokeFunction"],
"Resource": "arn:aws:lambda:*:*:function:*"
},
{
"Effect": "Allow",
"Action": ["codebuild:StartBuild"],
"Resource": "*"
}
]
}
- Navigate to your GitHub repository
- Go to
Actions
tab and create a simple workflow. - To point the lambda self-hosted runner in place, update your
.github/workflows/main.yml
to use it: Please note theruns-on:
section here that you need to at to the workflow file.
1
2
3
# The type of runner that the job will run on
runs-on:
- codebuild-gha-runner-lambda-test-${{ github.run_id }}-${{ github.run_attempt }}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# This is a basic workflow to help you get started with Actions
name: CI AWS Lambda Pipeline Test
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on:
- codebuild-gha-runner-lambda-test-${{ github.run_id }}-${{ github.run_attempt }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
- Reserved Capacity
- Caching Across Builds
- Restricting Runtime with Timeouts
- Tools Requiring Root-User Permissions
- Long-Running Builds (Lambda has a maximum timeout of 15 minutes)