View a markdown version of this page

App Runner 組態檔案範例 - AWS App Runner

AWS App Runner 不再開放給新客戶。現有客戶可以繼續正常使用該服務。如需詳細資訊,請參閱AWS App Runner 可用性變更

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

App Runner 組態檔案範例

注意

組態檔案僅適用於以原始程式碼為基礎的服務。您無法搭配映像型服務使用組態檔案。

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

組態檔案範例

透過最少的組態檔案,App Runner 會做出下列假設:

  • 在建置或執行期間,不需要自訂環境變數。

  • 使用最新的執行時間版本。

  • 使用預設連接埠號碼和連接埠環境變數。

範例 apprunner.yaml
version: 1.0 runtime: python3 build: commands: build: - pip install pipenv - pipenv install run: command: python app.py

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

範例 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"

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

只有修訂後的 App Runner 組建才支援 pre-run 參數。如果您的應用程式使用原始 App Runner 組建支援的執行時間版本,請勿將此參數插入您的組態檔案中。如需詳細資訊,請參閱受管執行期版本和 App Runner 組建

注意

由於此範例適用於 Python 3.11,因此我們使用 pip3python3命令。如需詳細資訊,請參閱 Python 平台主題特定執行時間版本的呼叫中的 。

範例 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"

如需特定受管執行期組態檔案的範例,請參閱 下的特定執行期子主題程式碼型服務