This project demonstrates a simple CI/CD pipeline to automatically deploy a Python AWS Lambda function using GitHub Actions.
The process is defined in the .github/workflows/lambda-deploy.yml file:
- Trigger: The workflow runs on every
pushto themainbranch. - Setup: A virtual machine is set up with a specific version of Python.
- Install Dependencies: Python packages listed in
lambda/requirements.txtare installed directly into thelambdadirectory. - AWS Credentials: The workflow securely logs into AWS using secrets stored in the repository settings.
- Package & Deploy: The contents of the
lambdafolder are zipped and deployed to update the AWS Lambda function's code.
.
├── .github/
│ └── workflows/
│ └── lambda-deploy.yml # CI/CD workflow definition
├── lambda/
│ ├── lambda_function.py # Lambda function code
│ └── requirements.txt # Python dependencies
└── README.md # This file
- Create a new user with programmatic access.
- Attach a policy like
AdministratorAccess(for learning purposes) or a more restrictive one likeAWSLambda_FullAccess. - Save the
Access key IDandSecret access key.
- In the AWS Lambda console, create a new function from scratch.
- Function name:
my-test-ciccd-lambda(must match the name in the.ymlfile). - Runtime:
Python 3.12. - Use the default option to create a new execution role.
- In your GitHub repository, go to
Settings>Secrets and variables>Actions. - Add two new repository secrets:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY
To avoid any AWS charges, you must delete all created resources after you are finished.
- Delete the Lambda Function: In the Lambda console, select the function and delete it.
- Delete the IAM Role: In the IAM console, find the role created for the Lambda function (e.g.,
my-test-ciccd-lambda-role-...) and delete it. - Delete CloudWatch Logs: In the CloudWatch console, find the log group (
/aws/lambda/my-test-ciccd-lambda) and delete it. - Delete the IAM User: In the IAM console, delete the user you created for GitHub Actions. You may need to delete its access keys first.