From e61ef2219cc62452bc76763ecc8b246b0297b5eb Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Thu, 10 Jul 2025 01:38:41 +0530 Subject: [PATCH 1/7] feat: implement zip-based Lambda deployment to reduce prerequisite --- content/en/20-prerequisites/README.md | 3 +- content/en/40-deploy/01-simply.md | 6 +- content/en/40-deploy/02-pipeline.md | 6 +- content/ja/20-prerequisites/README.md | 3 +- content/ja/40-deploy/01-simply.md | 8 +- content/ja/40-deploy/02-pipeline.md | 5 +- src/deploy/lambda/DEPLOYMENT_GUIDE.md | 231 ++++++++++++++++++ src/deploy/lambda/README.md | 188 ++++++++++++++ src/deploy/lambda/canary/build.bat | 56 +++++ src/deploy/lambda/canary/build.sh | 56 +++++ src/deploy/lambda/canary/function.yaml | 12 +- src/deploy/lambda/canary/src/index.py | 85 +++++++ src/deploy/lambda/canary/src/requirements.txt | 13 + src/deploy/lambda/setup-lambda.bat | 154 ++++++++++++ src/deploy/lambda/setup-lambda.sh | 132 ++++++++++ src/deploy/lambda/simple/build.bat | 56 +++++ src/deploy/lambda/simple/build.sh | 56 +++++ src/deploy/lambda/simple/function.yaml | 11 +- src/deploy/lambda/simple/src/index.py | 76 ++++++ 19 files changed, 1143 insertions(+), 14 deletions(-) create mode 100644 src/deploy/lambda/DEPLOYMENT_GUIDE.md create mode 100644 src/deploy/lambda/README.md create mode 100644 src/deploy/lambda/canary/build.bat create mode 100644 src/deploy/lambda/canary/build.sh create mode 100644 src/deploy/lambda/canary/src/index.py create mode 100644 src/deploy/lambda/canary/src/requirements.txt create mode 100644 src/deploy/lambda/setup-lambda.bat create mode 100644 src/deploy/lambda/setup-lambda.sh create mode 100644 src/deploy/lambda/simple/build.bat create mode 100644 src/deploy/lambda/simple/build.sh create mode 100644 src/deploy/lambda/simple/src/index.py diff --git a/content/en/20-prerequisites/README.md b/content/en/20-prerequisites/README.md index 37d9dbc..92182b1 100644 --- a/content/en/20-prerequisites/README.md +++ b/content/en/20-prerequisites/README.md @@ -23,8 +23,9 @@ To perform this tutorial, you need the following: - for **AWS Lambda**: - You can call APIs of Lambda from your local to your AWS account. See [here](https://pipecd.dev/docs/installation/install-piped/required-permissions/#for-lambdaapp) for details. - You have all of (i.e. all you need to create a Lambda function): - - an image in your ECR Repository + - an S3 bucket for storing Lambda zip files - function’s execution role + - Python 3.9+ installed locally (for building the function package) - for **Terraform**: - You can execute [`terraform` commands](https://developer.hashicorp.com/terraform/cli/commands) on local. diff --git a/content/en/40-deploy/01-simply.md b/content/en/40-deploy/01-simply.md index 1dec991..c6e8fb5 100644 --- a/content/en/40-deploy/01-simply.md +++ b/content/en/40-deploy/01-simply.md @@ -22,9 +22,11 @@ In this page, you will deploy an application to your platform in a simple way. - `servicedef.yaml`: Edit `cluster`, `securityGroups`, and `subnets`. - `taskdef.yaml`: Edit `executionRoleArn`. - For **AWS Lambda**: - - You will create a function of your own image. + - You will create a function using a simple Python source code package. - Edit `lambda/simple/` as below. - - `function.yaml`: Edit `role` and `image`. + - Build the function package: Run `./build.sh` (Linux/Mac) or `build.bat` (Windows) + - Upload the generated zip file to your S3 bucket + - `function.yaml`: Edit `role`, `s3Bucket`, and `s3Key` - For **Terraform**: - You will generate a file on local. - Edit `terraform/simple/` as below. diff --git a/content/en/40-deploy/02-pipeline.md b/content/en/40-deploy/02-pipeline.md index 727f2d8..f854a6d 100644 --- a/content/en/40-deploy/02-pipeline.md +++ b/content/en/40-deploy/02-pipeline.md @@ -21,9 +21,11 @@ _The process is almost the same as [1. Deploy Simply](01-simply.md). Only the co - `servicedef.yaml`: Copy from your `/src/deploy/ecs/simple/servicedef.yaml` and rename `serviceName`. - `taskdef.yaml`: Copy from your `/src/deploy/ecs/simple/taskdef.yaml` and rename `family`. - For **AWS Lambda**: - - You will create a function of your own image by Canary release. + - You will create a function using source code with Canary release strategy. - Edit `lambda/canary/` as below. - - `function.yaml`: Copy from your `/src/deploy/lambda/simple/function.yaml`] and rename `name`. + - Build the canary function package: Run `./build.sh` (Linux/Mac) or `build.bat` (Windows) + - Upload the generated zip file to your S3 bucket + - `function.yaml`: Edit `role`, `s3Bucket`, and `s3Key` (the function name is already different from simple) - For **Terraform**: - You will generate a file on local with plan->approval->apply pipeline. - Edit `terraform/plan-approval-apply/` as below. diff --git a/content/ja/20-prerequisites/README.md b/content/ja/20-prerequisites/README.md index d46fad5..b60cfd8 100644 --- a/content/ja/20-prerequisites/README.md +++ b/content/ja/20-prerequisites/README.md @@ -23,8 +23,9 @@ - **AWS Lambda**向け: - ローカルからあなたのAWSアカウントに対して、Lambdaの各種APIを実行できること。詳細は[こちら](https://pipecd.dev/docs/installation/install-piped/required-permissions/#for-lambdaapp)。 - 下記のすべて。(一般的なLambda関数を作る際に必要なものと同じです) - - ECRリポジトリにイメージがあること + - Lambdaのzipファイルを保存するためのS3バケット - 関数の実行ロール + - Python 3.9+がローカルにインストールされていること(関数パッケージのビルド用) - **Terraform**向け: - [`terraform` commands](https://developer.hashicorp.com/terraform/cli/commands)をローカルから実行できること。 diff --git a/content/ja/40-deploy/01-simply.md b/content/ja/40-deploy/01-simply.md index 1ca7620..f0c2e01 100644 --- a/content/ja/40-deploy/01-simply.md +++ b/content/ja/40-deploy/01-simply.md @@ -22,9 +22,11 @@ - `servicedef.yaml`: `cluster`, `securityGroups`, `subnets` - `taskdef.yaml`: `executionRoleArn`. - **AWS Lambda**向け: - - あなたのイメージを利用して関数をデプロイしていきます。 - - `lambda/simple/`の以下の箇所を編集してください。 - - `function.yaml`: `role`, `image` + - シンプルなPythonソースコードパッケージを使用して関数をデプロイしていきます。 + - `lambda/simple/`の以下の手順を実行してください。 + - 関数パッケージをビルド: `./build.sh` (Linux/Mac) または `build.bat` (Windows) を実行 + - 生成されたzipファイルをS3バケットにアップロード + - `function.yaml`: `role`, `s3Bucket`, `s3Key` を編集 - **Terraform**向け: - ファイルをローカルに生成していきます。 - `terraform/simple/`の以下の箇所を編集してください。 diff --git a/content/ja/40-deploy/02-pipeline.md b/content/ja/40-deploy/02-pipeline.md index 4cb3c62..a335ad3 100644 --- a/content/ja/40-deploy/02-pipeline.md +++ b/content/ja/40-deploy/02-pipeline.md @@ -21,8 +21,11 @@ _手順は[1. シンプルなデプロイ](01-simply.md)とほとんど同じで - `servicedef.yaml`: `/src/deploy/ecs/simple/servicedef.yaml`からコピーして、`serviceName`を変更 - `taskdef.yaml`: `/src/deploy/ecs/simple/taskdef.yaml`からコピーして、`family`を変更 - **AWS Lambda**向け: - - あなたのイメージを利用して関数をCanaryリリースしていきます。 + - ソースコードを使用して関数をCanaryリリースしていきます。 - `lambda/canary/`を以下のように編集してください。 + - Canary関数パッケージをビルド: `./build.sh` (Linux/Mac) または `build.bat` (Windows) を実行 + - 生成されたzipファイルをS3バケットにアップロード + - `function.yaml`: `role`, `s3Bucket`, `s3Key` を編集(関数名は既にsimpleと異なります) - `function.yaml`: `/src/deploy/lambda/simple/function.yaml`からコピーして、`name`を変更 - **Terraform**向け: - ファイルをローカルに生成していきます。plan->承認->applyのパイプラインを構築します。 diff --git a/src/deploy/lambda/DEPLOYMENT_GUIDE.md b/src/deploy/lambda/DEPLOYMENT_GUIDE.md new file mode 100644 index 0000000..7556eb6 --- /dev/null +++ b/src/deploy/lambda/DEPLOYMENT_GUIDE.md @@ -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) diff --git a/src/deploy/lambda/README.md b/src/deploy/lambda/README.md new file mode 100644 index 0000000..9b0baca --- /dev/null +++ b/src/deploy/lambda/README.md @@ -0,0 +1,188 @@ +# Lambda Deployment with PipeCD Tutorial + +This directory contains examples for deploying AWS Lambda functions using PipeCD with **zip file deployment** instead of container images, making it much easier to get started. + +## 🎯 What's New (Issue #16) + +Previously, the Lambda tutorial required: +- ❌ Building and pushing container images to ECR +- ❌ Complex Docker setup +- ❌ ECR repository management + +Now it uses: +- ✅ Simple Python source code +- ✅ Zip file packaging +- ✅ Direct S3 upload +- ✅ Minimal prerequisites + +## 📁 Directory Structure + +``` +lambda/ +├── simple/ # Simple deployment example +│ ├── src/ +│ │ ├── index.py # Lambda function source code +│ │ └── requirements.txt # Python dependencies +│ ├── function.yaml # Lambda function configuration +│ ├── app.pipecd.yaml # PipeCD application config +│ ├── build.sh # Build script (Linux/Mac) +│ └── build.bat # Build script (Windows) +├── canary/ # Canary deployment example +│ ├── src/ +│ │ ├── index.py # Enhanced Lambda function +│ │ └── requirements.txt # Python dependencies +│ ├── function.yaml # Lambda function configuration +│ ├── app.pipecd.yaml # PipeCD canary pipeline config +│ ├── build.sh # Build script (Linux/Mac) +│ └── build.bat # Build script (Windows) +└── README.md # This file +``` + +## 🚀 Quick Start + +### Prerequisites + +1. **AWS CLI configured** with appropriate permissions +2. **S3 bucket** for storing Lambda zip files +3. **IAM role** for Lambda execution +4. **Python 3.9+** (for local testing) + +### Step 1: Build the Lambda Package + +**Linux/Mac:** +```bash +cd simple/ +chmod +x build.sh +./build.sh +``` + +**Windows:** +```cmd +cd simple\ +build.bat +``` + +This creates `pipecd-tutorial-simple.zip` containing your Lambda function. + +### Step 2: Upload to S3 + +```bash +aws s3 cp pipecd-tutorial-simple.zip s3://your-bucket-name/lambda/pipecd-tutorial-simple.zip +``` + +### Step 3: Configure function.yaml + +Edit `simple/function.yaml`: + +```yaml +spec: + name: PipeCDTutorial_Simple + role: arn:aws:iam::123456789012:role/lambda-execution-role + source: + s3Bucket: your-bucket-name + s3Key: lambda/pipecd-tutorial-simple.zip + runtime: python3.9 + handler: index.lambda_handler +``` + +### Step 4: Deploy with PipeCD + +Follow the main tutorial instructions to register and deploy the application. + +## 📋 Function Details + +### Simple Function (`simple/src/index.py`) + +- Returns a JSON response with greeting and metadata +- Includes request information and timestamps +- Uses only Python standard library (no dependencies) +- Perfect for testing basic Lambda deployment + +### Canary Function (`canary/src/index.py`) + +- Enhanced version with deployment tracking +- Additional logging for canary deployment monitoring +- Environment variables for version control +- Demonstrates gradual rollout capabilities + +## 🔧 Customization + +### Adding Dependencies + +1. Edit `src/requirements.txt`: + ``` + requests==2.31.0 + boto3==1.34.0 + ``` + +2. Rebuild the package: + ```bash + ./build.sh + ``` + +### Modifying the Function + +1. Edit `src/index.py` with your custom logic +2. Test locally: `python src/index.py` +3. Rebuild and redeploy + +### Environment Variables + +Add environment variables in `function.yaml`: + +```yaml +spec: + environment: + CUSTOM_VAR: "custom_value" + API_ENDPOINT: "https://api.example.com" +``` + +## 🧪 Local Testing + +Test your function locally before deployment: + +```bash +cd simple/src/ +python index.py +``` + +This runs the function with a test event and displays the output. + +## 📊 Deployment Strategies + +### Simple Deployment +- Uses `simple/` directory +- Quick sync strategy +- Immediate deployment + +### Canary Deployment +- Uses `canary/` directory +- Gradual traffic shifting (10% → 50% → 100%) +- Built-in rollback capabilities +- Wait stages for monitoring + +## 🔍 Troubleshooting + +### Build Issues +- Ensure Python 3.9+ is installed +- Check file permissions on build scripts +- Verify requirements.txt syntax + +### Deployment Issues +- Confirm S3 bucket permissions +- Verify IAM role has Lambda execution permissions +- Check function.yaml syntax + +### Runtime Issues +- Review CloudWatch logs +- Test function locally first +- Verify environment variables + +## 📚 Next Steps + +1. Try the simple deployment first +2. Experiment with the canary deployment +3. Customize the function for your use case +4. Explore PipeCD's advanced Lambda features + +For more information, see the [PipeCD Lambda documentation](https://pipecd.dev/docs/user-guide/configuration-reference/#lambda-application). diff --git a/src/deploy/lambda/canary/build.bat b/src/deploy/lambda/canary/build.bat new file mode 100644 index 0000000..4abcfd2 --- /dev/null +++ b/src/deploy/lambda/canary/build.bat @@ -0,0 +1,56 @@ +@echo off +REM Build script for PipeCD Tutorial Lambda Function (Canary) - Windows +REM This script packages the canary Lambda function code into a zip file + +echo Building PipeCD Tutorial Lambda Function (Canary)... + +REM Set variables +set BUILD_DIR=build +set FUNCTION_NAME=pipecd-tutorial-canary +set ZIP_FILE=%FUNCTION_NAME%.zip + +REM Clean previous build +if exist "%BUILD_DIR%" ( + echo Cleaning previous build... + rmdir /s /q "%BUILD_DIR%" +) + +if exist "%ZIP_FILE%" ( + echo Removing previous zip file... + del "%ZIP_FILE%" +) + +REM Create build directory +mkdir "%BUILD_DIR%" + +REM Copy source code +echo Copying source code... +copy "src\index.py" "%BUILD_DIR%\" + +REM Check if requirements.txt has actual dependencies +findstr /v "^#" "src\requirements.txt" | findstr /v "^$" > nul +if %errorlevel% equ 0 ( + echo Installing Python dependencies... + pip install -r src\requirements.txt -t %BUILD_DIR% +) else ( + echo No dependencies to install (using only standard library) +) + +REM Create zip file +echo Creating zip package... +cd "%BUILD_DIR%" +powershell -command "Compress-Archive -Path * -DestinationPath '..\%ZIP_FILE%' -Force" +cd .. + +REM Cleanup build directory +rmdir /s /q "%BUILD_DIR%" + +echo ✅ Canary Lambda function packaged successfully: %ZIP_FILE% +for %%A in ("%ZIP_FILE%") do echo 📦 Package size: %%~zA bytes +echo. +echo Next steps: +echo 1. Upload %ZIP_FILE% to an S3 bucket +echo 2. Update function.yaml with the S3 bucket and key +echo 3. Deploy using PipeCD canary pipeline + +pause diff --git a/src/deploy/lambda/canary/build.sh b/src/deploy/lambda/canary/build.sh new file mode 100644 index 0000000..b0c4ed4 --- /dev/null +++ b/src/deploy/lambda/canary/build.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Build script for PipeCD Tutorial Lambda Function (Canary) +# This script packages the canary Lambda function code into a zip file + +set -e + +echo "Building PipeCD Tutorial Lambda Function (Canary)..." + +# Create build directory +BUILD_DIR="build" +FUNCTION_NAME="pipecd-tutorial-canary" +ZIP_FILE="${FUNCTION_NAME}.zip" + +# Clean previous build +if [ -d "$BUILD_DIR" ]; then + echo "Cleaning previous build..." + rm -rf "$BUILD_DIR" +fi + +if [ -f "$ZIP_FILE" ]; then + echo "Removing previous zip file..." + rm "$ZIP_FILE" +fi + +# Create build directory +mkdir -p "$BUILD_DIR" + +# Copy source code +echo "Copying source code..." +cp src/index.py "$BUILD_DIR/" + +# Install dependencies if requirements.txt has actual dependencies +if [ -f "src/requirements.txt" ] && [ -s "src/requirements.txt" ] && grep -v '^#' src/requirements.txt | grep -v '^$' > /dev/null; then + echo "Installing Python dependencies..." + pip install -r src/requirements.txt -t "$BUILD_DIR/" +else + echo "No dependencies to install (using only standard library)" +fi + +# Create zip file +echo "Creating zip package..." +cd "$BUILD_DIR" +zip -r "../$ZIP_FILE" . +cd .. + +# Cleanup build directory +rm -rf "$BUILD_DIR" + +echo "✅ Canary Lambda function packaged successfully: $ZIP_FILE" +echo "📦 Package size: $(du -h "$ZIP_FILE" | cut -f1)" +echo "" +echo "Next steps:" +echo "1. Upload $ZIP_FILE to an S3 bucket" +echo "2. Update function.yaml with the S3 bucket and key" +echo "3. Deploy using PipeCD canary pipeline" diff --git a/src/deploy/lambda/canary/function.yaml b/src/deploy/lambda/canary/function.yaml index cca2b80..ec1653c 100644 --- a/src/deploy/lambda/canary/function.yaml +++ b/src/deploy/lambda/canary/function.yaml @@ -4,6 +4,14 @@ kind: LambdaFunction spec: name: PipeCDTutorial_Canary role: # [EDIT_HERE] The ARN of the function’s execution role. - image: # [EDIT_HERE] The URI of a container image in the Amazon ECR registry. + # Using zip deployment instead of container image for simpler setup + source: + s3Bucket: # [EDIT_HERE] S3 bucket containing your zip file + s3Key: # [EDIT_HERE] S3 key path to your zip file (e.g., lambda/pipecd-tutorial-canary.zip) + runtime: python3.9 + handler: index.lambda_handler memory: 512 - timeout: 30 \ No newline at end of file + timeout: 30 + environment: + FUNCTION_VERSION: "v2.0.0" + DEPLOYMENT_TYPE: "canary" \ No newline at end of file diff --git a/src/deploy/lambda/canary/src/index.py b/src/deploy/lambda/canary/src/index.py new file mode 100644 index 0000000..4418db4 --- /dev/null +++ b/src/deploy/lambda/canary/src/index.py @@ -0,0 +1,85 @@ +""" +Canary Lambda function for PipeCD Tutorial + +This is a Lambda function for demonstrating canary deployments with PipeCD. +It includes version information and enhanced logging for deployment tracking. +""" + +import json +import os +from datetime import datetime, timezone + + +def lambda_handler(event, context): + """ + AWS Lambda handler function for canary deployment demo + + Args: + event: The event dict that contains the request data + context: The context object that contains runtime information + + Returns: + dict: Response object with statusCode, headers, and body + """ + + # Get environment variables + function_name = context.function_name if context else "unknown" + version = os.environ.get('FUNCTION_VERSION', 'v2.0.0') + deployment_type = os.environ.get('DEPLOYMENT_TYPE', 'canary') + + # Create response message with canary-specific information + message = { + "greeting": "Hello from PipeCD Tutorial Lambda (Canary)!", + "function_name": function_name, + "version": version, + "deployment_type": deployment_type, + "timestamp": datetime.now(timezone.utc).isoformat(), + "canary_info": { + "strategy": "gradual rollout", + "traffic_percentage": "controlled by PipeCD pipeline" + }, + "event_info": { + "http_method": event.get("httpMethod", "N/A"), + "path": event.get("path", "N/A"), + "query_params": event.get("queryStringParameters") or {} + } + } + + # Enhanced logging for canary deployment tracking + print(f"🚀 Canary deployment - Processing request for {function_name} version {version}") + print(f"📊 Deployment type: {deployment_type}") + print(f"📝 Event: {json.dumps(event, default=str)}") + + # Return response with canary-specific headers + response = { + "statusCode": 200, + "headers": { + "Content-Type": "application/json", + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Methods": "GET, POST, OPTIONS", + "X-Function-Version": version, + "X-Deployment-Type": deployment_type + }, + "body": json.dumps(message, indent=2) + } + + return response + + +# For local testing +if __name__ == "__main__": + # Test event + test_event = { + "httpMethod": "GET", + "path": "/canary-test", + "queryStringParameters": {"deployment": "canary"} + } + + # Mock context + class MockContext: + function_name = "pipecd-tutorial-canary-local" + + result = lambda_handler(test_event, MockContext()) + print("Canary test result:") + print(json.dumps(result, indent=2)) diff --git a/src/deploy/lambda/canary/src/requirements.txt b/src/deploy/lambda/canary/src/requirements.txt new file mode 100644 index 0000000..4532f96 --- /dev/null +++ b/src/deploy/lambda/canary/src/requirements.txt @@ -0,0 +1,13 @@ +# Requirements for PipeCD Tutorial Lambda Function (Canary) +# This file lists the Python dependencies needed for the canary Lambda function + +# No external dependencies required for this simple example +# The function only uses Python standard library modules: +# - json (built-in) +# - os (built-in) +# - datetime (built-in) + +# If you need to add dependencies in the future, list them here +# For example: +# requests==2.31.0 +# boto3==1.34.0 diff --git a/src/deploy/lambda/setup-lambda.bat b/src/deploy/lambda/setup-lambda.bat new file mode 100644 index 0000000..ab41d14 --- /dev/null +++ b/src/deploy/lambda/setup-lambda.bat @@ -0,0 +1,154 @@ +@echo off +REM Quick setup script for PipeCD Lambda Tutorial (Windows) +REM This script helps you get started with Lambda deployment quickly + +echo 🚀 PipeCD Lambda Tutorial Setup +echo ================================ + +REM Check prerequisites +echo 📋 Checking prerequisites... + +REM Check AWS CLI +aws --version >nul 2>nul +if %errorlevel% neq 0 ( + echo ❌ AWS CLI not found or not working. Please install AWS CLI first. + echo 💡 You can install it from: https://aws.amazon.com/cli/ + echo 💡 Or try: winget install Amazon.AWSCLI + pause + exit /b 1 +) + +REM Check Python +python --version >nul 2>nul +if %errorlevel% neq 0 ( + echo ❌ Python not found. Please install Python 3.9+ first. + echo 💡 You can install it from: https://python.org/downloads/ + echo 💡 Or try: winget install Python.Python.3.12 + pause + exit /b 1 +) + +REM Check if AWS is configured +aws sts get-caller-identity >nul 2>nul +if %errorlevel% neq 0 ( + echo ❌ AWS CLI not configured. Please run 'aws configure' first. + pause + exit /b 1 +) + +echo ✅ Prerequisites check passed! + +REM Get user inputs +echo. +echo 📝 Configuration +echo ================== + +set /p S3_BUCKET="Enter your S3 bucket name for Lambda packages: " +set /p LAMBDA_ROLE="Enter your Lambda execution role ARN: " + +REM Validate inputs +if "%S3_BUCKET%"=="" ( + echo ❌ S3 bucket name is required. + pause + exit /b 1 +) + +if "%LAMBDA_ROLE%"=="" ( + echo ❌ Lambda role ARN is required. + pause + exit /b 1 +) + +REM Check if S3 bucket exists +aws s3 ls "s3://%S3_BUCKET%" >nul 2>nul +if %errorlevel% neq 0 ( + echo ⚠️ S3 bucket '%S3_BUCKET%' not found or not accessible. + set /p CREATE_BUCKET="Do you want to create it? (y/n): " + if /i "%CREATE_BUCKET%"=="y" ( + echo Creating S3 bucket... + aws s3 mb "s3://%S3_BUCKET%" + if %errorlevel% equ 0 ( + echo ✅ S3 bucket created successfully! + ) else ( + echo ❌ Failed to create S3 bucket. + pause + exit /b 1 + ) + ) else ( + echo ❌ Please create the S3 bucket first or check permissions. + pause + exit /b 1 + ) +) + +REM Build and deploy simple function +echo. +echo 🏗️ Building Simple Lambda Function +echo ==================================== + +cd simple + +REM Update function.yaml +echo Updating function.yaml... +powershell -command "(Get-Content function.yaml) -replace '', '%S3_BUCKET%' | Set-Content function.yaml" +powershell -command "(Get-Content function.yaml) -replace '', 'lambda/pipecd-tutorial-simple.zip' | Set-Content function.yaml" +powershell -command "(Get-Content function.yaml) -replace '', '%LAMBDA_ROLE%' | Set-Content function.yaml" + +REM Build package +echo Building package... +call build.bat + +REM Upload to S3 +echo Uploading to S3... +aws s3 cp pipecd-tutorial-simple.zip "s3://%S3_BUCKET%/lambda/pipecd-tutorial-simple.zip" + +echo ✅ Simple function setup complete! + +REM Build and deploy canary function +echo. +echo 🏗️ Building Canary Lambda Function +echo ==================================== + +cd ..\canary + +REM Update function.yaml +echo Updating function.yaml... +powershell -command "(Get-Content function.yaml) -replace '', '%S3_BUCKET%' | Set-Content function.yaml" +powershell -command "(Get-Content function.yaml) -replace '', 'lambda/pipecd-tutorial-canary.zip' | Set-Content function.yaml" +powershell -command "(Get-Content function.yaml) -replace '', '%LAMBDA_ROLE%' | Set-Content function.yaml" + +REM Build package +echo Building package... +call build.bat + +REM Upload to S3 +echo Uploading to S3... +aws s3 cp pipecd-tutorial-canary.zip "s3://%S3_BUCKET%/lambda/pipecd-tutorial-canary.zip" + +echo ✅ Canary function setup complete! + +REM Summary +echo. +echo 🎉 Setup Complete! +echo ================== +echo ✅ Both Lambda functions are built and uploaded to S3 +echo ✅ Configuration files are updated +echo. +echo 📋 Next Steps: +echo 1. Commit and push your changes to Git +echo 2. Register the applications in PipeCD console +echo 3. Watch the deployment progress +echo. +echo 📁 Files created: +echo - simple\pipecd-tutorial-simple.zip +echo - canary\pipecd-tutorial-canary.zip +echo. +echo ☁️ S3 Objects: +echo - s3://%S3_BUCKET%/lambda/pipecd-tutorial-simple.zip +echo - s3://%S3_BUCKET%/lambda/pipecd-tutorial-canary.zip +echo. +echo 📚 For more information, see: +echo - README.md +echo - DEPLOYMENT_GUIDE.md + +pause diff --git a/src/deploy/lambda/setup-lambda.sh b/src/deploy/lambda/setup-lambda.sh new file mode 100644 index 0000000..0af3a00 --- /dev/null +++ b/src/deploy/lambda/setup-lambda.sh @@ -0,0 +1,132 @@ +#!/bin/bash + +# Quick setup script for PipeCD Lambda Tutorial +# This script helps you get started with Lambda deployment quickly + +set -e + +echo "🚀 PipeCD Lambda Tutorial Setup" +echo "================================" + +# Check prerequisites +echo "📋 Checking prerequisites..." + +# Check AWS CLI +if ! command -v aws &> /dev/null; then + echo "❌ AWS CLI not found. Please install AWS CLI first." + exit 1 +fi + +# Check Python +if ! command -v python3 &> /dev/null; then + echo "❌ Python 3 not found. Please install Python 3.9+ first." + exit 1 +fi + +# Check if AWS is configured +if ! aws sts get-caller-identity &> /dev/null; then + echo "❌ AWS CLI not configured. Please run 'aws configure' first." + exit 1 +fi + +echo "✅ Prerequisites check passed!" + +# Get user inputs +echo "" +echo "📝 Configuration" +echo "==================" + +read -p "Enter your S3 bucket name for Lambda packages: " S3_BUCKET +read -p "Enter your Lambda execution role ARN: " LAMBDA_ROLE + +# Validate inputs +if [ -z "$S3_BUCKET" ] || [ -z "$LAMBDA_ROLE" ]; then + echo "❌ S3 bucket name and Lambda role ARN are required." + exit 1 +fi + +# Check if S3 bucket exists +if ! aws s3 ls "s3://$S3_BUCKET" &> /dev/null; then + echo "⚠️ S3 bucket '$S3_BUCKET' not found or not accessible." + read -p "Do you want to create it? (y/n): " CREATE_BUCKET + if [ "$CREATE_BUCKET" = "y" ] || [ "$CREATE_BUCKET" = "Y" ]; then + echo "Creating S3 bucket..." + aws s3 mb "s3://$S3_BUCKET" + echo "✅ S3 bucket created successfully!" + else + echo "❌ Please create the S3 bucket first or check permissions." + exit 1 + fi +fi + +# Build and deploy simple function +echo "" +echo "🏗️ Building Simple Lambda Function" +echo "====================================" + +cd simple/ + +# Update function.yaml +echo "Updating function.yaml..." +sed -i.bak "s||$S3_BUCKET|g" function.yaml +sed -i.bak "s||lambda/pipecd-tutorial-simple.zip|g" function.yaml +sed -i.bak "s||$LAMBDA_ROLE|g" function.yaml + +# Build package +echo "Building package..." +chmod +x build.sh +./build.sh + +# Upload to S3 +echo "Uploading to S3..." +aws s3 cp pipecd-tutorial-simple.zip "s3://$S3_BUCKET/lambda/pipecd-tutorial-simple.zip" + +echo "✅ Simple function setup complete!" + +# Build and deploy canary function +echo "" +echo "🏗️ Building Canary Lambda Function" +echo "====================================" + +cd ../canary/ + +# Update function.yaml +echo "Updating function.yaml..." +sed -i.bak "s||$S3_BUCKET|g" function.yaml +sed -i.bak "s||lambda/pipecd-tutorial-canary.zip|g" function.yaml +sed -i.bak "s||$LAMBDA_ROLE|g" function.yaml + +# Build package +echo "Building package..." +chmod +x build.sh +./build.sh + +# Upload to S3 +echo "Uploading to S3..." +aws s3 cp pipecd-tutorial-canary.zip "s3://$S3_BUCKET/lambda/pipecd-tutorial-canary.zip" + +echo "✅ Canary function setup complete!" + +# Summary +echo "" +echo "🎉 Setup Complete!" +echo "==================" +echo "✅ Both Lambda functions are built and uploaded to S3" +echo "✅ Configuration files are updated" +echo "" +echo "📋 Next Steps:" +echo "1. Commit and push your changes to Git" +echo "2. Register the applications in PipeCD console" +echo "3. Watch the deployment progress" +echo "" +echo "📁 Files created:" +echo "- simple/pipecd-tutorial-simple.zip" +echo "- canary/pipecd-tutorial-canary.zip" +echo "" +echo "☁️ S3 Objects:" +echo "- s3://$S3_BUCKET/lambda/pipecd-tutorial-simple.zip" +echo "- s3://$S3_BUCKET/lambda/pipecd-tutorial-canary.zip" +echo "" +echo "📚 For more information, see:" +echo "- README.md" +echo "- DEPLOYMENT_GUIDE.md" diff --git a/src/deploy/lambda/simple/build.bat b/src/deploy/lambda/simple/build.bat new file mode 100644 index 0000000..afacce0 --- /dev/null +++ b/src/deploy/lambda/simple/build.bat @@ -0,0 +1,56 @@ +@echo off +REM Build script for PipeCD Tutorial Lambda Function (Windows) +REM This script packages the Lambda function code into a zip file + +echo Building PipeCD Tutorial Lambda Function... + +REM Set variables +set BUILD_DIR=build +set FUNCTION_NAME=pipecd-tutorial-simple +set ZIP_FILE=%FUNCTION_NAME%.zip + +REM Clean previous build +if exist "%BUILD_DIR%" ( + echo Cleaning previous build... + rmdir /s /q "%BUILD_DIR%" +) + +if exist "%ZIP_FILE%" ( + echo Removing previous zip file... + del "%ZIP_FILE%" +) + +REM Create build directory +mkdir "%BUILD_DIR%" + +REM Copy source code +echo Copying source code... +copy "src\index.py" "%BUILD_DIR%\" + +REM Check if requirements.txt has actual dependencies +findstr /v "^#" "src\requirements.txt" | findstr /v "^$" > nul +if %errorlevel% equ 0 ( + echo Installing Python dependencies... + pip install -r src\requirements.txt -t %BUILD_DIR% +) else ( + echo No dependencies to install (using only standard library) +) + +REM Create zip file +echo Creating zip package... +cd "%BUILD_DIR%" +powershell -command "Compress-Archive -Path * -DestinationPath '..\%ZIP_FILE%' -Force" +cd .. + +REM Cleanup build directory +rmdir /s /q "%BUILD_DIR%" + +echo ✅ Lambda function packaged successfully: %ZIP_FILE% +for %%A in ("%ZIP_FILE%") do echo 📦 Package size: %%~zA bytes +echo. +echo Next steps: +echo 1. Upload %ZIP_FILE% to an S3 bucket +echo 2. Update function.yaml with the S3 bucket and key +echo 3. Deploy using PipeCD + +pause diff --git a/src/deploy/lambda/simple/build.sh b/src/deploy/lambda/simple/build.sh new file mode 100644 index 0000000..1ba3a2d --- /dev/null +++ b/src/deploy/lambda/simple/build.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Build script for PipeCD Tutorial Lambda Function +# This script packages the Lambda function code into a zip file + +set -e + +echo "Building PipeCD Tutorial Lambda Function..." + +# Create build directory +BUILD_DIR="build" +FUNCTION_NAME="pipecd-tutorial-simple" +ZIP_FILE="${FUNCTION_NAME}.zip" + +# Clean previous build +if [ -d "$BUILD_DIR" ]; then + echo "Cleaning previous build..." + rm -rf "$BUILD_DIR" +fi + +if [ -f "$ZIP_FILE" ]; then + echo "Removing previous zip file..." + rm "$ZIP_FILE" +fi + +# Create build directory +mkdir -p "$BUILD_DIR" + +# Copy source code +echo "Copying source code..." +cp src/index.py "$BUILD_DIR/" + +# Install dependencies if requirements.txt has actual dependencies +if [ -f "src/requirements.txt" ] && [ -s "src/requirements.txt" ] && grep -v '^#' src/requirements.txt | grep -v '^$' > /dev/null; then + echo "Installing Python dependencies..." + pip install -r src/requirements.txt -t "$BUILD_DIR/" +else + echo "No dependencies to install (using only standard library)" +fi + +# Create zip file +echo "Creating zip package..." +cd "$BUILD_DIR" +zip -r "../$ZIP_FILE" . +cd .. + +# Cleanup build directory +rm -rf "$BUILD_DIR" + +echo "✅ Lambda function packaged successfully: $ZIP_FILE" +echo "📦 Package size: $(du -h "$ZIP_FILE" | cut -f1)" +echo "" +echo "Next steps:" +echo "1. Upload $ZIP_FILE to an S3 bucket" +echo "2. Update function.yaml with the S3 bucket and key" +echo "3. Deploy using PipeCD" diff --git a/src/deploy/lambda/simple/function.yaml b/src/deploy/lambda/simple/function.yaml index 7174d51..e6dd727 100644 --- a/src/deploy/lambda/simple/function.yaml +++ b/src/deploy/lambda/simple/function.yaml @@ -4,6 +4,13 @@ kind: LambdaFunction spec: name: PipeCDTutorial_Simple role: # [EDIT_HERE] The ARN of the function’s execution role. - image: # [EDIT_HERE] The URI of a container image in your ECR repository. + # Using zip deployment instead of container image for simpler setup + source: + s3Bucket: # [EDIT_HERE] S3 bucket containing your zip file + s3Key: # [EDIT_HERE] S3 key path to your zip file (e.g., lambda/pipecd-tutorial-simple.zip) + runtime: python3.9 + handler: index.lambda_handler memory: 512 - timeout: 30 \ No newline at end of file + timeout: 30 + environment: + FUNCTION_VERSION: "v1.0.0" \ No newline at end of file diff --git a/src/deploy/lambda/simple/src/index.py b/src/deploy/lambda/simple/src/index.py new file mode 100644 index 0000000..44d1cd7 --- /dev/null +++ b/src/deploy/lambda/simple/src/index.py @@ -0,0 +1,76 @@ +""" +Simple Lambda function for PipeCD Tutorial + +This is a basic Lambda function that demonstrates deployment with PipeCD. +It returns a simple JSON response with a greeting message. +""" + +import json +import os +from datetime import datetime, timezone + + +def lambda_handler(event, context): + """ + AWS Lambda handler function + + Args: + event: The event dict that contains the request data + context: The context object that contains runtime information + + Returns: + dict: Response object with statusCode, headers, and body + """ + + # Get environment variables + function_name = context.function_name if context else "unknown" + version = os.environ.get('FUNCTION_VERSION', 'v1.0.0') + + # Create response message + message = { + "greeting": "Hello from PipeCD Tutorial Lambda!", + "function_name": function_name, + "version": version, + "timestamp": datetime.now(timezone.utc).isoformat(), + "event_info": { + "http_method": event.get("httpMethod", "N/A"), + "path": event.get("path", "N/A"), + "query_params": event.get("queryStringParameters") or {} + } + } + + # Log the request + print(f"Processing request for {function_name} version {version}") + print(f"Event: {json.dumps(event, default=str)}") + + # Return response + response = { + "statusCode": 200, + "headers": { + "Content-Type": "application/json", + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Methods": "GET, POST, OPTIONS" + }, + "body": json.dumps(message, indent=2) + } + + return response + + +# For local testing +if __name__ == "__main__": + # Test event + test_event = { + "httpMethod": "GET", + "path": "/test", + "queryStringParameters": {"name": "PipeCD"} + } + + # Mock context + class MockContext: + function_name = "pipecd-tutorial-local" + + result = lambda_handler(test_event, MockContext()) + print("Test result:") + print(json.dumps(result, indent=2)) From c0b5cc3da1cf95af28e2cdd0e2b12cd8ccfbf896 Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Thu, 10 Jul 2025 02:28:36 +0530 Subject: [PATCH 2/7] updated some necessarry changes --- src/deploy/lambda/canary/build.sh | 11 ++++++++++- src/deploy/lambda/simple/build.sh | 11 ++++++++++- src/deploy/lambda/simple/src/requirements.txt | 13 +++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/deploy/lambda/simple/src/requirements.txt diff --git a/src/deploy/lambda/canary/build.sh b/src/deploy/lambda/canary/build.sh index b0c4ed4..87df1a4 100644 --- a/src/deploy/lambda/canary/build.sh +++ b/src/deploy/lambda/canary/build.sh @@ -41,7 +41,16 @@ fi # Create zip file echo "Creating zip package..." cd "$BUILD_DIR" -zip -r "../$ZIP_FILE" . + +# Check if we're on Windows (Git Bash) and use PowerShell for zip +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then + # Use PowerShell to create zip on Windows + powershell.exe -command "Compress-Archive -Path * -DestinationPath '../$ZIP_FILE' -Force" +else + # Use standard zip command on Linux/Mac + zip -r "../$ZIP_FILE" . +fi + cd .. # Cleanup build directory diff --git a/src/deploy/lambda/simple/build.sh b/src/deploy/lambda/simple/build.sh index 1ba3a2d..29568c1 100644 --- a/src/deploy/lambda/simple/build.sh +++ b/src/deploy/lambda/simple/build.sh @@ -41,7 +41,16 @@ fi # Create zip file echo "Creating zip package..." cd "$BUILD_DIR" -zip -r "../$ZIP_FILE" . + +# Check if we're on Windows (Git Bash) and use PowerShell for zip +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then + # Use PowerShell to create zip on Windows + powershell.exe -command "Compress-Archive -Path * -DestinationPath '../$ZIP_FILE' -Force" +else + # Use standard zip command on Linux/Mac + zip -r "../$ZIP_FILE" . +fi + cd .. # Cleanup build directory diff --git a/src/deploy/lambda/simple/src/requirements.txt b/src/deploy/lambda/simple/src/requirements.txt new file mode 100644 index 0000000..3a4018f --- /dev/null +++ b/src/deploy/lambda/simple/src/requirements.txt @@ -0,0 +1,13 @@ +# Requirements for PipeCD Tutorial Lambda Function +# This file lists the Python dependencies needed for the Lambda function + +# No external dependencies required for this simple example +# The function only uses Python standard library modules: +# - json (built-in) +# - os (built-in) +# - datetime (built-in) + +# If you need to add dependencies in the future, list them here +# For example: +# requests==2.31.0 +# boto3==1.34.0 From 76a1c4d126ea9d41e401bd3379dceef797cb01ce Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Thu, 10 Jul 2025 12:48:04 +0530 Subject: [PATCH 3/7] made a procedure without building and pushing to s3 --- content/en/20-prerequisites/README.md | 2 - content/en/40-deploy/01-simply.md | 6 +- content/en/40-deploy/02-pipeline.md | 4 +- content/ja/20-prerequisites/README.md | 2 - content/ja/40-deploy/01-simply.md | 8 +- content/ja/40-deploy/02-pipeline.md | 4 +- src/deploy/lambda/DEPLOYMENT_GUIDE.md | 231 ------------------------- src/deploy/lambda/README.md | 71 +++----- src/deploy/lambda/canary/build.bat | 56 ------ src/deploy/lambda/canary/build.sh | 65 ------- src/deploy/lambda/canary/function.yaml | 9 +- src/deploy/lambda/setup-lambda.bat | 154 ----------------- src/deploy/lambda/setup-lambda.sh | 132 -------------- src/deploy/lambda/simple/build.bat | 56 ------ src/deploy/lambda/simple/build.sh | 65 ------- src/deploy/lambda/simple/function.yaml | 9 +- 16 files changed, 37 insertions(+), 837 deletions(-) delete mode 100644 src/deploy/lambda/DEPLOYMENT_GUIDE.md delete mode 100644 src/deploy/lambda/canary/build.bat delete mode 100644 src/deploy/lambda/canary/build.sh delete mode 100644 src/deploy/lambda/setup-lambda.bat delete mode 100644 src/deploy/lambda/setup-lambda.sh delete mode 100644 src/deploy/lambda/simple/build.bat delete mode 100644 src/deploy/lambda/simple/build.sh diff --git a/content/en/20-prerequisites/README.md b/content/en/20-prerequisites/README.md index 92182b1..0891be1 100644 --- a/content/en/20-prerequisites/README.md +++ b/content/en/20-prerequisites/README.md @@ -23,9 +23,7 @@ To perform this tutorial, you need the following: - for **AWS Lambda**: - You can call APIs of Lambda from your local to your AWS account. See [here](https://pipecd.dev/docs/installation/install-piped/required-permissions/#for-lambdaapp) for details. - You have all of (i.e. all you need to create a Lambda function): - - an S3 bucket for storing Lambda zip files - function’s execution role - - Python 3.9+ installed locally (for building the function package) - for **Terraform**: - You can execute [`terraform` commands](https://developer.hashicorp.com/terraform/cli/commands) on local. diff --git a/content/en/40-deploy/01-simply.md b/content/en/40-deploy/01-simply.md index c6e8fb5..9cdf3fd 100644 --- a/content/en/40-deploy/01-simply.md +++ b/content/en/40-deploy/01-simply.md @@ -22,11 +22,9 @@ In this page, you will deploy an application to your platform in a simple way. - `servicedef.yaml`: Edit `cluster`, `securityGroups`, and `subnets`. - `taskdef.yaml`: Edit `executionRoleArn`. - For **AWS Lambda**: - - You will create a function using a simple Python source code package. + - You will create a function using simple Python source code. - Edit `lambda/simple/` as below. - - Build the function package: Run `./build.sh` (Linux/Mac) or `build.bat` (Windows) - - Upload the generated zip file to your S3 bucket - - `function.yaml`: Edit `role`, `s3Bucket`, and `s3Key` + - `function.yaml`: Edit `role` only (PipeCD automatically packages and deploys your source code) - For **Terraform**: - You will generate a file on local. - Edit `terraform/simple/` as below. diff --git a/content/en/40-deploy/02-pipeline.md b/content/en/40-deploy/02-pipeline.md index f854a6d..2d58d2c 100644 --- a/content/en/40-deploy/02-pipeline.md +++ b/content/en/40-deploy/02-pipeline.md @@ -23,9 +23,7 @@ _The process is almost the same as [1. Deploy Simply](01-simply.md). Only the co - For **AWS Lambda**: - You will create a function using source code with Canary release strategy. - Edit `lambda/canary/` as below. - - Build the canary function package: Run `./build.sh` (Linux/Mac) or `build.bat` (Windows) - - Upload the generated zip file to your S3 bucket - - `function.yaml`: Edit `role`, `s3Bucket`, and `s3Key` (the function name is already different from simple) + - `function.yaml`: Edit `role` only (PipeCD automatically packages and deploys your source code) - For **Terraform**: - You will generate a file on local with plan->approval->apply pipeline. - Edit `terraform/plan-approval-apply/` as below. diff --git a/content/ja/20-prerequisites/README.md b/content/ja/20-prerequisites/README.md index b60cfd8..8e05338 100644 --- a/content/ja/20-prerequisites/README.md +++ b/content/ja/20-prerequisites/README.md @@ -23,9 +23,7 @@ - **AWS Lambda**向け: - ローカルからあなたのAWSアカウントに対して、Lambdaの各種APIを実行できること。詳細は[こちら](https://pipecd.dev/docs/installation/install-piped/required-permissions/#for-lambdaapp)。 - 下記のすべて。(一般的なLambda関数を作る際に必要なものと同じです) - - Lambdaのzipファイルを保存するためのS3バケット - 関数の実行ロール - - Python 3.9+がローカルにインストールされていること(関数パッケージのビルド用) - **Terraform**向け: - [`terraform` commands](https://developer.hashicorp.com/terraform/cli/commands)をローカルから実行できること。 diff --git a/content/ja/40-deploy/01-simply.md b/content/ja/40-deploy/01-simply.md index f0c2e01..0620c95 100644 --- a/content/ja/40-deploy/01-simply.md +++ b/content/ja/40-deploy/01-simply.md @@ -22,11 +22,9 @@ - `servicedef.yaml`: `cluster`, `securityGroups`, `subnets` - `taskdef.yaml`: `executionRoleArn`. - **AWS Lambda**向け: - - シンプルなPythonソースコードパッケージを使用して関数をデプロイしていきます。 - - `lambda/simple/`の以下の手順を実行してください。 - - 関数パッケージをビルド: `./build.sh` (Linux/Mac) または `build.bat` (Windows) を実行 - - 生成されたzipファイルをS3バケットにアップロード - - `function.yaml`: `role`, `s3Bucket`, `s3Key` を編集 + - シンプルなPythonソースコードを使用して関数をデプロイしていきます。 + - `lambda/simple/`の以下の箇所を編集してください。 + - `function.yaml`: `role` のみ編集(PipeCDが自動的にソースコードをパッケージ化してデプロイします) - **Terraform**向け: - ファイルをローカルに生成していきます。 - `terraform/simple/`の以下の箇所を編集してください。 diff --git a/content/ja/40-deploy/02-pipeline.md b/content/ja/40-deploy/02-pipeline.md index a335ad3..3427fa2 100644 --- a/content/ja/40-deploy/02-pipeline.md +++ b/content/ja/40-deploy/02-pipeline.md @@ -23,9 +23,7 @@ _手順は[1. シンプルなデプロイ](01-simply.md)とほとんど同じで - **AWS Lambda**向け: - ソースコードを使用して関数をCanaryリリースしていきます。 - `lambda/canary/`を以下のように編集してください。 - - Canary関数パッケージをビルド: `./build.sh` (Linux/Mac) または `build.bat` (Windows) を実行 - - 生成されたzipファイルをS3バケットにアップロード - - `function.yaml`: `role`, `s3Bucket`, `s3Key` を編集(関数名は既にsimpleと異なります) + - `function.yaml`: `role` のみ編集(PipeCDが自動的にソースコードをパッケージ化してデプロイします) - `function.yaml`: `/src/deploy/lambda/simple/function.yaml`からコピーして、`name`を変更 - **Terraform**向け: - ファイルをローカルに生成していきます。plan->承認->applyのパイプラインを構築します。 diff --git a/src/deploy/lambda/DEPLOYMENT_GUIDE.md b/src/deploy/lambda/DEPLOYMENT_GUIDE.md deleted file mode 100644 index 7556eb6..0000000 --- a/src/deploy/lambda/DEPLOYMENT_GUIDE.md +++ /dev/null @@ -1,231 +0,0 @@ -# 🚀 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) diff --git a/src/deploy/lambda/README.md b/src/deploy/lambda/README.md index 9b0baca..cd70e36 100644 --- a/src/deploy/lambda/README.md +++ b/src/deploy/lambda/README.md @@ -1,6 +1,6 @@ # Lambda Deployment with PipeCD Tutorial -This directory contains examples for deploying AWS Lambda functions using PipeCD with **zip file deployment** instead of container images, making it much easier to get started. +This directory contains examples for deploying AWS Lambda functions using PipeCD with **direct source code deployment** instead of container images, making it much easier to get started. ## 🎯 What's New (Issue #16) @@ -11,9 +11,9 @@ Previously, the Lambda tutorial required: Now it uses: - ✅ Simple Python source code -- ✅ Zip file packaging -- ✅ Direct S3 upload -- ✅ Minimal prerequisites +- ✅ **Automatic packaging by PipeCD** +- ✅ **No manual zip building or S3 uploads** +- ✅ Minimal prerequisites (just an IAM role) ## 📁 Directory Structure @@ -24,17 +24,13 @@ lambda/ │ │ ├── index.py # Lambda function source code │ │ └── requirements.txt # Python dependencies │ ├── function.yaml # Lambda function configuration -│ ├── app.pipecd.yaml # PipeCD application config -│ ├── build.sh # Build script (Linux/Mac) -│ └── build.bat # Build script (Windows) +│ └── app.pipecd.yaml # PipeCD application config ├── canary/ # Canary deployment example │ ├── src/ │ │ ├── index.py # Enhanced Lambda function │ │ └── requirements.txt # Python dependencies │ ├── function.yaml # Lambda function configuration -│ ├── app.pipecd.yaml # PipeCD canary pipeline config -│ ├── build.sh # Build script (Linux/Mac) -│ └── build.bat # Build script (Windows) +│ └── app.pipecd.yaml # PipeCD canary pipeline config └── README.md # This file ``` @@ -43,34 +39,9 @@ lambda/ ### Prerequisites 1. **AWS CLI configured** with appropriate permissions -2. **S3 bucket** for storing Lambda zip files -3. **IAM role** for Lambda execution -4. **Python 3.9+** (for local testing) +2. **IAM role** for Lambda execution -### Step 1: Build the Lambda Package - -**Linux/Mac:** -```bash -cd simple/ -chmod +x build.sh -./build.sh -``` - -**Windows:** -```cmd -cd simple\ -build.bat -``` - -This creates `pipecd-tutorial-simple.zip` containing your Lambda function. - -### Step 2: Upload to S3 - -```bash -aws s3 cp pipecd-tutorial-simple.zip s3://your-bucket-name/lambda/pipecd-tutorial-simple.zip -``` - -### Step 3: Configure function.yaml +### Step 1: Configure function.yaml Edit `simple/function.yaml`: @@ -79,16 +50,22 @@ spec: name: PipeCDTutorial_Simple role: arn:aws:iam::123456789012:role/lambda-execution-role source: - s3Bucket: your-bucket-name - s3Key: lambda/pipecd-tutorial-simple.zip + git: "" # Empty means same repository + ref: "" # Empty means current commit + path: "src" # Path to source code directory runtime: python3.9 handler: index.lambda_handler ``` -### Step 4: Deploy with PipeCD +### Step 2: Deploy with PipeCD Follow the main tutorial instructions to register and deploy the application. +**That's it!** PipeCD will automatically: +- Package your source code into a zip file +- Deploy it to AWS Lambda +- Handle all the complexity for you + ## 📋 Function Details ### Simple Function (`simple/src/index.py`) @@ -115,16 +92,13 @@ Follow the main tutorial instructions to register and deploy the application. boto3==1.34.0 ``` -2. Rebuild the package: - ```bash - ./build.sh - ``` +2. Commit and push - PipeCD will automatically install dependencies during packaging ### Modifying the Function 1. Edit `src/index.py` with your custom logic 2. Test locally: `python src/index.py` -3. Rebuild and redeploy +3. Commit and push - PipeCD handles the rest ### Environment Variables @@ -163,15 +137,10 @@ This runs the function with a test event and displays the output. ## 🔍 Troubleshooting -### Build Issues -- Ensure Python 3.9+ is installed -- Check file permissions on build scripts -- Verify requirements.txt syntax - ### Deployment Issues -- Confirm S3 bucket permissions - Verify IAM role has Lambda execution permissions - Check function.yaml syntax +- Ensure source code is in the correct directory structure ### Runtime Issues - Review CloudWatch logs diff --git a/src/deploy/lambda/canary/build.bat b/src/deploy/lambda/canary/build.bat deleted file mode 100644 index 4abcfd2..0000000 --- a/src/deploy/lambda/canary/build.bat +++ /dev/null @@ -1,56 +0,0 @@ -@echo off -REM Build script for PipeCD Tutorial Lambda Function (Canary) - Windows -REM This script packages the canary Lambda function code into a zip file - -echo Building PipeCD Tutorial Lambda Function (Canary)... - -REM Set variables -set BUILD_DIR=build -set FUNCTION_NAME=pipecd-tutorial-canary -set ZIP_FILE=%FUNCTION_NAME%.zip - -REM Clean previous build -if exist "%BUILD_DIR%" ( - echo Cleaning previous build... - rmdir /s /q "%BUILD_DIR%" -) - -if exist "%ZIP_FILE%" ( - echo Removing previous zip file... - del "%ZIP_FILE%" -) - -REM Create build directory -mkdir "%BUILD_DIR%" - -REM Copy source code -echo Copying source code... -copy "src\index.py" "%BUILD_DIR%\" - -REM Check if requirements.txt has actual dependencies -findstr /v "^#" "src\requirements.txt" | findstr /v "^$" > nul -if %errorlevel% equ 0 ( - echo Installing Python dependencies... - pip install -r src\requirements.txt -t %BUILD_DIR% -) else ( - echo No dependencies to install (using only standard library) -) - -REM Create zip file -echo Creating zip package... -cd "%BUILD_DIR%" -powershell -command "Compress-Archive -Path * -DestinationPath '..\%ZIP_FILE%' -Force" -cd .. - -REM Cleanup build directory -rmdir /s /q "%BUILD_DIR%" - -echo ✅ Canary Lambda function packaged successfully: %ZIP_FILE% -for %%A in ("%ZIP_FILE%") do echo 📦 Package size: %%~zA bytes -echo. -echo Next steps: -echo 1. Upload %ZIP_FILE% to an S3 bucket -echo 2. Update function.yaml with the S3 bucket and key -echo 3. Deploy using PipeCD canary pipeline - -pause diff --git a/src/deploy/lambda/canary/build.sh b/src/deploy/lambda/canary/build.sh deleted file mode 100644 index 87df1a4..0000000 --- a/src/deploy/lambda/canary/build.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -# Build script for PipeCD Tutorial Lambda Function (Canary) -# This script packages the canary Lambda function code into a zip file - -set -e - -echo "Building PipeCD Tutorial Lambda Function (Canary)..." - -# Create build directory -BUILD_DIR="build" -FUNCTION_NAME="pipecd-tutorial-canary" -ZIP_FILE="${FUNCTION_NAME}.zip" - -# Clean previous build -if [ -d "$BUILD_DIR" ]; then - echo "Cleaning previous build..." - rm -rf "$BUILD_DIR" -fi - -if [ -f "$ZIP_FILE" ]; then - echo "Removing previous zip file..." - rm "$ZIP_FILE" -fi - -# Create build directory -mkdir -p "$BUILD_DIR" - -# Copy source code -echo "Copying source code..." -cp src/index.py "$BUILD_DIR/" - -# Install dependencies if requirements.txt has actual dependencies -if [ -f "src/requirements.txt" ] && [ -s "src/requirements.txt" ] && grep -v '^#' src/requirements.txt | grep -v '^$' > /dev/null; then - echo "Installing Python dependencies..." - pip install -r src/requirements.txt -t "$BUILD_DIR/" -else - echo "No dependencies to install (using only standard library)" -fi - -# Create zip file -echo "Creating zip package..." -cd "$BUILD_DIR" - -# Check if we're on Windows (Git Bash) and use PowerShell for zip -if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then - # Use PowerShell to create zip on Windows - powershell.exe -command "Compress-Archive -Path * -DestinationPath '../$ZIP_FILE' -Force" -else - # Use standard zip command on Linux/Mac - zip -r "../$ZIP_FILE" . -fi - -cd .. - -# Cleanup build directory -rm -rf "$BUILD_DIR" - -echo "✅ Canary Lambda function packaged successfully: $ZIP_FILE" -echo "📦 Package size: $(du -h "$ZIP_FILE" | cut -f1)" -echo "" -echo "Next steps:" -echo "1. Upload $ZIP_FILE to an S3 bucket" -echo "2. Update function.yaml with the S3 bucket and key" -echo "3. Deploy using PipeCD canary pipeline" diff --git a/src/deploy/lambda/canary/function.yaml b/src/deploy/lambda/canary/function.yaml index ec1653c..5c4312c 100644 --- a/src/deploy/lambda/canary/function.yaml +++ b/src/deploy/lambda/canary/function.yaml @@ -2,12 +2,13 @@ apiVersion: pipecd.dev/v1beta1 kind: LambdaFunction spec: - name: PipeCDTutorial_Canary + name: CanaryZipFunction role: # [EDIT_HERE] The ARN of the function’s execution role. - # Using zip deployment instead of container image for simpler setup + # Using PipeCD's built-in source code packaging - no manual zip building or S3 uploads needed! source: - s3Bucket: # [EDIT_HERE] S3 bucket containing your zip file - s3Key: # [EDIT_HERE] S3 key path to your zip file (e.g., lambda/pipecd-tutorial-canary.zip) + git: "" # Empty means same repository + ref: "" # Empty means current commit + path: "src" # Path to source code directory relative to this function.yaml runtime: python3.9 handler: index.lambda_handler memory: 512 diff --git a/src/deploy/lambda/setup-lambda.bat b/src/deploy/lambda/setup-lambda.bat deleted file mode 100644 index ab41d14..0000000 --- a/src/deploy/lambda/setup-lambda.bat +++ /dev/null @@ -1,154 +0,0 @@ -@echo off -REM Quick setup script for PipeCD Lambda Tutorial (Windows) -REM This script helps you get started with Lambda deployment quickly - -echo 🚀 PipeCD Lambda Tutorial Setup -echo ================================ - -REM Check prerequisites -echo 📋 Checking prerequisites... - -REM Check AWS CLI -aws --version >nul 2>nul -if %errorlevel% neq 0 ( - echo ❌ AWS CLI not found or not working. Please install AWS CLI first. - echo 💡 You can install it from: https://aws.amazon.com/cli/ - echo 💡 Or try: winget install Amazon.AWSCLI - pause - exit /b 1 -) - -REM Check Python -python --version >nul 2>nul -if %errorlevel% neq 0 ( - echo ❌ Python not found. Please install Python 3.9+ first. - echo 💡 You can install it from: https://python.org/downloads/ - echo 💡 Or try: winget install Python.Python.3.12 - pause - exit /b 1 -) - -REM Check if AWS is configured -aws sts get-caller-identity >nul 2>nul -if %errorlevel% neq 0 ( - echo ❌ AWS CLI not configured. Please run 'aws configure' first. - pause - exit /b 1 -) - -echo ✅ Prerequisites check passed! - -REM Get user inputs -echo. -echo 📝 Configuration -echo ================== - -set /p S3_BUCKET="Enter your S3 bucket name for Lambda packages: " -set /p LAMBDA_ROLE="Enter your Lambda execution role ARN: " - -REM Validate inputs -if "%S3_BUCKET%"=="" ( - echo ❌ S3 bucket name is required. - pause - exit /b 1 -) - -if "%LAMBDA_ROLE%"=="" ( - echo ❌ Lambda role ARN is required. - pause - exit /b 1 -) - -REM Check if S3 bucket exists -aws s3 ls "s3://%S3_BUCKET%" >nul 2>nul -if %errorlevel% neq 0 ( - echo ⚠️ S3 bucket '%S3_BUCKET%' not found or not accessible. - set /p CREATE_BUCKET="Do you want to create it? (y/n): " - if /i "%CREATE_BUCKET%"=="y" ( - echo Creating S3 bucket... - aws s3 mb "s3://%S3_BUCKET%" - if %errorlevel% equ 0 ( - echo ✅ S3 bucket created successfully! - ) else ( - echo ❌ Failed to create S3 bucket. - pause - exit /b 1 - ) - ) else ( - echo ❌ Please create the S3 bucket first or check permissions. - pause - exit /b 1 - ) -) - -REM Build and deploy simple function -echo. -echo 🏗️ Building Simple Lambda Function -echo ==================================== - -cd simple - -REM Update function.yaml -echo Updating function.yaml... -powershell -command "(Get-Content function.yaml) -replace '', '%S3_BUCKET%' | Set-Content function.yaml" -powershell -command "(Get-Content function.yaml) -replace '', 'lambda/pipecd-tutorial-simple.zip' | Set-Content function.yaml" -powershell -command "(Get-Content function.yaml) -replace '', '%LAMBDA_ROLE%' | Set-Content function.yaml" - -REM Build package -echo Building package... -call build.bat - -REM Upload to S3 -echo Uploading to S3... -aws s3 cp pipecd-tutorial-simple.zip "s3://%S3_BUCKET%/lambda/pipecd-tutorial-simple.zip" - -echo ✅ Simple function setup complete! - -REM Build and deploy canary function -echo. -echo 🏗️ Building Canary Lambda Function -echo ==================================== - -cd ..\canary - -REM Update function.yaml -echo Updating function.yaml... -powershell -command "(Get-Content function.yaml) -replace '', '%S3_BUCKET%' | Set-Content function.yaml" -powershell -command "(Get-Content function.yaml) -replace '', 'lambda/pipecd-tutorial-canary.zip' | Set-Content function.yaml" -powershell -command "(Get-Content function.yaml) -replace '', '%LAMBDA_ROLE%' | Set-Content function.yaml" - -REM Build package -echo Building package... -call build.bat - -REM Upload to S3 -echo Uploading to S3... -aws s3 cp pipecd-tutorial-canary.zip "s3://%S3_BUCKET%/lambda/pipecd-tutorial-canary.zip" - -echo ✅ Canary function setup complete! - -REM Summary -echo. -echo 🎉 Setup Complete! -echo ================== -echo ✅ Both Lambda functions are built and uploaded to S3 -echo ✅ Configuration files are updated -echo. -echo 📋 Next Steps: -echo 1. Commit and push your changes to Git -echo 2. Register the applications in PipeCD console -echo 3. Watch the deployment progress -echo. -echo 📁 Files created: -echo - simple\pipecd-tutorial-simple.zip -echo - canary\pipecd-tutorial-canary.zip -echo. -echo ☁️ S3 Objects: -echo - s3://%S3_BUCKET%/lambda/pipecd-tutorial-simple.zip -echo - s3://%S3_BUCKET%/lambda/pipecd-tutorial-canary.zip -echo. -echo 📚 For more information, see: -echo - README.md -echo - DEPLOYMENT_GUIDE.md - -pause diff --git a/src/deploy/lambda/setup-lambda.sh b/src/deploy/lambda/setup-lambda.sh deleted file mode 100644 index 0af3a00..0000000 --- a/src/deploy/lambda/setup-lambda.sh +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/bash - -# Quick setup script for PipeCD Lambda Tutorial -# This script helps you get started with Lambda deployment quickly - -set -e - -echo "🚀 PipeCD Lambda Tutorial Setup" -echo "================================" - -# Check prerequisites -echo "📋 Checking prerequisites..." - -# Check AWS CLI -if ! command -v aws &> /dev/null; then - echo "❌ AWS CLI not found. Please install AWS CLI first." - exit 1 -fi - -# Check Python -if ! command -v python3 &> /dev/null; then - echo "❌ Python 3 not found. Please install Python 3.9+ first." - exit 1 -fi - -# Check if AWS is configured -if ! aws sts get-caller-identity &> /dev/null; then - echo "❌ AWS CLI not configured. Please run 'aws configure' first." - exit 1 -fi - -echo "✅ Prerequisites check passed!" - -# Get user inputs -echo "" -echo "📝 Configuration" -echo "==================" - -read -p "Enter your S3 bucket name for Lambda packages: " S3_BUCKET -read -p "Enter your Lambda execution role ARN: " LAMBDA_ROLE - -# Validate inputs -if [ -z "$S3_BUCKET" ] || [ -z "$LAMBDA_ROLE" ]; then - echo "❌ S3 bucket name and Lambda role ARN are required." - exit 1 -fi - -# Check if S3 bucket exists -if ! aws s3 ls "s3://$S3_BUCKET" &> /dev/null; then - echo "⚠️ S3 bucket '$S3_BUCKET' not found or not accessible." - read -p "Do you want to create it? (y/n): " CREATE_BUCKET - if [ "$CREATE_BUCKET" = "y" ] || [ "$CREATE_BUCKET" = "Y" ]; then - echo "Creating S3 bucket..." - aws s3 mb "s3://$S3_BUCKET" - echo "✅ S3 bucket created successfully!" - else - echo "❌ Please create the S3 bucket first or check permissions." - exit 1 - fi -fi - -# Build and deploy simple function -echo "" -echo "🏗️ Building Simple Lambda Function" -echo "====================================" - -cd simple/ - -# Update function.yaml -echo "Updating function.yaml..." -sed -i.bak "s||$S3_BUCKET|g" function.yaml -sed -i.bak "s||lambda/pipecd-tutorial-simple.zip|g" function.yaml -sed -i.bak "s||$LAMBDA_ROLE|g" function.yaml - -# Build package -echo "Building package..." -chmod +x build.sh -./build.sh - -# Upload to S3 -echo "Uploading to S3..." -aws s3 cp pipecd-tutorial-simple.zip "s3://$S3_BUCKET/lambda/pipecd-tutorial-simple.zip" - -echo "✅ Simple function setup complete!" - -# Build and deploy canary function -echo "" -echo "🏗️ Building Canary Lambda Function" -echo "====================================" - -cd ../canary/ - -# Update function.yaml -echo "Updating function.yaml..." -sed -i.bak "s||$S3_BUCKET|g" function.yaml -sed -i.bak "s||lambda/pipecd-tutorial-canary.zip|g" function.yaml -sed -i.bak "s||$LAMBDA_ROLE|g" function.yaml - -# Build package -echo "Building package..." -chmod +x build.sh -./build.sh - -# Upload to S3 -echo "Uploading to S3..." -aws s3 cp pipecd-tutorial-canary.zip "s3://$S3_BUCKET/lambda/pipecd-tutorial-canary.zip" - -echo "✅ Canary function setup complete!" - -# Summary -echo "" -echo "🎉 Setup Complete!" -echo "==================" -echo "✅ Both Lambda functions are built and uploaded to S3" -echo "✅ Configuration files are updated" -echo "" -echo "📋 Next Steps:" -echo "1. Commit and push your changes to Git" -echo "2. Register the applications in PipeCD console" -echo "3. Watch the deployment progress" -echo "" -echo "📁 Files created:" -echo "- simple/pipecd-tutorial-simple.zip" -echo "- canary/pipecd-tutorial-canary.zip" -echo "" -echo "☁️ S3 Objects:" -echo "- s3://$S3_BUCKET/lambda/pipecd-tutorial-simple.zip" -echo "- s3://$S3_BUCKET/lambda/pipecd-tutorial-canary.zip" -echo "" -echo "📚 For more information, see:" -echo "- README.md" -echo "- DEPLOYMENT_GUIDE.md" diff --git a/src/deploy/lambda/simple/build.bat b/src/deploy/lambda/simple/build.bat deleted file mode 100644 index afacce0..0000000 --- a/src/deploy/lambda/simple/build.bat +++ /dev/null @@ -1,56 +0,0 @@ -@echo off -REM Build script for PipeCD Tutorial Lambda Function (Windows) -REM This script packages the Lambda function code into a zip file - -echo Building PipeCD Tutorial Lambda Function... - -REM Set variables -set BUILD_DIR=build -set FUNCTION_NAME=pipecd-tutorial-simple -set ZIP_FILE=%FUNCTION_NAME%.zip - -REM Clean previous build -if exist "%BUILD_DIR%" ( - echo Cleaning previous build... - rmdir /s /q "%BUILD_DIR%" -) - -if exist "%ZIP_FILE%" ( - echo Removing previous zip file... - del "%ZIP_FILE%" -) - -REM Create build directory -mkdir "%BUILD_DIR%" - -REM Copy source code -echo Copying source code... -copy "src\index.py" "%BUILD_DIR%\" - -REM Check if requirements.txt has actual dependencies -findstr /v "^#" "src\requirements.txt" | findstr /v "^$" > nul -if %errorlevel% equ 0 ( - echo Installing Python dependencies... - pip install -r src\requirements.txt -t %BUILD_DIR% -) else ( - echo No dependencies to install (using only standard library) -) - -REM Create zip file -echo Creating zip package... -cd "%BUILD_DIR%" -powershell -command "Compress-Archive -Path * -DestinationPath '..\%ZIP_FILE%' -Force" -cd .. - -REM Cleanup build directory -rmdir /s /q "%BUILD_DIR%" - -echo ✅ Lambda function packaged successfully: %ZIP_FILE% -for %%A in ("%ZIP_FILE%") do echo 📦 Package size: %%~zA bytes -echo. -echo Next steps: -echo 1. Upload %ZIP_FILE% to an S3 bucket -echo 2. Update function.yaml with the S3 bucket and key -echo 3. Deploy using PipeCD - -pause diff --git a/src/deploy/lambda/simple/build.sh b/src/deploy/lambda/simple/build.sh deleted file mode 100644 index 29568c1..0000000 --- a/src/deploy/lambda/simple/build.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -# Build script for PipeCD Tutorial Lambda Function -# This script packages the Lambda function code into a zip file - -set -e - -echo "Building PipeCD Tutorial Lambda Function..." - -# Create build directory -BUILD_DIR="build" -FUNCTION_NAME="pipecd-tutorial-simple" -ZIP_FILE="${FUNCTION_NAME}.zip" - -# Clean previous build -if [ -d "$BUILD_DIR" ]; then - echo "Cleaning previous build..." - rm -rf "$BUILD_DIR" -fi - -if [ -f "$ZIP_FILE" ]; then - echo "Removing previous zip file..." - rm "$ZIP_FILE" -fi - -# Create build directory -mkdir -p "$BUILD_DIR" - -# Copy source code -echo "Copying source code..." -cp src/index.py "$BUILD_DIR/" - -# Install dependencies if requirements.txt has actual dependencies -if [ -f "src/requirements.txt" ] && [ -s "src/requirements.txt" ] && grep -v '^#' src/requirements.txt | grep -v '^$' > /dev/null; then - echo "Installing Python dependencies..." - pip install -r src/requirements.txt -t "$BUILD_DIR/" -else - echo "No dependencies to install (using only standard library)" -fi - -# Create zip file -echo "Creating zip package..." -cd "$BUILD_DIR" - -# Check if we're on Windows (Git Bash) and use PowerShell for zip -if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then - # Use PowerShell to create zip on Windows - powershell.exe -command "Compress-Archive -Path * -DestinationPath '../$ZIP_FILE' -Force" -else - # Use standard zip command on Linux/Mac - zip -r "../$ZIP_FILE" . -fi - -cd .. - -# Cleanup build directory -rm -rf "$BUILD_DIR" - -echo "✅ Lambda function packaged successfully: $ZIP_FILE" -echo "📦 Package size: $(du -h "$ZIP_FILE" | cut -f1)" -echo "" -echo "Next steps:" -echo "1. Upload $ZIP_FILE to an S3 bucket" -echo "2. Update function.yaml with the S3 bucket and key" -echo "3. Deploy using PipeCD" diff --git a/src/deploy/lambda/simple/function.yaml b/src/deploy/lambda/simple/function.yaml index e6dd727..5643bc6 100644 --- a/src/deploy/lambda/simple/function.yaml +++ b/src/deploy/lambda/simple/function.yaml @@ -2,12 +2,13 @@ apiVersion: pipecd.dev/v1beta1 kind: LambdaFunction spec: - name: PipeCDTutorial_Simple + name: SimpleZipFunction role: # [EDIT_HERE] The ARN of the function’s execution role. - # Using zip deployment instead of container image for simpler setup + # Using PipeCD's built-in source code packaging - no manual zip building or S3 uploads needed! source: - s3Bucket: # [EDIT_HERE] S3 bucket containing your zip file - s3Key: # [EDIT_HERE] S3 key path to your zip file (e.g., lambda/pipecd-tutorial-simple.zip) + git: "" # Empty means same repository + ref: "" # Empty means current commit + path: "src" # Path to source code directory relative to this function.yaml runtime: python3.9 handler: index.lambda_handler memory: 512 From cfd3d2c4f33c7051eedff35f48e5d79acb9a01a4 Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Thu, 10 Jul 2025 15:51:25 +0530 Subject: [PATCH 4/7] removed standalone readme and aligned the instruction with the tutorial flow ! --- content/en/40-deploy/01-simply.md | 6 +- content/en/40-deploy/02-pipeline.md | 6 +- content/ja/40-deploy/01-simply.md | 6 +- content/ja/40-deploy/02-pipeline.md | 6 +- src/deploy/lambda/README.md | 157 ---------------------------- 5 files changed, 12 insertions(+), 169 deletions(-) delete mode 100644 src/deploy/lambda/README.md diff --git a/content/en/40-deploy/01-simply.md b/content/en/40-deploy/01-simply.md index 9cdf3fd..1f80337 100644 --- a/content/en/40-deploy/01-simply.md +++ b/content/en/40-deploy/01-simply.md @@ -22,9 +22,9 @@ In this page, you will deploy an application to your platform in a simple way. - `servicedef.yaml`: Edit `cluster`, `securityGroups`, and `subnets`. - `taskdef.yaml`: Edit `executionRoleArn`. - For **AWS Lambda**: - - You will create a function using simple Python source code. - - Edit `lambda/simple/` as below. - - `function.yaml`: Edit `role` only (PipeCD automatically packages and deploys your source code) + - You will create a function from your own Python source code. + - Edit `lambda/simple/function.yaml`: Edit the `role` field. + - **No need to build or upload a ZIP file manually. PipeCD will package and deploy your function automatically.** - For **Terraform**: - You will generate a file on local. - Edit `terraform/simple/` as below. diff --git a/content/en/40-deploy/02-pipeline.md b/content/en/40-deploy/02-pipeline.md index 2d58d2c..f6b9afe 100644 --- a/content/en/40-deploy/02-pipeline.md +++ b/content/en/40-deploy/02-pipeline.md @@ -21,9 +21,9 @@ _The process is almost the same as [1. Deploy Simply](01-simply.md). Only the co - `servicedef.yaml`: Copy from your `/src/deploy/ecs/simple/servicedef.yaml` and rename `serviceName`. - `taskdef.yaml`: Copy from your `/src/deploy/ecs/simple/taskdef.yaml` and rename `family`. - For **AWS Lambda**: - - You will create a function using source code with Canary release strategy. - - Edit `lambda/canary/` as below. - - `function.yaml`: Edit `role` only (PipeCD automatically packages and deploys your source code) + - You will create a function from your own Python source code using a canary deployment strategy. + - Edit `lambda/canary/function.yaml`: Copy from your `src/deploy/lambda/simple/function.yaml` and rename the `name`. + - **No need to build or upload a ZIP file manually. PipeCD will package and deploy your function automatically.** - For **Terraform**: - You will generate a file on local with plan->approval->apply pipeline. - Edit `terraform/plan-approval-apply/` as below. diff --git a/content/ja/40-deploy/01-simply.md b/content/ja/40-deploy/01-simply.md index 0620c95..8c46592 100644 --- a/content/ja/40-deploy/01-simply.md +++ b/content/ja/40-deploy/01-simply.md @@ -22,9 +22,9 @@ - `servicedef.yaml`: `cluster`, `securityGroups`, `subnets` - `taskdef.yaml`: `executionRoleArn`. - **AWS Lambda**向け: - - シンプルなPythonソースコードを使用して関数をデプロイしていきます。 - - `lambda/simple/`の以下の箇所を編集してください。 - - `function.yaml`: `role` のみ編集(PipeCDが自動的にソースコードをパッケージ化してデプロイします) + - あなた自身のPythonソースコードから関数を作成します。 + - `lambda/simple/function.yaml`を編集: `role`フィールドを編集してください。 + - **ZIPファイルを手動でビルドやアップロードする必要はありません。PipeCDが自動的に関数をパッケージ化してデプロイします。** - **Terraform**向け: - ファイルをローカルに生成していきます。 - `terraform/simple/`の以下の箇所を編集してください。 diff --git a/content/ja/40-deploy/02-pipeline.md b/content/ja/40-deploy/02-pipeline.md index 3427fa2..5d553d1 100644 --- a/content/ja/40-deploy/02-pipeline.md +++ b/content/ja/40-deploy/02-pipeline.md @@ -21,9 +21,9 @@ _手順は[1. シンプルなデプロイ](01-simply.md)とほとんど同じで - `servicedef.yaml`: `/src/deploy/ecs/simple/servicedef.yaml`からコピーして、`serviceName`を変更 - `taskdef.yaml`: `/src/deploy/ecs/simple/taskdef.yaml`からコピーして、`family`を変更 - **AWS Lambda**向け: - - ソースコードを使用して関数をCanaryリリースしていきます。 - - `lambda/canary/`を以下のように編集してください。 - - `function.yaml`: `role` のみ編集(PipeCDが自動的にソースコードをパッケージ化してデプロイします) + - Canaryデプロイ戦略を使用してあなた自身のPythonソースコードから関数を作成します。 + - `lambda/canary/function.yaml`を編集: `src/deploy/lambda/simple/function.yaml`からコピーして`name`を変更してください。 + - **ZIPファイルを手動でビルドやアップロードする必要はありません。PipeCDが自動的に関数をパッケージ化してデプロイします。** - `function.yaml`: `/src/deploy/lambda/simple/function.yaml`からコピーして、`name`を変更 - **Terraform**向け: - ファイルをローカルに生成していきます。plan->承認->applyのパイプラインを構築します。 diff --git a/src/deploy/lambda/README.md b/src/deploy/lambda/README.md deleted file mode 100644 index cd70e36..0000000 --- a/src/deploy/lambda/README.md +++ /dev/null @@ -1,157 +0,0 @@ -# Lambda Deployment with PipeCD Tutorial - -This directory contains examples for deploying AWS Lambda functions using PipeCD with **direct source code deployment** instead of container images, making it much easier to get started. - -## 🎯 What's New (Issue #16) - -Previously, the Lambda tutorial required: -- ❌ Building and pushing container images to ECR -- ❌ Complex Docker setup -- ❌ ECR repository management - -Now it uses: -- ✅ Simple Python source code -- ✅ **Automatic packaging by PipeCD** -- ✅ **No manual zip building or S3 uploads** -- ✅ Minimal prerequisites (just an IAM role) - -## 📁 Directory Structure - -``` -lambda/ -├── simple/ # Simple deployment example -│ ├── src/ -│ │ ├── index.py # Lambda function source code -│ │ └── requirements.txt # Python dependencies -│ ├── function.yaml # Lambda function configuration -│ └── app.pipecd.yaml # PipeCD application config -├── canary/ # Canary deployment example -│ ├── src/ -│ │ ├── index.py # Enhanced Lambda function -│ │ └── requirements.txt # Python dependencies -│ ├── function.yaml # Lambda function configuration -│ └── app.pipecd.yaml # PipeCD canary pipeline config -└── README.md # This file -``` - -## 🚀 Quick Start - -### Prerequisites - -1. **AWS CLI configured** with appropriate permissions -2. **IAM role** for Lambda execution - -### Step 1: Configure function.yaml - -Edit `simple/function.yaml`: - -```yaml -spec: - name: PipeCDTutorial_Simple - role: arn:aws:iam::123456789012:role/lambda-execution-role - source: - git: "" # Empty means same repository - ref: "" # Empty means current commit - path: "src" # Path to source code directory - runtime: python3.9 - handler: index.lambda_handler -``` - -### Step 2: Deploy with PipeCD - -Follow the main tutorial instructions to register and deploy the application. - -**That's it!** PipeCD will automatically: -- Package your source code into a zip file -- Deploy it to AWS Lambda -- Handle all the complexity for you - -## 📋 Function Details - -### Simple Function (`simple/src/index.py`) - -- Returns a JSON response with greeting and metadata -- Includes request information and timestamps -- Uses only Python standard library (no dependencies) -- Perfect for testing basic Lambda deployment - -### Canary Function (`canary/src/index.py`) - -- Enhanced version with deployment tracking -- Additional logging for canary deployment monitoring -- Environment variables for version control -- Demonstrates gradual rollout capabilities - -## 🔧 Customization - -### Adding Dependencies - -1. Edit `src/requirements.txt`: - ``` - requests==2.31.0 - boto3==1.34.0 - ``` - -2. Commit and push - PipeCD will automatically install dependencies during packaging - -### Modifying the Function - -1. Edit `src/index.py` with your custom logic -2. Test locally: `python src/index.py` -3. Commit and push - PipeCD handles the rest - -### Environment Variables - -Add environment variables in `function.yaml`: - -```yaml -spec: - environment: - CUSTOM_VAR: "custom_value" - API_ENDPOINT: "https://api.example.com" -``` - -## 🧪 Local Testing - -Test your function locally before deployment: - -```bash -cd simple/src/ -python index.py -``` - -This runs the function with a test event and displays the output. - -## 📊 Deployment Strategies - -### Simple Deployment -- Uses `simple/` directory -- Quick sync strategy -- Immediate deployment - -### Canary Deployment -- Uses `canary/` directory -- Gradual traffic shifting (10% → 50% → 100%) -- Built-in rollback capabilities -- Wait stages for monitoring - -## 🔍 Troubleshooting - -### Deployment Issues -- Verify IAM role has Lambda execution permissions -- Check function.yaml syntax -- Ensure source code is in the correct directory structure - -### Runtime Issues -- Review CloudWatch logs -- Test function locally first -- Verify environment variables - -## 📚 Next Steps - -1. Try the simple deployment first -2. Experiment with the canary deployment -3. Customize the function for your use case -4. Explore PipeCD's advanced Lambda features - -For more information, see the [PipeCD Lambda documentation](https://pipecd.dev/docs/user-guide/configuration-reference/#lambda-application). From 84562522617c3a7a28f3d7d3586e0a7bda5bb149 Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Sat, 12 Jul 2025 13:18:22 +0530 Subject: [PATCH 5/7] typo fixed in the description and corrected the description --- content/en/40-deploy/01-simply.md | 4 ++-- content/en/40-deploy/02-pipeline.md | 4 ++-- content/ja/40-deploy/01-simply.md | 4 ++-- content/ja/40-deploy/02-pipeline.md | 5 ++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/content/en/40-deploy/01-simply.md b/content/en/40-deploy/01-simply.md index 1f80337..7cc0f64 100644 --- a/content/en/40-deploy/01-simply.md +++ b/content/en/40-deploy/01-simply.md @@ -22,7 +22,7 @@ In this page, you will deploy an application to your platform in a simple way. - `servicedef.yaml`: Edit `cluster`, `securityGroups`, and `subnets`. - `taskdef.yaml`: Edit `executionRoleArn`. - For **AWS Lambda**: - - You will create a function from your own Python source code. + - Create a function from Python source code. - Edit `lambda/simple/function.yaml`: Edit the `role` field. - **No need to build or upload a ZIP file manually. PipeCD will package and deploy your function automatically.** - For **Terraform**: @@ -91,4 +91,4 @@ In this page, you will deploy an application to your platform in a simple way. [Next: Deploy with a Customized Pipeline >](02-pipeline.md) -[< Previous: Deploy](README.md) \ No newline at end of file +[< Previous: Deploy](README.md) diff --git a/content/en/40-deploy/02-pipeline.md b/content/en/40-deploy/02-pipeline.md index f6b9afe..78e3cc2 100644 --- a/content/en/40-deploy/02-pipeline.md +++ b/content/en/40-deploy/02-pipeline.md @@ -21,8 +21,8 @@ _The process is almost the same as [1. Deploy Simply](01-simply.md). Only the co - `servicedef.yaml`: Copy from your `/src/deploy/ecs/simple/servicedef.yaml` and rename `serviceName`. - `taskdef.yaml`: Copy from your `/src/deploy/ecs/simple/taskdef.yaml` and rename `family`. - For **AWS Lambda**: - - You will create a function from your own Python source code using a canary deployment strategy. - - Edit `lambda/canary/function.yaml`: Copy from your `src/deploy/lambda/simple/function.yaml` and rename the `name`. + - You will create a function from Python source code using a canary deployment strategy. + - Edit `lambda/canary/function.yaml`: Edit the `role` field. - **No need to build or upload a ZIP file manually. PipeCD will package and deploy your function automatically.** - For **Terraform**: - You will generate a file on local with plan->approval->apply pipeline. diff --git a/content/ja/40-deploy/01-simply.md b/content/ja/40-deploy/01-simply.md index 8c46592..ec8b534 100644 --- a/content/ja/40-deploy/01-simply.md +++ b/content/ja/40-deploy/01-simply.md @@ -22,7 +22,7 @@ - `servicedef.yaml`: `cluster`, `securityGroups`, `subnets` - `taskdef.yaml`: `executionRoleArn`. - **AWS Lambda**向け: - - あなた自身のPythonソースコードから関数を作成します。 + - Pythonソースコードから関数を作成します。 - `lambda/simple/function.yaml`を編集: `role`フィールドを編集してください。 - **ZIPファイルを手動でビルドやアップロードする必要はありません。PipeCDが自動的に関数をパッケージ化してデプロイします。** - **Terraform**向け: @@ -91,4 +91,4 @@ [次: カスタムのパイプラインでデプロイ>](02-pipeline.md) -[< 戻る: Deploy](README.md) \ No newline at end of file +[< 戻る: Deploy](README.md) diff --git a/content/ja/40-deploy/02-pipeline.md b/content/ja/40-deploy/02-pipeline.md index 5d553d1..e8147b7 100644 --- a/content/ja/40-deploy/02-pipeline.md +++ b/content/ja/40-deploy/02-pipeline.md @@ -21,10 +21,9 @@ _手順は[1. シンプルなデプロイ](01-simply.md)とほとんど同じで - `servicedef.yaml`: `/src/deploy/ecs/simple/servicedef.yaml`からコピーして、`serviceName`を変更 - `taskdef.yaml`: `/src/deploy/ecs/simple/taskdef.yaml`からコピーして、`family`を変更 - **AWS Lambda**向け: - - Canaryデプロイ戦略を使用してあなた自身のPythonソースコードから関数を作成します。 - - `lambda/canary/function.yaml`を編集: `src/deploy/lambda/simple/function.yaml`からコピーして`name`を変更してください。 + - Canaryデプロイ戦略を使用してPythonソースコードから関数を作成します。 + - `lambda/canary/function.yaml`を編集: `role`フィールドを編集してください。 - **ZIPファイルを手動でビルドやアップロードする必要はありません。PipeCDが自動的に関数をパッケージ化してデプロイします。** - - `function.yaml`: `/src/deploy/lambda/simple/function.yaml`からコピーして、`name`を変更 - **Terraform**向け: - ファイルをローカルに生成していきます。plan->承認->applyのパイプラインを構築します。 - `terraform/plan-approval-apply/`の下記の箇所を編集してください。 From 918d6a4f4417c685451f4432c170f4fa47e47fcf Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Sat, 12 Jul 2025 13:21:47 +0530 Subject: [PATCH 6/7] aligned the text of english version to match with japanese version --- content/en/40-deploy/02-pipeline.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/en/40-deploy/02-pipeline.md b/content/en/40-deploy/02-pipeline.md index 78e3cc2..1bfe6c8 100644 --- a/content/en/40-deploy/02-pipeline.md +++ b/content/en/40-deploy/02-pipeline.md @@ -21,7 +21,7 @@ _The process is almost the same as [1. Deploy Simply](01-simply.md). Only the co - `servicedef.yaml`: Copy from your `/src/deploy/ecs/simple/servicedef.yaml` and rename `serviceName`. - `taskdef.yaml`: Copy from your `/src/deploy/ecs/simple/taskdef.yaml` and rename `family`. - For **AWS Lambda**: - - You will create a function from Python source code using a canary deployment strategy. + - Create a function from Python source code using a canary deployment strategy. - Edit `lambda/canary/function.yaml`: Edit the `role` field. - **No need to build or upload a ZIP file manually. PipeCD will package and deploy your function automatically.** - For **Terraform**: From 5c377dffae5f7f55462824989f568ac1738e60d4 Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Mon, 14 Jul 2025 00:58:42 +0530 Subject: [PATCH 7/7] updated the git ref fields and related comments --- src/deploy/lambda/canary/function.yaml | 12 ++++++++---- src/deploy/lambda/simple/function.yaml | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/deploy/lambda/canary/function.yaml b/src/deploy/lambda/canary/function.yaml index 5c4312c..3c203d7 100644 --- a/src/deploy/lambda/canary/function.yaml +++ b/src/deploy/lambda/canary/function.yaml @@ -6,13 +6,17 @@ spec: role: # [EDIT_HERE] The ARN of the function’s execution role. # Using PipeCD's built-in source code packaging - no manual zip building or S3 uploads needed! source: - git: "" # Empty means same repository - ref: "" # Empty means current commit - path: "src" # Path to source code directory relative to this function.yaml + # git remote address where the source code is placing. + git: https://github.com//.git # [EDIT_HERE] + # the commit SHA or tag for remote git. Use branch name means you will always use + # the latest code of that branch as Lambda function code which is NOT recommended. + ref: main # [EDIT_HERE] Using main branch for simplicity in the tutorial + # relative path from the repository root directory to the function code directory. + path: "src" runtime: python3.9 handler: index.lambda_handler memory: 512 timeout: 30 environment: FUNCTION_VERSION: "v2.0.0" - DEPLOYMENT_TYPE: "canary" \ No newline at end of file + DEPLOYMENT_TYPE: "canary" diff --git a/src/deploy/lambda/simple/function.yaml b/src/deploy/lambda/simple/function.yaml index 5643bc6..9a2e2db 100644 --- a/src/deploy/lambda/simple/function.yaml +++ b/src/deploy/lambda/simple/function.yaml @@ -6,12 +6,16 @@ spec: role: # [EDIT_HERE] The ARN of the function’s execution role. # Using PipeCD's built-in source code packaging - no manual zip building or S3 uploads needed! source: - git: "" # Empty means same repository - ref: "" # Empty means current commit - path: "src" # Path to source code directory relative to this function.yaml + # git remote address where the source code is placing. + git: https://github.com//.git # [EDIT_HERE] + # the commit SHA or tag for remote git. Use branch name means you will always use + # the latest code of that branch as Lambda function code which is NOT recommended. + ref: main # [EDIT_HERE] Using main branch for simplicity in the tutorial + # relative path from the repository root directory to the function code directory. + path: "src" runtime: python3.9 handler: index.lambda_handler memory: 512 timeout: 30 environment: - FUNCTION_VERSION: "v1.0.0" \ No newline at end of file + FUNCTION_VERSION: "v1.0.0"