-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Simplify Lambda deployment with zip files instead of container images #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RayyanSeliya
wants to merge
7
commits into
pipe-cd:main
Choose a base branch
from
RayyanSeliya:simplify-lambda-deployment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e61ef22
feat: implement zip-based Lambda deployment to reduce prerequisite
RayyanSeliya c0b5cc3
updated some necessarry changes
RayyanSeliya 76a1c4d
made a procedure without building and pushing to s3
RayyanSeliya cfd3d2c
removed standalone readme and aligned the instruction with the tutori…
RayyanSeliya 8456252
typo fixed in the description and corrected the description
RayyanSeliya 918d6a4
aligned the text of english version to match with japanese version
RayyanSeliya 5c377df
updated the git ref fields and related comments
RayyanSeliya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| # 🚀 Complete Lambda Deployment Guide | ||
|
|
||
| This guide provides step-by-step instructions for deploying AWS Lambda functions with PipeCD using the new simplified zip-based approach. | ||
|
|
||
| ## 📋 Prerequisites Checklist | ||
|
|
||
| Before starting, ensure you have: | ||
|
|
||
| - [ ] AWS CLI configured with appropriate permissions | ||
| - [ ] S3 bucket created for storing Lambda packages | ||
| - [ ] IAM role for Lambda execution with basic permissions | ||
| - [ ] Python 3.9+ installed locally | ||
| - [ ] PipeCD control plane and piped running | ||
|
|
||
| ## 🔧 Setup Instructions | ||
|
|
||
| ### 1. Create S3 Bucket (if not exists) | ||
|
|
||
| ```bash | ||
| # Create bucket | ||
| aws s3 mb s3://your-lambda-bucket-name | ||
|
|
||
| # Enable versioning (recommended) | ||
| aws s3api put-bucket-versioning \ | ||
| --bucket your-lambda-bucket-name \ | ||
| --versioning-configuration Status=Enabled | ||
| ``` | ||
|
|
||
| ### 2. Create IAM Role for Lambda | ||
|
|
||
| Create a trust policy file `lambda-trust-policy.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Principal": { | ||
| "Service": "lambda.amazonaws.com" | ||
| }, | ||
| "Action": "sts:AssumeRole" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| Create the role: | ||
|
|
||
| ```bash | ||
| # Create role | ||
| aws iam create-role \ | ||
| --role-name pipecd-lambda-execution-role \ | ||
| --assume-role-policy-document file://lambda-trust-policy.json | ||
|
|
||
| # Attach basic execution policy | ||
| aws iam attach-role-policy \ | ||
| --role-name pipecd-lambda-execution-role \ | ||
| --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole | ||
|
|
||
| # Get role ARN (save this for later) | ||
| aws iam get-role --role-name pipecd-lambda-execution-role --query 'Role.Arn' --output text | ||
| ``` | ||
|
|
||
| ## 🏗️ Building and Deploying | ||
|
|
||
| ### Simple Deployment | ||
|
|
||
| 1. **Navigate to simple directory:** | ||
| ```bash | ||
| cd src/deploy/lambda/simple/ | ||
| ``` | ||
|
|
||
| 2. **Build the package:** | ||
| ```bash | ||
| # Linux/Mac | ||
| chmod +x build.sh | ||
| ./build.sh | ||
|
|
||
| # Windows | ||
| build.bat | ||
| ``` | ||
|
|
||
| 3. **Upload to S3:** | ||
| ```bash | ||
| aws s3 cp pipecd-tutorial-simple.zip s3://your-lambda-bucket-name/lambda/pipecd-tutorial-simple.zip | ||
| ``` | ||
|
|
||
| 4. **Configure function.yaml:** | ||
| ```yaml | ||
| spec: | ||
| name: PipeCDTutorial_Simple | ||
| role: arn:aws:iam::123456789012:role/pipecd-lambda-execution-role | ||
| source: | ||
| s3Bucket: your-lambda-bucket-name | ||
| s3Key: lambda/pipecd-tutorial-simple.zip | ||
| runtime: python3.9 | ||
| handler: index.lambda_handler | ||
| memory: 512 | ||
| timeout: 30 | ||
| environment: | ||
| FUNCTION_VERSION: "v1.0.0" | ||
| ``` | ||
|
|
||
| 5. **Deploy with PipeCD:** | ||
| - Register the application in PipeCD console | ||
| - Commit and push changes to trigger deployment | ||
|
|
||
| ### Canary Deployment | ||
|
|
||
| 1. **Navigate to canary directory:** | ||
| ```bash | ||
| cd src/deploy/lambda/canary/ | ||
| ``` | ||
|
|
||
| 2. **Build the package:** | ||
| ```bash | ||
| # Linux/Mac | ||
| chmod +x build.sh | ||
| ./build.sh | ||
|
|
||
| # Windows | ||
| build.bat | ||
| ``` | ||
|
|
||
| 3. **Upload to S3:** | ||
| ```bash | ||
| aws s3 cp pipecd-tutorial-canary.zip s3://your-lambda-bucket-name/lambda/pipecd-tutorial-canary.zip | ||
| ``` | ||
|
|
||
| 4. **Configure function.yaml:** | ||
| ```yaml | ||
| spec: | ||
| name: PipeCDTutorial_Canary | ||
| role: arn:aws:iam::123456789012:role/pipecd-lambda-execution-role | ||
| source: | ||
| s3Bucket: your-lambda-bucket-name | ||
| s3Key: lambda/pipecd-tutorial-canary.zip | ||
| runtime: python3.9 | ||
| handler: index.lambda_handler | ||
| memory: 512 | ||
| timeout: 30 | ||
| environment: | ||
| FUNCTION_VERSION: "v2.0.0" | ||
| DEPLOYMENT_TYPE: "canary" | ||
| ``` | ||
|
|
||
| 5. **Deploy with canary strategy:** | ||
| - The pipeline will automatically handle gradual rollout | ||
| - Monitor deployment progress in PipeCD console | ||
|
|
||
| ## 🧪 Testing Your Deployment | ||
|
|
||
| ### Local Testing | ||
|
|
||
| Test the function locally before deployment: | ||
|
|
||
| ```bash | ||
| cd src/ | ||
| python index.py | ||
| ``` | ||
|
|
||
| ### AWS Testing | ||
|
|
||
| After deployment, test the function: | ||
|
|
||
| ```bash | ||
| # Invoke function directly | ||
| aws lambda invoke \ | ||
| --function-name PipeCDTutorial_Simple \ | ||
| --payload '{"httpMethod":"GET","path":"/test"}' \ | ||
| response.json | ||
|
|
||
| # View response | ||
| cat response.json | ||
| ``` | ||
|
|
||
| ## 🔍 Troubleshooting | ||
|
|
||
| ### Common Issues | ||
|
|
||
| 1. **Build fails:** | ||
| - Check Python version: `python --version` | ||
| - Ensure build script has execute permissions | ||
| - Verify requirements.txt syntax | ||
|
|
||
| 2. **Upload fails:** | ||
| - Check AWS credentials: `aws sts get-caller-identity` | ||
| - Verify S3 bucket exists and you have write permissions | ||
| - Check bucket region matches your AWS CLI region | ||
|
|
||
| 3. **Deployment fails:** | ||
| - Verify IAM role ARN is correct | ||
| - Check S3 bucket and key path in function.yaml | ||
| - Ensure Lambda service has access to S3 bucket | ||
|
|
||
| 4. **Function errors:** | ||
| - Check CloudWatch logs: `aws logs describe-log-groups --log-group-name-prefix /aws/lambda/PipeCDTutorial` | ||
| - Verify handler path: `index.lambda_handler` | ||
| - Check runtime compatibility | ||
|
|
||
| ### Debugging Commands | ||
|
|
||
| ```bash | ||
| # Check function configuration | ||
| aws lambda get-function --function-name PipeCDTutorial_Simple | ||
|
|
||
| # View recent logs | ||
| aws logs tail /aws/lambda/PipeCDTutorial_Simple --follow | ||
|
|
||
| # Test function with custom payload | ||
| aws lambda invoke \ | ||
| --function-name PipeCDTutorial_Simple \ | ||
| --payload '{"test": "data"}' \ | ||
| --cli-binary-format raw-in-base64-out \ | ||
| response.json | ||
| ``` | ||
|
|
||
| ## 🎯 Next Steps | ||
|
|
||
| 1. **Customize the function** for your specific use case | ||
| 2. **Add dependencies** by editing requirements.txt | ||
| 3. **Implement monitoring** using CloudWatch metrics | ||
| 4. **Set up alerts** for function errors | ||
| 5. **Explore advanced PipeCD features** like approval workflows | ||
|
|
||
| ## 📚 Additional Resources | ||
|
|
||
| - [PipeCD Lambda Documentation](https://pipecd.dev/docs/user-guide/configuration-reference/#lambda-application) | ||
| - [AWS Lambda Developer Guide](https://docs.aws.amazon.com/lambda/latest/dg/) | ||
| - [AWS Lambda Best Practices](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make a procedure without building and pushing to s3. That's troublesome.
Use the zip packing feature of PipeCD Lambda.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure will research on this through https://pipecd.dev/docs-v0.52.x/user-guide/managing-application/defining-app-configuration/lambda/ and implement it accordingly