

# 使用 GitHub Action 部署 Lambda 函数
GitHub Actions

当将代码或配置更改推送到仓库时，就可以使用 [GitHub Action](https://github.com/features/actions) 自动部署 Lambda 函数。[部署 Lambda 函数](https://github.com/aws-actions/aws-lambda-deploy)的操作提供了一个声明式的简单 YAML 接口，这消除了手动部署步骤的复杂性。

## 工作流示例


要配置自动化 Lambda 函数部署，请在仓库的 `.github/workflows/` 目录中创建工作流程文件：

**Example 进行 Lambda 部署 GitHub Action 工作流程**  

```
name: Deploy Amazon 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 Amazon 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) 配置 Amazon 凭证，并使用 `./dist` 目录中的代码部署函数。

有关更新函数配置、通过 S3 存储桶进行部署和试运行验证等其他示例，请参阅 [部署 Lambda 函数自述文件](https://github.com/aws-actions/aws-lambda-deploy)。

## 其他资源

+ [配置 GitHub Action 的 Amazon 凭证](https://github.com/aws-actions/configure-aws-credentials)
+ [在 Amazon 中配置 OpenID Connect](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)