

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

# 使用 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)動作提供簡單的 YAML 介面，可處理建立應用程式版本、將原始碼套件上傳至 Amazon S3，以及部署到您的 Elastic Beanstalk 環境。

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

下列範例工作流程會在每次您推送至`main`分支時，將應用程式部署至 Elastic Beanstalk 環境。在 `.github/workflows/` 下的儲存庫中建立`.yml`檔案。

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

```
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) AWS 透過[設定 AWS 登入](https://github.com/aws-actions/configure-aws-credentials)資料動作向 進行驗證，然後將您的應用程式部署到 Elastic Beanstalk。部署動作會封裝您的儲存庫內容、將原始碼套件上傳至 Amazon S3、建立新的應用程式版本，以及建立或更新您的環境。根據預設，它會等待部署完成，並等待環境回到運作狀態。

如需更多組態選項和進階範例，請參閱 GitHub 上的 [Elastic Beanstalk 部署動作 README](https://github.com/aws-actions/aws-elasticbeanstalk-deploy#readme)。

## 其他資源
<a name="deploying-github-actions-resources"></a>
+ 在 GitHub 上[部署 Elastic Beanstalk 動作](https://github.com/aws-actions/aws-elasticbeanstalk-deploy) 
+ 在 GitHub [上設定 AWS 登入資料動作](https://github.com/aws-actions/configure-aws-credentials) 
+ 在 [Amazon 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 文件）