diff --git a/content/en/20-prerequisites/README.md b/content/en/20-prerequisites/README.md index 37d9dbc..0891be1 100644 --- a/content/en/20-prerequisites/README.md +++ b/content/en/20-prerequisites/README.md @@ -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. diff --git a/content/en/40-deploy/01-simply.md b/content/en/40-deploy/01-simply.md index 1dec991..7cc0f64 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 of your own image. - - Edit `lambda/simple/` as below. - - `function.yaml`: Edit `role` and `image`. + - 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**: - You will generate a file on local. - Edit `terraform/simple/` as below. @@ -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 727f2d8..1bfe6c8 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 of your own image by Canary release. - - Edit `lambda/canary/` as below. - - `function.yaml`: Copy from your `/src/deploy/lambda/simple/function.yaml`] and rename `name`. + - 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. - 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..8e05338 100644 --- a/content/ja/20-prerequisites/README.md +++ b/content/ja/20-prerequisites/README.md @@ -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)をローカルから実行できること。 diff --git a/content/ja/40-deploy/01-simply.md b/content/ja/40-deploy/01-simply.md index 1ca7620..ec8b534 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**向け: - - あなたのイメージを利用して関数をデプロイしていきます。 - - `lambda/simple/`の以下の箇所を編集してください。 - - `function.yaml`: `role`, `image` + - Pythonソースコードから関数を作成します。 + - `lambda/simple/function.yaml`を編集: `role`フィールドを編集してください。 + - **ZIPファイルを手動でビルドやアップロードする必要はありません。PipeCDが自動的に関数をパッケージ化してデプロイします。** - **Terraform**向け: - ファイルをローカルに生成していきます。 - `terraform/simple/`の以下の箇所を編集してください。 @@ -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 4cb3c62..e8147b7 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`: `/src/deploy/lambda/simple/function.yaml`からコピーして、`name`を変更 + - Canaryデプロイ戦略を使用してPythonソースコードから関数を作成します。 + - `lambda/canary/function.yaml`を編集: `role`フィールドを編集してください。 + - **ZIPファイルを手動でビルドやアップロードする必要はありません。PipeCDが自動的に関数をパッケージ化してデプロイします。** - **Terraform**向け: - ファイルをローカルに生成していきます。plan->承認->applyのパイプラインを構築します。 - `terraform/plan-approval-apply/`の下記の箇所を編集してください。 diff --git a/src/deploy/lambda/canary/function.yaml b/src/deploy/lambda/canary/function.yaml index cca2b80..3c203d7 100644 --- a/src/deploy/lambda/canary/function.yaml +++ b/src/deploy/lambda/canary/function.yaml @@ -2,8 +2,21 @@ apiVersion: pipecd.dev/v1beta1 kind: LambdaFunction spec: - name: PipeCDTutorial_Canary + name: CanaryZipFunction 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 PipeCD's built-in source code packaging - no manual zip building or S3 uploads needed! + source: + # 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 \ No newline at end of file + timeout: 30 + environment: + FUNCTION_VERSION: "v2.0.0" + DEPLOYMENT_TYPE: "canary" 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/simple/function.yaml b/src/deploy/lambda/simple/function.yaml index 7174d51..9a2e2db 100644 --- a/src/deploy/lambda/simple/function.yaml +++ b/src/deploy/lambda/simple/function.yaml @@ -2,8 +2,20 @@ apiVersion: pipecd.dev/v1beta1 kind: LambdaFunction spec: - name: PipeCDTutorial_Simple + name: SimpleZipFunction 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 PipeCD's built-in source code packaging - no manual zip building or S3 uploads needed! + source: + # 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 \ No newline at end of file + timeout: 30 + environment: + FUNCTION_VERSION: "v1.0.0" 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)) 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