This is a quick guide for anyone interested in creating a CI/CD pipeline that auto-updates a Lambda function every time a push is made within CodeCommit. The pipeline is a great way to automate any changes you make to your Lambda function all done within a CodeCommit repository.
Note: There are 3 types of ways to deploy your code onto AWS Lambda
- Using the in-line editor provided (up to 3 MB of Lambda code storage)
- Making a zipped deployment package and uploading it via console
- Making a zipped package and saving it in the S3 bucket. (up to 250 MB unzipped)
Preview of CI/CD Pipeline:
CodeCommit –> CodeBuild/CodePipeline –> S3 –> Lambda
- You’ll want to create a CodeCommit repository dedicated to hosting your Lambda function source code.
-
Create an S3 Bucket where our Lambda source code will be zipped and stored.
-
Add an S3 trigger to your lambda function so whenever there is a change in the zipped Lambda code it will be called.
-
Now you’ll want to create a CodeBuild job that knows which branch and repository to pull the source Lambda code from and create the zipped file. For this step you’ll need to use a
buildspec
file, which is essentially a script that provides the steps necessary for the CodeBuild job. Here is an examplebuildspec
file:build: commands: — cd ./deploymentDir — zip -r deployment.zip * — aws s3 cp deployment.zip s3://your-bucketname/location-of-zip artifacts: files: — ./deploymentDir/deployment.zip
-
Finally, create a CodePipeline that will where we will set triggers on when we will run the CodeBuild step.