

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 GitHub Actions 部署 Lambda 函式
<a name="deploying-github-actions"></a>

在您將程式碼或組態變更推送至程式碼庫時，可透過 [GitHub Actions](https://github.com/features/actions) 自動部署 Lambda 函式。[部署 Lambda 函式](https://github.com/aws-actions/aws-lambda-deploy)動作提供簡潔的宣告式 YAML 介面，可消除手動部署步驟的複雜性。

## 範例工作流程
<a name="deploying-github-actions-example"></a>

若要設定自動化 Lambda 函式部署，請在儲存庫的 `.github/workflows/` 目錄中建立工作流程檔案：

**Example 用於部署 Lambda 的 GitHub Actions 工作流程**  

```
name: Deploy AWS Lambda

on:
  push:
    branches: 
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      id-token: write # Required for OIDC authentication
      contents: read  # Required to check out the repository
    steps:
      - uses: actions/checkout@v4
      
      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123456789012:role/GitHubActionRole
          aws-region: us-east-1
      
      - name: Deploy Lambda Function
        uses: aws-actions/aws-lambda-deploy@v1
        with:
          function-name: my-lambda-function
          code-artifacts-dir: ./dist
```

此工作流程會在您將變更推送至 `main` 分支時執行。其會檢查您的儲存庫、使用 OpenID Connect (OIDC) 設定 AWS 憑證，並使用 `./dist` 目錄中的程式碼部署函式。

如需有關更新函式組態、透過 S3 儲存貯體部署及試執行驗證的更多範例，請參閱 [Deploy Lambda Function README](https://github.com/aws-actions/aws-lambda-deploy)。

## 其他資源
<a name="deploying-github-actions-resources"></a>
+ [Configure AWS Credentials GitHub Action](https://github.com/aws-actions/configure-aws-credentials)
+ [Configuring OpenID Connect in AWS](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)