Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion content/en/20-prerequisites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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
- function’s execution role
- for **Terraform**:
- You can execute [`terraform` commands](https://developer.hashicorp.com/terraform/cli/commands) on local.
Expand Down
4 changes: 2 additions & 2 deletions content/en/40-deploy/01-simply.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 of your own image.
- You will create a function using simple Python source code.
- Edit `lambda/simple/` as below.
- `function.yaml`: Edit `role` and `image`.
- `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.
Expand Down
4 changes: 2 additions & 2 deletions content/en/40-deploy/02-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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`.
- `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.
Expand Down
1 change: 0 additions & 1 deletion content/ja/20-prerequisites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
- **AWS Lambda**向け:
- ローカルからあなたのAWSアカウントに対して、Lambdaの各種APIを実行できること。詳細は[こちら](https://pipecd.dev/docs/installation/install-piped/required-permissions/#for-lambdaapp)。
- 下記のすべて。(一般的なLambda関数を作る際に必要なものと同じです)
- ECRリポジトリにイメージがあること
- 関数の実行ロール
- **Terraform**向け:
- [`terraform` commands](https://developer.hashicorp.com/terraform/cli/commands)をローカルから実行できること。
Expand Down
4 changes: 2 additions & 2 deletions content/ja/40-deploy/01-simply.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
- `servicedef.yaml`: `cluster`, `securityGroups`, `subnets`
- `taskdef.yaml`: `executionRoleArn`.
- **AWS Lambda**向け:
- あなたのイメージを利用して関数をデプロイしていきます
- シンプルなPythonソースコードを使用して関数をデプロイしていきます
- `lambda/simple/`の以下の箇所を編集してください。
- `function.yaml`: `role`, `image`
- `function.yaml`: `role` のみ編集(PipeCDが自動的にソースコードをパッケージ化してデプロイします)
- **Terraform**向け:
- ファイルをローカルに生成していきます。
- `terraform/simple/`の以下の箇所を編集してください。
Expand Down
3 changes: 2 additions & 1 deletion content/ja/40-deploy/02-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +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リリースしていきます
- ソースコードを使用して関数をCanaryリリースしていきます
- `lambda/canary/`を以下のように編集してください。
- `function.yaml`: `role` のみ編集(PipeCDが自動的にソースコードをパッケージ化してデプロイします)
- `function.yaml`: `/src/deploy/lambda/simple/function.yaml`からコピーして、`name`を変更
- **Terraform**向け:
- ファイルをローカルに生成していきます。plan->承認->applyのパイプラインを構築します。
Expand Down
157 changes: 157 additions & 0 deletions src/deploy/lambda/README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users cannot find this file. Move to a better place.
Do you understand the tutorial flow?

Copy link
Author

@RayyanSeliya RayyanSeliya Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @t-kikuc for your feedback. I initially focused on the Lambda ZIP deployment itself, but after your comments, I reviewed the tutorial structure to ensure my changes fit the main flow. I’ve deleted the standalone Lambda README and moved the instructions into 01-simply.md and 02-pipeline.md for clarity. Thanks again for helping me see the tutorial from the user’s perspective!

Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary


## 📁 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).
15 changes: 12 additions & 3 deletions src/deploy/lambda/canary/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
apiVersion: pipecd.dev/v1beta1
kind: LambdaFunction
spec:
name: PipeCDTutorial_Canary
name: CanaryZipFunction
role: <IAM_ROLE_ARN> # [EDIT_HERE] The ARN of the function’s execution role.
image: <IMAGE_URI> # [EDIT_HERE] The URI of a container image in the Amazon ECR registry.
# 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
runtime: python3.9
handler: index.lambda_handler
memory: 512
timeout: 30
timeout: 30
environment:
FUNCTION_VERSION: "v2.0.0"
DEPLOYMENT_TYPE: "canary"
85 changes: 85 additions & 0 deletions src/deploy/lambda/canary/src/index.py
Original file line number Diff line number Diff line change
@@ -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))
13 changes: 13 additions & 0 deletions src/deploy/lambda/canary/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
14 changes: 11 additions & 3 deletions src/deploy/lambda/simple/function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
apiVersion: pipecd.dev/v1beta1
kind: LambdaFunction
spec:
name: PipeCDTutorial_Simple
name: SimpleZipFunction
role: <IAM_ROLE_ARN> # [EDIT_HERE] The ARN of the function’s execution role.
image: <IMAGE_URI> # [EDIT_HERE] The URI of a container image in your ECR repository.
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you know this spec?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you know this spec?

hey @t-kikuc I implemented this based on the code comments and the pattern I saw in other PipeCD resources. The Helm chart docs mention that 'Empty means the same repository' (https://pipecd.dev/docs-v0.52.x/user-guide/configuration-reference/#analysis-template-configuration:~:text=Empty%20means%20the%20same%20repository), and I assumed this convention applies to Lambda functions too.

If this approach isn't correct for Lambda functions, I'd appreciate your guidance on what values should be used instead for the tutorial. Should we use explicit git/ref values or is there a better way to reference the current repository?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not helm chart.

See https://pipecd.dev/docs-v0.52.x/user-guide/managing-application/defining-app-configuration/lambda/ and https://github.com/pipe-cd/pipecd/blob/0c999367d009c143baa72785d4ad6bd841bdb189/pkg/app/piped/platformprovider/lambda/function.go#L128-L142

@t-kikuc Thank you for pointing out my mistake with the empty git / ref fields. I've corrected both function.yaml files to align exactly with the documentation at https://pipecd.dev/docs-v0.52.x/user-guide/managing-application/defining-app-configuration/lambda/#:~:text=Deploy%20source%20code,Lambda%20function%20pattern. I've maintained the same comment style as the official example while using HTTPS URLs for GitHub repositories, which is more beginner-friendly for the tutorial. The [EDIT_HERE] markers will guide users to replace these values with their own repository information.

path: "src" # Path to source code directory relative to this function.yaml
runtime: python3.9
handler: index.lambda_handler
memory: 512
timeout: 30
timeout: 30
environment:
FUNCTION_VERSION: "v1.0.0"
Loading