

AWS App Runner 不再開放給新客戶。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS App Runner 可用性變更](https://docs.aws.amazon.com/apprunner/latest/dg/apprunner-availability-change.html)。

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

# App Runner 組態檔案範例
<a name="config-file-examples"></a>

**注意**  
組態檔案僅適用於[以原始程式碼為基礎的服務](service-source-code.md)。您無法搭配[映像型服務](service-source-image.md)使用組態檔案。

下列範例示範 AWS App Runner 組態檔案。有些是最小的，且僅包含必要的設定。其他則已完成，包括所有組態檔案區段。如需 App Runner 組態檔案的概觀，請參閱 [使用組態檔案設定 App Runner 服務選項](config-file.md)。

## 組態檔案範例
<a name="config-file-examples.managed"></a>

### 最小組態檔案
<a name="config-file-examples.managed.minimal"></a>

透過最少的組態檔案，App Runner 會做出下列假設：
+ 在建置或執行期間，不需要自訂環境變數。
+ 使用最新的執行時間版本。
+ 使用預設連接埠號碼和連接埠環境變數。

**Example apprunner.yaml**  

```
version: 1.0
runtime: python3 
build:
  commands:
    build:
      - pip install pipenv
      - pipenv install 
run: 
  command: python app.py
```

### 完成組態檔案
<a name="config-file-examples.managed.complete"></a>

此範例顯示使用具有受管執行時間的`apprunner.yaml`原始格式的所有組態金鑰。

**Example apprunner.yaml**  

```
version: 1.0
runtime: python3 
build:
  commands:
    pre-build:
      - wget -c https://s3.amazonaws.com/amzn-s3-demo-bucket/test-lib.tar.gz -O - | tar -xz
    build:        
      - pip install pipenv
      - pipenv install
    post-build:
      - python manage.py test
  env:
    - name: DJANGO_SETTINGS_MODULE
      value: "django_apprunner.settings"
    - name: MY_VAR_EXAMPLE
      value: "example"
run:
  runtime-version: {{3.7.7}}
  command: pipenv run gunicorn django_apprunner.wsgi --log-file -
  network: 
    port: 8000
    env: MY_APP_PORT  
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
  secrets:
    - name: my-secret
      value-from: "arn:aws:secretsmanager:us-east-1:123456789012:secret:testingstackAppRunnerConstr-kJFXde2ULKbT-S7t8xR:username::"
    - name: my-parameter
      value-from: "arn:aws:ssm:us-east-1:123456789012:parameter/parameter-name"
    - name: my-parameter-only-name
      value-from: "parameter-name"
```

### 完整組態檔案 — （使用修訂的組建）
<a name="config-file-examples.managed.complete-v2"></a>

此範例顯示使用 中所有組態金鑰`apprunner.yaml`搭配受管執行時間。

只有修訂後的 App Runner 組建才支援 `pre-run` 參數。如果您的應用程式使用原始 App Runner 組建支援的執行時間版本，請勿將此參數插入您的組態檔案中。如需詳細資訊，請參閱[受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail)。

**注意**  
由於此範例適用於 Python 3.11，因此我們使用 `pip3`和 `python3`命令。如需詳細資訊，請參閱 Python 平台主題[特定執行時間版本的呼叫](service-source-code-python.md#service-source-code-python.callouts)中的 。

**Example apprunner.yaml**  

```
version: 1.0
runtime: python311
build:
  commands:
    pre-build:
      - wget -c https://s3.amazonaws.com/amzn-s3-demo-bucket/test-lib.tar.gz -O - | tar -xz
    build:        
      - pip3 install pipenv
      - pipenv install
    post-build:
      - python3 manage.py test
  env:
    - name: DJANGO_SETTINGS_MODULE
      value: "django_apprunner.settings"
    - name: MY_VAR_EXAMPLE
      value: "example"
run:
  runtime-version: {{3.11}}
  pre-run:  
    - pip3 install pipenv
    - pipenv install
    - python3 copy-global-files.py
  command: pipenv run gunicorn django_apprunner.wsgi --log-file -
  network: 
    port: 8000
    env: MY_APP_PORT  
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
  secrets:
    - name: my-secret
      value-from: "arn:aws:secretsmanager:us-east-1:123456789012:secret:testingstackAppRunnerConstr-kJFXde2ULKbT-S7t8xR:username::"
    - name: my-parameter
      value-from: "arn:aws:ssm:us-east-1:123456789012:parameter/parameter-name"
    - name: my-parameter-only-name
      value-from: "parameter-name"
```

如需特定受管執行期組態檔案的範例，請參閱 下的特定執行期子主題[程式碼型服務](service-source-code.md)。