

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 GitHub 操作部署到 Elastic Beanstalk
<a name="deploying-github-actions"></a>

GitHub 当您将代码更改推送到存储库时，[操作](https://docs.github.com/en/actions)可以自动将您的应用程序部署到 Elastic Beanstalk。[Elastic Beanstalk](https://github.com/aws-actions/aws-elasticbeanstalk-deploy) Deploy 操作提供了一个简单的 YAML 接口，用于创建应用程序版本、将源包上传到 Amazon S3 以及部署到您的 Elastic Beanstalk 环境。

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

以下示例工作流程在您每次推送到 Elastic Beanstalk 环境时都会将应用程序部署到 Elastic Beanstalk 环境。`main`在下方的存储库中创建一个`.yml`文件`.github/workflows/`。

**Example GitHub 部署 Elastic Beanstalk 的操作工作流程**  

```
name: Deploy to Elastic Beanstalk

on:
  push:
    branches:
      - main

permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123456789012:role/my-github-actions-role
          aws-region: us-east-1

      - name: Deploy to Elastic Beanstalk
        uses: aws-actions/aws-elasticbeanstalk-deploy@v1.0.0
        with:
          aws-region: us-east-1
          application-name: my-application
          environment-name: my-application-env
```

此工作流程会检出您的存储库，使用 [OpenID Connect (OIDC)](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services) Amazon 通过 “[配置 Amazon 凭据](https://github.com/aws-actions/configure-aws-credentials)” 操作进行身份验证，然后将您的应用程序部署到 Elastic Beanstalk。部署操作会打包您的存储库内容，将源包上传到 Amazon S3，创建新的应用程序版本，并创建或更新您的环境。默认情况下，它会等待部署完成以及环境恢复到正常状态。

有关更多配置选项和高级示例，请参阅 Elastic Be [anstalk Deploy 操作自述文件](https://github.com/aws-actions/aws-elasticbeanstalk-deploy#readme)。 GitHub

## 其他资源
<a name="deploying-github-actions-resources"></a>
+ [Elastic Beanstalk 在上部署动](https://github.com/aws-actions/aws-elasticbeanstalk-deploy)作 GitHub
+ [在 “配置 Amazon 凭证” 操作](https://github.com/aws-actions/configure-aws-credentials) GitHub
+ [在亚马逊 Web Services 中配置 OpenID Connect](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)（文档）GitHub