Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion content/en/20-prerequisites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 4 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,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.
Expand Down
6 changes: 4 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,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)
Copy link
Member

Choose a reason for hiding this comment

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

Please make a procedure without building and pushing to s3. That's troublesome.

Use the zip packing feature of PipeCD Lambda.

Copy link
Author

Choose a reason for hiding this comment

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

Sure will research on this through https://pipecd.dev/docs-v0.52.x/user-guide/managing-application/defining-app-configuration/lambda/ and implement it accordingly

- 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.
Expand Down
3 changes: 2 additions & 1 deletion content/ja/20-prerequisites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)をローカルから実行できること。

Expand Down
8 changes: 5 additions & 3 deletions content/ja/40-deploy/01-simply.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/`の以下の箇所を編集してください。
Expand Down
5 changes: 4 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,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のパイプラインを構築します。
Expand Down
231 changes: 231 additions & 0 deletions src/deploy/lambda/DEPLOYMENT_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
# 🚀 Complete Lambda Deployment Guide

This guide provides step-by-step instructions for deploying AWS Lambda functions with PipeCD using the new simplified zip-based approach.

## 📋 Prerequisites Checklist

Before starting, ensure you have:

- [ ] AWS CLI configured with appropriate permissions
- [ ] S3 bucket created for storing Lambda packages
- [ ] IAM role for Lambda execution with basic permissions
- [ ] Python 3.9+ installed locally
- [ ] PipeCD control plane and piped running

## 🔧 Setup Instructions

### 1. Create S3 Bucket (if not exists)

```bash
# Create bucket
aws s3 mb s3://your-lambda-bucket-name

# Enable versioning (recommended)
aws s3api put-bucket-versioning \
--bucket your-lambda-bucket-name \
--versioning-configuration Status=Enabled
```

### 2. Create IAM Role for Lambda

Create a trust policy file `lambda-trust-policy.json`:

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
```

Create the role:

```bash
# Create role
aws iam create-role \
--role-name pipecd-lambda-execution-role \
--assume-role-policy-document file://lambda-trust-policy.json

# Attach basic execution policy
aws iam attach-role-policy \
--role-name pipecd-lambda-execution-role \
--policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

# Get role ARN (save this for later)
aws iam get-role --role-name pipecd-lambda-execution-role --query 'Role.Arn' --output text
```

## 🏗️ Building and Deploying

### Simple Deployment

1. **Navigate to simple directory:**
```bash
cd src/deploy/lambda/simple/
```

2. **Build the package:**
```bash
# Linux/Mac
chmod +x build.sh
./build.sh

# Windows
build.bat
```

3. **Upload to S3:**
```bash
aws s3 cp pipecd-tutorial-simple.zip s3://your-lambda-bucket-name/lambda/pipecd-tutorial-simple.zip
```

4. **Configure function.yaml:**
```yaml
spec:
name: PipeCDTutorial_Simple
role: arn:aws:iam::123456789012:role/pipecd-lambda-execution-role
source:
s3Bucket: your-lambda-bucket-name
s3Key: lambda/pipecd-tutorial-simple.zip
runtime: python3.9
handler: index.lambda_handler
memory: 512
timeout: 30
environment:
FUNCTION_VERSION: "v1.0.0"
```

5. **Deploy with PipeCD:**
- Register the application in PipeCD console
- Commit and push changes to trigger deployment

### Canary Deployment

1. **Navigate to canary directory:**
```bash
cd src/deploy/lambda/canary/
```

2. **Build the package:**
```bash
# Linux/Mac
chmod +x build.sh
./build.sh

# Windows
build.bat
```

3. **Upload to S3:**
```bash
aws s3 cp pipecd-tutorial-canary.zip s3://your-lambda-bucket-name/lambda/pipecd-tutorial-canary.zip
```

4. **Configure function.yaml:**
```yaml
spec:
name: PipeCDTutorial_Canary
role: arn:aws:iam::123456789012:role/pipecd-lambda-execution-role
source:
s3Bucket: your-lambda-bucket-name
s3Key: lambda/pipecd-tutorial-canary.zip
runtime: python3.9
handler: index.lambda_handler
memory: 512
timeout: 30
environment:
FUNCTION_VERSION: "v2.0.0"
DEPLOYMENT_TYPE: "canary"
```

5. **Deploy with canary strategy:**
- The pipeline will automatically handle gradual rollout
- Monitor deployment progress in PipeCD console

## 🧪 Testing Your Deployment

### Local Testing

Test the function locally before deployment:

```bash
cd src/
python index.py
```

### AWS Testing

After deployment, test the function:

```bash
# Invoke function directly
aws lambda invoke \
--function-name PipeCDTutorial_Simple \
--payload '{"httpMethod":"GET","path":"/test"}' \
response.json

# View response
cat response.json
```

## 🔍 Troubleshooting

### Common Issues

1. **Build fails:**
- Check Python version: `python --version`
- Ensure build script has execute permissions
- Verify requirements.txt syntax

2. **Upload fails:**
- Check AWS credentials: `aws sts get-caller-identity`
- Verify S3 bucket exists and you have write permissions
- Check bucket region matches your AWS CLI region

3. **Deployment fails:**
- Verify IAM role ARN is correct
- Check S3 bucket and key path in function.yaml
- Ensure Lambda service has access to S3 bucket

4. **Function errors:**
- Check CloudWatch logs: `aws logs describe-log-groups --log-group-name-prefix /aws/lambda/PipeCDTutorial`
- Verify handler path: `index.lambda_handler`
- Check runtime compatibility

### Debugging Commands

```bash
# Check function configuration
aws lambda get-function --function-name PipeCDTutorial_Simple

# View recent logs
aws logs tail /aws/lambda/PipeCDTutorial_Simple --follow

# Test function with custom payload
aws lambda invoke \
--function-name PipeCDTutorial_Simple \
--payload '{"test": "data"}' \
--cli-binary-format raw-in-base64-out \
response.json
```

## 🎯 Next Steps

1. **Customize the function** for your specific use case
2. **Add dependencies** by editing requirements.txt
3. **Implement monitoring** using CloudWatch metrics
4. **Set up alerts** for function errors
5. **Explore advanced PipeCD features** like approval workflows

## 📚 Additional Resources

- [PipeCD Lambda Documentation](https://pipecd.dev/docs/user-guide/configuration-reference/#lambda-application)
- [AWS Lambda Developer Guide](https://docs.aws.amazon.com/lambda/latest/dg/)
- [AWS Lambda Best Practices](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)
Loading