

AWS App Runner 自 2026 年 4 月 30 日起，不再開放給新客戶。如果您想要使用 App Runner，請在該日期之前註冊。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS App Runner 可用性變更](https://docs.aws.amazon.com/apprunner/latest/dg/apprunner-availability-change.html)。

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

# 以原始程式碼為基礎的 App Runner 服務
<a name="service-source-code"></a>

您可以使用 根據兩種基本不同的服務來源類型 AWS App Runner 來建立和管理服務：*來源碼*和*來源映像*。無論來源類型為何，App Runner 都會負責啟動、執行、擴展和負載平衡您的服務。您可以使用 App Runner 的 CI/CD 功能來追蹤來源映像或程式碼的變更。當 App Runner 發現變更時，它會自動建置 （適用於原始程式碼） 並將新版本部署到您的 App Runner 服務。

本章討論以來源碼為基礎的 服務。如需以來源映像為基礎的服務資訊，請參閱 [以來源映像為基礎的 App Runner 服務](service-source-image.md)。

原始程式碼是 App Runner 為您建置和部署的應用程式程式碼。您可以將 App Runner 指向程式碼儲存庫中的[來源目錄](#service-source-code.source-directory)，然後選擇對應於程式設計平台版本的合適*執行時間*。App Runner 會根據執行時間的基礎映像和您的應用程式程式碼來建置映像。然後，它會啟動根據此映像執行容器的服務。

 App Runner 提供便利的平台特定*受管執行時間*。這些執行時間中的每一個都會從您的原始程式碼建置容器映像，並將語言執行時間相依性新增至映像。您不需要提供容器組態和建置指示，例如 Dockerfile。

本章的子主題討論 App Runner 支援的各種平台：為不同的程式設計環境和版本提供受管執行期的*受管平台*。

**Topics**
+ [原始程式碼儲存庫提供者](#service-source-code.providers)
+ [來源目錄](#service-source-code.source-directory)
+ [App Runner 受管平台](#service-source-code.managed-platforms)
+ [受管執行時間版本的終止支援](#service-source-code.managed-platforms.eos)
+ [受管執行期版本和 App Runner 組建](#service-source-code.build-detail)
+ [使用 Python 平台](service-source-code-python.md)
+ [使用 Node.js 平台](service-source-code-nodejs.md)
+ [使用 Java 平台](service-source-code-java.md)
+ [使用 .NET 平台](service-source-code-net6.md)
+ [使用 PHP 平台](service-source-code-php.md)
+ [使用 Ruby 平台](service-source-code-ruby.md)
+ [使用 Go 平台](service-source-code-go1.md)

## 原始程式碼儲存庫提供者
<a name="service-source-code.providers"></a>

App Runner 透過從原始程式碼儲存庫讀取原始程式碼來部署原始程式碼。App Runner 支援兩個原始程式碼儲存庫提供者：[GitHub](https://github.com/) 和 [Bitbucket](https://bitbucket.org/)。

### 從原始碼儲存庫供應商部署
<a name="service-source-code.providers.github"></a>

若要從原始碼儲存庫將原始碼部署至 App Runner 服務，App Runner 會建立與其的連線。當您使用 App Runner 主控台[建立服務](manage-create.md)時，您會提供連線詳細資訊和來源目錄，讓 App Runner 部署您的原始程式碼。

**連線**  
您可以在服務建立程序中提供連線詳細資訊。當您使用 App Runner API 或 時 AWS CLI，連線是個別的資源。首先，您可以使用 [CreateConnection](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateConnection.html) API 動作建立連線。然後，您可以使用 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) API 動作在建立服務期間提供連線的 ARN。

**來源目錄**  
當您建立服務時，您也會提供來源目錄。根據預設，App Runner 會使用儲存庫的根目錄做為來源目錄。來源目錄是原始碼儲存庫中存放應用程式原始碼和組態檔案的位置。建置和啟動命令也會從來源目錄執行。當您使用 App Runner API 或 AWS CLI 來建立或更新服務時，您會在 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) 和 [UpdateService](https://docs.aws.amazon.com/apprunner/latest/api/API_UpdateService.html) API 動作中提供來源目錄。如需詳細資訊，請參閱下面的[來源目錄](#service-source-code.source-directory)章節。

如需建立 App Runner 服務的詳細資訊，請參閱 [建立 App Runner 服務](manage-create.md)。如需 App Runner 連線的詳細資訊，請參閱 [管理 App Runner 連線](manage-connections.md)。

## 來源目錄
<a name="service-source-code.source-directory"></a>

當您建立 App Runner 服務時，您可以提供來源目錄，以及儲存庫和分支。將**來源目錄**欄位的值設定為儲存應用程式的原始碼和組態檔案的儲存庫目錄路徑。App Runner 會從您提供的來源目錄路徑執行建置和啟動命令。

輸入來源目錄路徑的值做為根儲存庫目錄的絕對值。如果您未指定值，它會預設為儲存庫頂層目錄，也稱為儲存庫根目錄。

除了頂層儲存庫目錄之外，您還可以選擇提供不同的來源目錄路徑。這支援單儲存庫架構，這表示多個應用程式的原始碼存放在一個儲存庫中。若要從單一單一儲存庫建立和支援多個 App Runner 服務，請在建立每個服務時指定不同的來源目錄。

**注意**  
如果您為多個 App Runner 服務指定相同的來源目錄，這兩個服務都會個別部署和操作。

如果您選擇使用`apprunner.yaml`組態檔案來定義您的服務參數，請將它放在儲存庫的來源目錄資料夾中。

如果**部署觸發**選項設定為**自動**，則您在來源目錄中遞交的變更將觸發自動部署。*只有來源目錄路徑中的變更*才會觸發自動部署。請務必了解來源目錄的位置如何影響自動部署的範圍。如需詳細資訊，請參閱 中的*自動化部署*[部署方法](manage-deploy.md#manage-deploy.methods)。

**注意**  
如果您的 App Runner 服務使用 PHP 受管執行期，而且您想要指定預設根儲存庫以外的來源目錄，請務必使用正確的 PHP 執行期版本。如需詳細資訊，請參閱[使用 PHP 平台](service-source-code-php.md)。

## App Runner 受管平台
<a name="service-source-code.managed-platforms"></a>

App Runner 受管平台為各種程式設計環境提供受管執行期。每個受管執行期都可讓您根據程式設計語言或執行期環境的版本輕鬆建置和執行容器。當您使用受管執行期時，App Runner 會從受管執行期映像開始。此映像以 [Amazon Linux Docker 映像](https://hub.docker.com/_/amazonlinux)為基礎，並包含語言執行期套件，以及一些工具和熱門的相依性套件。App Runner 使用此受管執行期映像做為基礎映像，並新增您的應用程式程式碼來建置 Docker 映像。然後，它會部署此映像，以在容器中執行您的 Web 服務。

 當您使用 App Runner 主控台或 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) API 操作[建立服務時，](manage-create.md)您可以指定 App Runner 服務的執行時間。您也可以指定執行時間做為原始程式碼的一部分。在程式碼儲存庫中包含的 [App Runner 組態檔案中](config-file.md)使用 `runtime`關鍵字。受管執行時間的命名慣例為 *<language-name><major-version>*。

App Runner 會在每次部署或服務更新時，將服務的執行時間更新為最新版本。如果您的應用程式需要特定版本的受管執行時間，您可以使用 [App Runner 組態檔案中](config-file.md)的 `runtime-version`關鍵字來指定它。您可以鎖定任何層級的版本，包括主要或次要版本。App Runner 只會對服務的執行時間進行較低層級的更新。

## 受管執行時間版本的終止支援
<a name="service-source-code.managed-platforms.eos"></a>

當受管語言執行時間的官方提供者或社群正式宣告版本為生命週期結束 (EOL) 時，App Runner 會接著宣告版本狀態為*終止支援*。如果您的服務在已達到終止支援的受管語言執行時間版本上執行，則適用下列政策和建議。

**語言執行時間版本的終止支援：**
+ **現有的服務**將繼續執行並為流量提供服務，即使他們使用的執行時間已達到終止支援。不過，它們將在不再接收更新、安全修補程式或技術支援的不支援執行時間上執行。
+ 仍然允許更新使用終止支援執行時間的**現有服務**，但不建議繼續為服務使用終止支援執行時間。
+ 無法使用已達終止支援日期的執行時間**建立新服務**。

**具有終止支援狀態的語言版本所需的動作：**
+ 如果您的服務是以**來源映像為基礎**，則不需要對該服務採取進一步的動作。
+ 如果您的服務是以**原始程式碼為基礎**，請更新您的服務組態以使用支援的執行時間版本。若要這樣做，請在 [App Runner 主控台](https://console.aws.amazon.com/apprunner)中選取支援的執行時間版本、更新 [apprunner.yaml](config-file.md) 組態檔案中`runtime`的欄位，或使用 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html)/[UpdateService](https://docs.aws.amazon.com/apprunner/latest/api/API_UpdateService.html) API 操作或 IaC 工具來設定 `runtime` 參數。如需支援的執行時間清單，請參閱本章中任何特定執行時間的*版本資訊*頁面。
+ 或者，您可以切換到 App Runner 的**容器映像來源**選項。如需詳細資訊，請參閱[影像型服務](service-source-image.md)。

**注意**  
如果您要從 Node.js 12、14 或 16 移至 **Node.js 22**，或從 Python 3.7 或 3.8 移至 **Python 3.11**，請注意 Node.js 22 和 Python 3.11 會使用修訂過的 App Runner 建置程序，以提供更快且更有效率的建置。若要在升級之前確保相容性，建議您檢閱下一節中的[建置程序指引](#service-source-code.build-detail)。

下表列出具有指定終止支援日期的 App Runner 受管執行期版本。


| **執行時間版本** | **App Runner 終止支援日期** | 
| --- | --- | 
|  Python 3.8 [支援的執行時間](service-source-code-python-releases.md)  |  2025 年 12 月 1 日  | 
|  Python 3.7 [支援的執行時間](service-source-code-python-releases.md)  |  2025 年 12 月 1 日  | 
|  Node.js 18 [支援的執行時間](service-source-code-nodejs-releases.md)  |  2025 年 12 月 1 日  | 
|  Node.js 16 [支援的執行時間](service-source-code-nodejs-releases.md)  |  2025 年 12 月 1 日  | 
|  Node.js 14 [支援的執行時間](service-source-code-nodejs-releases.md)  |  2025 年 12 月 1 日  | 
|  Node.js 12 [支援的執行時間](service-source-code-nodejs-releases.md)  |  2025 年 12 月 1 日  | 
|  .NET 6 \$1  |  2025 年 12 月 1 日  | 
|  PHP 8.1 \$1  |  2025 年 12 月 31 日  | 
|  Ruby 3.1 \$1  |  2025 年 12 月 1 日  | 
|  Go 1 \$1  | 2025 年 12 月 1 日 | 

**\$1** App Runner 不會為標示星號 (\$1) 的執行時間發行任何新語言版本。這些執行時間如下：.NET、PHP、Ruby 和 Go。如果您為這些執行時間設定了程式碼型服務，我們建議您執行下列其中一個動作：
+ 如果適用，請將您的服務組態切換到不同的受支援受管執行時間。
+ 或者，使用您偏好的執行時間版本建置自訂容器映像，並使用 App Runner [影像型服務](service-source-image.md)的選項進行部署。您可以在 Amazon ECR 中託管映像。

## 受管執行期版本和 App Runner 組建
<a name="service-source-code.build-detail"></a>

App Runner 為在較近期主要版本執行時間上執行的應用程式提供更新的建置程序。此修訂後的建置程序更快速且更有效率。它也會建立佔用空間較小的最終映像，只包含執行應用程式所需的原始程式碼、建置成品和執行時間。

我們將較新的建置程序稱為*修訂後的 App Runner 組建*，並將原始建置程序稱為*原始 App Runner 組建*。為了避免破壞舊版執行時間平台的變更，App Runner 只會將修訂後的組建套用至特定執行時間版本，通常是新發行的主要版本。

我們已將新元件引入 `apprunner.yaml`組態檔案，讓修訂後的組建與非常特定的使用案例回溯相容，並提供更多彈性來設定應用程式的組建。這是選用[`pre-run`](config-file-ref.md#config-file-ref.run)參數。我們會說明何時使用此參數，以及以下各節中有關組建的其他實用資訊。

下表說明哪些版本的 App Runner 組建適用於特定的受管執行時間版本。我們會繼續更新本文件，讓您隨時了解我們目前的執行時間。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code.html)

**注意**  
某些列出的執行時間包括**終止支援**日期。如需詳細資訊，請參閱[受管執行時間版本的終止支援](#service-source-code.managed-platforms.eos)。

**重要**  
**Python 3.11** – 對於使用 Python 3.11 受管執行時間的服務建置組態，我們提供特定建議。如需詳細資訊，請參閱 *Python 平台*主題[特定執行時間版本的呼叫](service-source-code-python.md#service-source-code-python.callouts)中的 。

### App Runner 建置和遷移的詳細資訊
<a name="service-source-code.build-detail.builds-and-migr"></a>

當您將應用程式遷移至使用修訂組建的較新執行期時，您可能需要稍微修改組建組態。

為了提供遷移考量的內容，我們會先說明原始 App Runner 組建和修訂組建的高階程序。接下來我們將有一個章節，說明可能需要一些組態更新之服務的特定屬性。

#### 原始 App Runner 組建
<a name="service-source-code.build-detail.v1"></a>

原始 App Runner 應用程式建置程序會利用 AWS CodeBuild 服務。初始步驟是根據 CodeBuild 服務所策劃的影像。以下 Docker 建置程序會使用適用的 App Runner 受管執行期映像做為基礎映像。

一般步驟如下：

1. 在 CodeBuild 策劃的映像中執行`pre-build`命令。

   這些`pre-build`命令是選用的。它們只能在`apprunner.yaml`組態檔案中指定。

1. 在上一個步驟的相同映像上使用 CodeBuild 執行`build`命令。

   `build` 命令是必要的。它們可以在 App Runner 主控台、App Runner API 或`apprunner.yaml`組態檔案中指定。

1. 執行 Docker 組建，根據特定平台和執行期版本的 App Runner 受管執行期映像產生映像。

1. 從我們在**步驟 2 **中產生的映像複製`/app`目錄。目的地是根據我們在**步驟 3** 中產生的 App Runner 受管執行期映像的映像。

1. 在產生的 App Runner 受管執行期映像上再次執行`build`命令。我們會再次執行組建命令，從我們在**步驟 4 **中複製的`/app`目錄中的原始程式碼產生組建成品。App Runner 稍後會部署此映像，以在容器中執行您的 Web 服務。

   `build` 命令是必要的。它們可以在 App Runner 主控台、App Runner API 或`apprunner.yaml`組態檔案中指定。

1. 在**步驟 2** 的 CodeBuild 映像中執行`post-build`命令。

   這些`post-build`命令是選用的。它們只能在`apprunner.yaml`組態檔案中指定。

建置完成後，App Runner 會從**步驟 5** 部署產生的 App Runner 受管執行期映像，以在容器中執行您的 Web 服務。

#### 修訂後的 App Runner 組建
<a name="service-source-code.build-detail.v2"></a>

修訂後的建置程序比上一節所述的原始建置程序更快且更有效率。它消除了先前版本組建中發生的組建命令的重複。它也會建立佔用空間較小的最終映像，只包含執行應用程式所需的原始程式碼、建置成品和執行時間。

此建置程序使用 Docker 多階段建置。一般程序步驟如下：

1. **建置階段** — 在 App Runner 建置映像之上啟動執行 `pre-build`和 `build`命令的 Docker 建置程序。

   1. 將應用程式原始碼複製到 `/app`目錄。
**注意**  
此`/app`目錄會在 Docker 組建的每個階段中指定為工作目錄。

   1. 執行 `pre-build` 命令。

      這些`pre-build`命令是選用的。它們只能在`apprunner.yaml`組態檔案中指定。

   1. 執行`build`命令。

      `build` 命令是必要的。它們可以在 App Runner 主控台、App Runner API 或`apprunner.yaml`組態檔案中指定。

1. **封裝階段** — 產生最終客戶容器映像，這也以 App Runner 執行映像為基礎。

   1. 將`/app`目錄從先前的**建置階段**複製到新的執行映像。這包括您的應用程式原始程式碼和上一個階段的建置成品。

   1. 執行`pre-run`命令。如果您需要使用 `build`命令修改`/app`目錄外部的執行期映像，請將相同或必要的命令新增至`apprunner.yaml`組態檔案的此區段。

      這是為了支援修訂後的 App Runner 建置而引入的新參數。

      這些`pre-run`命令是選用的。它們只能在`apprunner.yaml`組態檔案中指定。
**備註**  
`pre-run` 命令僅受修訂的組建支援。如果您的服務使用使用原始建置的執行期版本，請勿將其新增至組態檔案。
如果您不需要使用 `build`命令修改`/app`目錄外的任何內容，則不需要指定`pre-run`命令。

1. **建置後階段** — 此階段會從*建置階段*繼續並執行`post-build`命令。

   1. 在 `/app`目錄中執行`post-build`命令。

      這些`post-build`命令是選用的。它們只能在`apprunner.yaml`組態檔案中指定。

建置完成後，App Runner 接著會部署執行映像，以在容器中執行您的 Web 服務。

**注意**  
設定建置程序`apprunner.yaml`時，請勿誤導至 執行區段中的`env`項目。即使**步驟 2(b)** 中參考的`pre-run`命令參數位於執行區段中，也請勿使用執行區段中的 `env` 參數來設定建置。這些`pre-run`命令只會參考組態檔案建置區段中定義的`env`變數。如需詳細資訊，請參閱 *App Runner 組態檔案章節*[執行區段](config-file-ref.md#config-file-ref.run)中的 。

#### 遷移考量的服務需求
<a name="service-source-code.build-detail.migrating"></a>

如果您的應用程式環境有這兩個需求之一，則您需要透過新增`pre-run`命令來修改建置組態。
+ 如果您需要使用 `build`命令修改`/app`目錄外的任何內容。
+ 如果您需要執行`build`命令兩次，以建立所需的環境。這是非常不尋常的要求。絕大多數的組建都不會這樣做。

**`/app`目錄外的修改**
+ [修訂後的 App Runner 組建](#service-source-code.build-detail.v2)假設您的應用程式在 `/app` 目錄外沒有相依性。
+ 您隨`apprunner.yaml`檔案、App Runner API 或 App Runner 主控台提供的命令必須在 `/app`目錄中產生建置成品。
+ 您可以修改 `pre-build`、 `build`和 `post-build`命令，以確保所有建置成品都位於 `/app`目錄中。
+ 如果您的應用程式需要 建置進一步修改服務產生的映像，您可以在 `/app` 目錄中使用新`pre-run`命令`apprunner.yaml`。如需詳細資訊，請參閱[使用組態檔案設定 App Runner 服務選項](config-file.md)。

**執行`build`命令兩次**
+ [原始 App Runner 組建](#service-source-code.build-detail.v1)會執行`build`命令兩次，首先在**步驟 2 **中執行，然後再次在**步驟 5 **中執行。修訂後的 App Runner 組建可修復此備援，而且只會執行`build`命令一次。如果您的應用程式應該對`build`命令執行兩次有不尋常的需求，修訂後的 App Runner 組建會提供使用 `pre-run` 參數再次指定和執行相同命令的選項。這樣做會保留相同的雙組建行為。

# 使用 Python 平台
<a name="service-source-code-python"></a>

**重要**  
App Runner 將於 2025 年 12 月 1 日結束對 **Python 3.7** 和 **Python 3.8** 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

 AWS App Runner Python 平台提供受管執行期。每個執行時間都可讓您根據 Python 版本使用 Web 應用程式輕鬆建置和執行容器。當您使用 Python 執行期時，App Runner 會從受管 Python 執行期映像開始。此映像以 [Amazon Linux Docker 映像](https://hub.docker.com/_/amazonlinux)為基礎，包含 Python 版本的執行時間套件，以及一些工具和熱門的相依性套件。App Runner 使用此受管執行期映像做為基礎映像，並新增您的應用程式程式碼來建置 Docker 映像。然後，它會部署此映像，以在容器中執行您的 Web 服務。

 當您使用 App Runner 主控台或 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) API 操作[建立服務時，](manage-create.md)您可以指定 App Runner 服務的執行時間。您也可以指定執行時間做為原始程式碼的一部分。在程式碼儲存庫中包含的 [App Runner 組態檔案中](config-file.md)使用 `runtime`關鍵字。受管執行時間的命名慣例為 *<language-name><major-version>*。

如需有效的 Python 執行期名稱和版本，請參閱 [Python 執行期發行資訊](service-source-code-python-releases.md)。

App Runner 會在每次部署或服務更新時，將服務的執行時間更新為最新版本。如果您的應用程式需要特定版本的受管執行時間，您可以使用 [App Runner 組態檔案中](config-file.md)的 `runtime-version`關鍵字來指定它。您可以鎖定任何層級的版本，包括主要或次要版本。App Runner 只會對服務的執行時間進行較低層級的更新。

Python 執行時間的版本語法： `major[.minor[.patch]]`

例如：`3.8.5`

下列範例示範版本鎖定：
+ `3.8` – 鎖定主要和次要版本。App Runner 只會更新修補程式版本。
+ `3.8.5` – 鎖定至特定修補程式版本。App Runner 不會更新您的執行時間版本。

**Topics**
+ [Python 執行期組態](#service-source-code-python.config)
+ [特定執行時間版本的呼叫](#service-source-code-python.callouts)
+ [Python 執行時間範例](#service-source-code-python.examples)
+ [Python 執行期發行資訊](service-source-code-python-releases.md)

## Python 執行期組態
<a name="service-source-code-python.config"></a>

當您選擇受管執行時間時，您也必須至少設定建置和執行命令。您可以在[建立](manage-create.md)或[更新](manage-configure.md) App Runner 服務時設定它們。您可以使用下列其中一種方法執行此操作：
+ **使用 App Runner 主控台** – 在建立程序或組態索引標籤的設定**建置**區段中指定命令。
+ **使用 App Runner API** – 呼叫 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) 或 [UpdateService](https://docs.aws.amazon.com/apprunner/latest/api/API_UpdateService.html) API 操作。使用 [CodeConfigurationValues](https://docs.aws.amazon.com/apprunner/latest/api/API_CodeConfigurationValues.html) 資料類型的 `BuildCommand`和 `StartCommand`成員指定命令。
+ **使用[組態檔案](config-file.md)** – 在最多三個建置階段指定一或多個建置命令，以及用於啟動應用程式的單一執行命令。還有其他選用的組態設定。

提供組態檔案是選用的。當您使用主控台或 API 建立 App Runner 服務時，您可以指定 App Runner 在建立時直接從組態檔案取得您的組態設定。

## 特定執行時間版本的呼叫
<a name="service-source-code-python.callouts"></a>

**注意**  
App Runner 現在會根據下列執行時間版本執行應用程式的更新建置程序：Python 3.11、Node.js 22 和 Node.js 18。如果您的應用程式在其中一個執行時間版本上執行，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail) 以取得修訂建置程序的詳細資訊。使用所有其他執行時間版本的應用程式不會受到影響，而且會繼續使用原始建置程序。

### Python 3.11 （已修訂 App Runner 組建）
<a name="service-source-code-python.callouts.python311"></a>

針對受管 Python 3.11 執行時間，在 *apprunner.yaml* 中使用下列設定。
+ 將頂端區段中的`runtime`金鑰設定為 `python311`   
**Example**  

  ```
  runtime: python311
  ```
+ 使用 `pip3`而非 `pip` 安裝相依性。
+ 使用`python3`解譯器而非 `python`。
+ 以`pre-run`命令執行`pip3`安裝程式。Python 會在 `/app`目錄之外安裝相依性。由於 App Runner 會針對 Python 3.11 執行修訂後的 App Runner 組建，因此透過 `apprunner.yaml` 檔案組建區段中的命令在`/app`目錄外安裝的任何內容都會遺失。如需詳細資訊，請參閱[修訂後的 App Runner 組建](service-source-code.md#service-source-code.build-detail.v2)。  
**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 -
  ```

如需詳細資訊，請參閱本主題稍後[的 Python 3.11 擴充組態檔案範例。](#service-source-code-python.examples.extended-v2)

## Python 執行時間範例
<a name="service-source-code-python.examples"></a>

下列範例顯示用於建置和執行 Python 服務的 App Runner 組態檔案。最後一個範例是完整 Python 應用程式的原始程式碼，您可以部署到 Python 執行時間服務。

**注意**  
這些範例中使用的執行時間版本為 *3.7.7* 和 *3.11。*您可以將其取代為您想要使用的版本。如需最新支援的 Python 執行期版本，請參閱 [Python 執行期發行資訊](service-source-code-python-releases.md)。

### 最小 Python 組態檔案
<a name="service-source-code-python.examples.minimal"></a>

此範例顯示您可以搭配 Python 受管執行時間使用的最小組態檔案。如需 App Runner 使用最小組態檔案所做的假設，請參閱 [組態檔案範例](config-file-examples.md#config-file-examples.managed)。

Python 3.11 使用 `pip3`和 `python3`命令。如需詳細資訊，請參閱本主題稍後[的 Python 3.11 擴充組態檔案範例。](#service-source-code-python.examples.extended-v2)

**Example apprunner.yaml**  

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

### 擴充 Python 組態檔案
<a name="service-source-code-python.examples.extended"></a>

此範例顯示使用具有 Python 受管執行時間的所有組態金鑰。

**注意**  
這些範例中使用的執行時間版本是 *3.7.7*。您可以將其取代為您想要使用的版本。如需最新支援的 Python 執行期版本，請參閱 [Python 執行期發行資訊](service-source-code-python-releases.md)。  
Python 3.11 使用 `pip3`和 `python3`命令。如需詳細資訊，請參閱本主題稍後的 Python 3.11 擴充組態檔案範例。

**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"
```

### 擴充 Python 組態檔案 — Python 3.11 （使用修訂的組建）
<a name="service-source-code-python.examples.extended-v2"></a>

此範例顯示在 中使用所有組態金鑰搭配 Python 3.11 受管執行時間。 `apprunner.yaml`此範例包含 `pre-run`區段，因為此版本的 Python 使用修訂過的 App Runner 建置。

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

**注意**  
這些範例中使用的執行時間版本為 *3.11。*您可以將其取代為您想要使用的版本。如需最新支援的 Python 執行期版本，請參閱 [Python 執行期發行資訊](service-source-code-python-releases.md)。

**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"
```

### 完成 Python 應用程式來源
<a name="service-source-code-python.examples.end2end"></a>

此範例顯示您可以部署到 Python 執行期服務的完整 Python 應用程式的原始程式碼。

**Example requirements.txt**  

```
pyramid==2.0
```

**Example server.py**  

```
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
import os

def hello_world(request):
    name = os.environ.get('NAME')
    if name == None or len(name) == 0:
        name = "world"
    message = "Hello, " + name + "!\n"
    return Response(message)

if __name__ == '__main__':
    port = int(os.environ.get("PORT"))
    with Configurator() as config:
        config.add_route('hello', '/')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()
    server = make_server('0.0.0.0', port, app)
    server.serve_forever()
```

**Example apprunner.yaml**  

```
version: 1.0
runtime: python3
build:
  commands:
    build:
      - pip install -r requirements.txt
run:
  command: python server.py
```

# Python 執行期發行資訊
<a name="service-source-code-python-releases"></a>

**重要**  
App Runner 將於 2025 年 12 月 1 日結束對 **Python 3.7** 和 **Python 3.8** 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

本主題列出 App Runner 支援的 Python 執行期版本的完整詳細資訊。


**支援的執行時間版本 — 修訂後的 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-python-releases.html)

**備註**  
**Python 3.11** – 對於使用 Python 3.11 受管執行時間的服務建置組態，我們提供特定建議。如需詳細資訊，請參閱 *Python 平台*主題[特定執行時間版本的呼叫](service-source-code-python.md#service-source-code-python.callouts)中的 。
App Runner 為最近發佈的特定主要執行時間提供修訂後的建置程序。因此，您會在本文件的特定章節中看到已*修訂的 App Runner 組建*和*原始 App Runner 組建*的參考。如需詳細資訊，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail)。


**支援的執行時間版本 — 原始 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-python-releases.html)

**注意**  
App Runner 為最近發佈的特定主要執行時間提供修訂後的建置程序。因此，您會在本文件的特定章節中看到已*修訂的 App Runner 組建*和*原始 App Runner 組建*的參考。如需詳細資訊，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail)。

# 使用 Node.js 平台
<a name="service-source-code-nodejs"></a>

**重要**  
App Runner 將於 **2025 年 12 月 1 日結束對 Node.js** 12、**Node.js 14**、**Node.js 16** 和 **Node.js 18** 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

 AWS App Runner Node.js 平台提供受管執行期。每個執行時間都可讓您根據 Node.js 版本使用 Web 應用程式輕鬆建置和執行容器。當您使用 Node.js 執行期時，App Runner 會從受管 Node.js 執行期映像開始。此映像以 [Amazon Linux Docker 映像](https://hub.docker.com/_/amazonlinux)為基礎，並包含 Node.js 版本和一些工具的執行時間套件。App Runner 使用此受管執行期映像做為基礎映像，並新增您的應用程式程式碼來建置 Docker 映像。然後，它會部署此映像，以在容器中執行您的 Web 服務。

 當您使用 App Runner 主控台或 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) API 操作[建立服務時，](manage-create.md)您可以指定 App Runner 服務的執行時間。您也可以指定執行時間做為原始程式碼的一部分。在程式碼儲存庫中包含的 [App Runner 組態檔案中](config-file.md)使用 `runtime`關鍵字。受管執行時間的命名慣例為 *<language-name><major-version>*。

如需有效的 Node.js 執行時間名稱和版本，請參閱 [Node.js 執行時間版本資訊](service-source-code-nodejs-releases.md)。

App Runner 會在每次部署或服務更新時，將服務的執行時間更新為最新版本。如果您的應用程式需要特定版本的受管執行時間，您可以使用 [App Runner 組態檔案中](config-file.md)的 `runtime-version`關鍵字來指定它。您可以鎖定任何層級的版本，包括主要或次要版本。App Runner 只會對服務的執行時間進行較低層級的更新。

Node.js 執行時間的版本語法： `major[.minor[.patch]]`

例如：`22.14.0`

下列範例示範版本鎖定：
+ `22.14` – 鎖定主要和次要版本。App Runner 只會更新修補程式版本。
+ `22.14.0` – 鎖定至特定修補程式版本。App Runner 不會更新您的執行時間版本。

**Topics**
+ [Node.js 執行期組態](#service-source-code-nodejs.config)
+ [特定執行時間版本的呼叫](#service-source-code-nodejs.callouts)
+ [Node.js 執行時間範例](#service-source-code-nodejs.examples)
+ [Node.js 執行時間版本資訊](service-source-code-nodejs-releases.md)

## Node.js 執行期組態
<a name="service-source-code-nodejs.config"></a>

當您選擇受管執行時間時，您也必須至少設定建置和執行命令。您可以在[建立](manage-create.md)或[更新](manage-configure.md) App Runner 服務時設定它們。您可以使用下列其中一種方法執行此操作：
+ **使用 App Runner 主控台** – 在建立程序或組態索引標籤的設定**建置**區段中指定命令。
+ **使用 App Runner API** – 呼叫 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) 或 [UpdateService](https://docs.aws.amazon.com/apprunner/latest/api/API_UpdateService.html) API 操作。使用 [CodeConfigurationValues](https://docs.aws.amazon.com/apprunner/latest/api/API_CodeConfigurationValues.html) 資料類型的 `BuildCommand`和 `StartCommand`成員指定命令。
+ **使用[組態檔案](config-file.md)** – 在最多三個建置階段指定一或多個建置命令，以及用於啟動應用程式的單一執行命令。還有其他選用的組態設定。

提供組態檔案是選用的。當您使用主控台或 API 建立 App Runner 服務時，您可以指定 App Runner 在建立時直接從組態檔案取得您的組態設定。

特別是使用 Node.js 執行時間，您也可以使用來源儲存庫根`package.json`目錄中名為 的 JSON 檔案來設定建置和執行時間。使用此檔案，您可以設定 Node.js 引擎版本、相依性套件和各種命令 （命令列應用程式）。npm 或 yarn 等套件管理員會將此檔案解譯為其命令的輸入。

例如：
+ **npm install** 在 中安裝由 `dependencies`和 `devDependencies`節點定義的套件`package.json`。
+ **npm start** 或 會**npm run start**執行 中`scripts/start`節點定義的命令`package.json`。

以下是範例 `package.json` 檔案。

### package.json
<a name="service-source-code-nodejs.config.package-json-example"></a>

```
{
  "name": "node-js-getting-started",
  "version": "0.3.0",
  "description": "A sample Node.js app using Express 4",
  "engines": {
    "node": "22.14.0"
  },
  "scripts": {
    "start": "node index.js",
    "test": "node test.js"
  },
  "dependencies": {
    "cool-ascii-faces": "^1.3.4",
    "ejs": "^2.5.6",
    "express": "^4.15.2"
  },
  "devDependencies": {
    "got": "^11.3.0",
    "tape": "^4.7.0"
  }
}
```

如需 的詳細資訊`package.json`，請參閱 *npm Docs* 網站上的[建立 package.json 檔案](https://docs.npmjs.com/creating-a-package-json-file)。

**提示**  
如果您的`package.json`檔案定義了**start**命令，您可以在 App Runner 組態檔案中將其用作**run**命令，如下列範例所示。  

**Example**  
package.json  

  ```
  {
    "scripts": {
      "start": "node index.js"
    }
  }
  ```
apprunner.yaml  

  ```
  run:
    command: npm start
  ```
當您**npm install**在開發環境中執行 時，npm 會建立 檔案 `package-lock.json`。此檔案包含剛安裝的套件版本 npm 的快照。之後，當 npm 安裝相依性時，它會使用這些確切版本。如果您安裝 yarn，它會建立 `yarn.lock` 檔案。將這些檔案遞交至原始碼儲存庫，以確保您的應用程式已安裝您開發和測試的相依性版本。
您也可以使用 App Runner 組態檔案來設定 Node.js 版本和啟動命令。當您這樣做時，這些定義會覆寫 中的定義`package.json`。中的`node`版本`package.json`與 App Runner 組態檔案中`runtime-version`的值衝突會導致 App Runner 建置階段失敗。

## 特定執行時間版本的呼叫
<a name="service-source-code-nodejs.callouts"></a>

### Node.js 22 和 Node.js 18 （已修訂 App Runner 組建）
<a name="service-source-code-nodejs.callouts.nodejs18"></a>

App Runner 現在會根據下列執行時間版本執行應用程式的更新建置程序：Python 3.11、Node.js 22 和 Node.js 18。如果您的應用程式在其中一個執行時間版本上執行，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail) 以取得修訂建置程序的詳細資訊。使用所有其他執行時間版本的應用程式不會受到影響，而且會繼續使用原始建置程序。

## Node.js 執行時間範例
<a name="service-source-code-nodejs.examples"></a>

下列範例顯示用於建置和執行 Node.js 服務的 App Runner 組態檔案。

**注意**  
這些範例中使用的執行時間版本為 *22.14.0*。您可以將其取代為您想要使用的版本。如需最新支援的 Node.js 執行時間版本，請參閱 [Node.js 執行時間版本資訊](service-source-code-nodejs-releases.md)。

### 最小 Node.js 組態檔案
<a name="service-source-code-nodejs.examples.minimal"></a>

此範例顯示您可以搭配 Node.js 受管執行時間使用的最小組態檔案。如需 App Runner 使用最小組態檔案所做的假設，請參閱 [組態檔案範例](config-file-examples.md#config-file-examples.managed)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: nodejs22
build:
  commands:    
    build:
      - npm install --production                                  
run:                              
  command: node app.js
```

### 擴充 Node.js 組態檔案
<a name="service-source-code-nodejs.examples.extended"></a>

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

**注意**  
這些範例中使用的執行時間版本為 *22.14.0*。您可以將其取代為您想要使用的版本。如需最新支援的 Node.js 執行時間版本，請參閱 [Node.js 執行時間版本資訊](service-source-code-nodejs-releases.md)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: nodejs22
build:
  commands:
    pre-build:
      - npm install --only=dev
      - node test.js
    build:
      - npm install --production
    post-build:
      - node node_modules/ejs/postinstall.js
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
run:
  runtime-version: 22.14.0
  command: node app.js
  network:
    port: 8000
    env: APP_PORT
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
```

### 擴充 Node.js 組態檔案 – Node.js 22 （使用修訂的組建）
<a name="service-source-code-nodejs.examples.extended-v2"></a>

此範例顯示使用 中具有 Node.js 受管執行時間的所有組態金鑰。 `apprunner.yaml`此範例包含 `pre-run`區段，因為此版本的 Node.js 使用修訂過的 App Runner 組建。

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

**注意**  
這些範例中使用的執行時間版本為 *22.14.0。*您可以將其取代為您想要使用的版本。如需最新支援的 Node.js 執行時間版本，請參閱 [Node.js 執行時間版本資訊](service-source-code-nodejs-releases.md)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: nodejs22
build:
  commands:
    pre-build:
      - npm install --only=dev
      - node test.js
    build:
      - npm install --production
    post-build:
      - node node_modules/ejs/postinstall.js
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
run:
  runtime-version: 22.14.0
  pre-run: 
    - node copy-global-files.js
  command: node app.js
  network:
    port: 8000
    env: APP_PORT
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
```

### Node.js 應用程式搭配 Grunt
<a name="service-source-code-nodejs.examples.grunt"></a>

此範例說明如何設定使用 Grunt 開發的 Node.js 應用程式。[Grunt](https://gruntjs.com/) 是命令列 JavaScript 任務執行器。它執行重複性任務並管理程序自動化，以減少人為錯誤。使用 npm 安裝和管理 Grunt 和 Grunt 外掛程式。您可以透過在來源儲存庫的根目錄中包含 `Gruntfile.js` 檔案來設定 Grunt。

**Example package.json**  

```
{
  "scripts": {
    "build": "grunt uglify",
    "start": "node app.js"
  },
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-contrib-jshint": "~0.10.0",
    "grunt-contrib-nodeunit": "~0.4.1",
    "grunt-contrib-uglify": "~0.5.0"
  },
  "dependencies": {
    "express": "^4.15.2"
  },
}
```

**Example Gruntfile.js**  

```
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      build: {
        src: 'src/<%= pkg.name %>.js',
        dest: 'build/<%= pkg.name %>.min.js'
      }
    }
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Default task(s).
  grunt.registerTask('default', ['uglify']);

};
```

**Example apprunner.yaml**  
這些範例中使用的執行時間版本為 *22.14.0*。您可以將其取代為您想要使用的版本。如需最新支援的 Node.js 執行時間版本，請參閱 [Node.js 執行時間版本資訊](service-source-code-nodejs-releases.md)。

```
version: 1.0
runtime: nodejs22
build:
  commands:
    pre-build:
      - npm install grunt grunt-cli
      - npm install --only=dev
      - npm run build
    build:
      - npm install --production
run:
  runtime-version: 22.14.0
  command: node app.js
  network:
    port: 8000
    env: APP_PORT
```

# Node.js 執行時間版本資訊
<a name="service-source-code-nodejs-releases"></a>

**重要**  
App Runner 將於 **2025 年 12 月 1 日結束對 Node.js** 12、**Node.js 14**、**Node.js 16** 和 **Node.js 18** 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

**注意**  
App Runner 的標準棄用政策是在執行時間的任何主要元件達到社群長期支援 (LTS) 結束且不再提供安全性更新時棄用執行時間。在某些情況下，App Runner 可能會在執行時間支援的語言版本end-of-support日期之後，將執行時間的棄用延遲一段有限期間。這類案例的範例可能是擴展對執行時間的支援，以允許客戶有時間進行遷移。

本主題列出 App Runner 支援的 Node.js 執行時間版本的完整詳細資訊。


**支援的執行時間版本 — 修訂後的 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-nodejs-releases.html)

**注意**  
App Runner 為最近發佈的特定主要執行時間提供修訂後的建置程序。因此，您會在本文件的特定章節中看到*修訂後的 App Runner 組建*和*原始 App Runner 組建*的參考。如需詳細資訊，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail)。


**支援的執行時間版本 — 修訂後的 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-nodejs-releases.html)




**支援的執行時間版本 — 原始 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-nodejs-releases.html)

# 使用 Java 平台
<a name="service-source-code-java"></a>

 AWS App Runner Java 平台提供受管執行期。每個執行時間都可讓您根據 Java 版本使用 Web 應用程式輕鬆建置和執行容器。當您使用 Java 執行期時，App Runner 會從受管 Java 執行期映像開始。此映像以 [Amazon Linux Docker 映像](https://hub.docker.com/_/amazonlinux)為基礎，並包含 Java 版本的執行時間套件和一些工具。App Runner 使用此受管執行期映像做為基礎映像，並新增您的應用程式程式碼來建置 Docker 映像。然後，它會部署此映像，以在容器中執行您的 Web 服務。

 當您使用 App Runner 主控台或 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) API 操作[建立服務時，](manage-create.md)您可以指定 App Runner 服務的執行時間。您也可以指定執行時間做為原始程式碼的一部分。在程式碼儲存庫中包含的 [App Runner 組態檔案中](config-file.md)使用 `runtime`關鍵字。受管執行時間的命名慣例為 *<language-name><major-version>*。

目前，所有支援的 Java 執行時間都以 Amazon Corretto 為基礎。如需有效的 Java 執行期名稱和版本，請參閱 [Java 執行期版本資訊](service-source-code-java-releases.md)。

App Runner 會在每次部署或服務更新時，將服務的執行時間更新為最新版本。如果您的應用程式需要特定版本的受管執行時間，您可以使用 [App Runner 組態檔案中](config-file.md)的 `runtime-version`關鍵字來指定它。您可以鎖定任何層級的版本，包括主要或次要版本。App Runner 只會對服務的執行時間進行較低層級的更新。

Amazon Corretto 執行時間的版本語法：


| **執行時間** | **語法** | **範例** | 
| --- | --- | --- | 
|  corretto11  |  `11.0[.openjdk-update[.openjdk-build[.corretto-specific-revision]]]`  |  `11.0.13.08.1`  | 
|  corretto8  |  `8[.openjdk-update[.openjdk-build[.corretto-specific-revision]]]`  |  `8.312.07.1`  | 

下列範例示範版本鎖定：
+ `11.0.13` – 鎖定 Open JDK 更新版本。App Runner 只會更新 Open JDK 和 Amazon Corretto 低階組建。
+ `11.0.13.08.1` – 鎖定至特定版本。App Runner 不會更新您的執行時間版本。

**Topics**
+ [Java 執行期組態](#service-source-code-java.config)
+ [Java 執行時間範例](#service-source-code-java.examples)
+ [Java 執行期版本資訊](service-source-code-java-releases.md)

## Java 執行期組態
<a name="service-source-code-java.config"></a>

當您選擇受管執行時間時，您也必須至少設定建置和執行命令。您可以在[建立](manage-create.md)或[更新](manage-configure.md) App Runner 服務時設定它們。您可以使用下列其中一種方法執行此操作：
+ **使用 App Runner 主控台** – 在建立程序或組態索引標籤**的設定建置**區段中指定命令。
+ **使用 App Runner API** – 呼叫 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) 或 [UpdateService](https://docs.aws.amazon.com/apprunner/latest/api/API_UpdateService.html) API 操作。使用 [CodeConfigurationValues](https://docs.aws.amazon.com/apprunner/latest/api/API_CodeConfigurationValues.html) 資料類型的 `BuildCommand`和 `StartCommand`成員指定命令。
+ **使用[組態檔案](config-file.md)** – 在最多三個建置階段指定一或多個建置命令，以及用於啟動應用程式的單一執行命令。還有其他選用的組態設定。

提供組態檔案是選用的。當您使用主控台或 API 建立 App Runner 服務時，您可以指定 App Runner 在建立時直接從組態檔案取得您的組態設定。

## Java 執行時間範例
<a name="service-source-code-java.examples"></a>

下列範例顯示用於建置和執行 Java 服務的 App Runner 組態檔案。最後一個範例是完整 Java 應用程式的原始碼，您可以部署到 Corretto 11 執行時間服務。

**注意**  
這些範例中使用的執行時間版本為 *11.0.13.08.1*。您可以將其取代為您想要使用的版本。如需最新支援的 Java 執行期版本，請參閱 [Java 執行期版本資訊](service-source-code-java-releases.md)。

### 最小 Corretto 11 組態檔案
<a name="service-source-code-java.examples.minimal"></a>

此範例顯示您可以搭配 Corretto 11 受管執行時間使用的最小組態檔案。如需 App Runner 使用最少組態檔案所做的假設，請參閱 。

**Example apprunner.yaml**  

```
version: 1.0
runtime: corretto11
build:
  commands:    
    build:
      - mvn clean package
run:                              
  command: java -Xms256m -jar target/MyApp-1.0-SNAPSHOT.jar .
```

### 擴充 Corretto 11 組態檔案
<a name="service-source-code-java.examples.extended"></a>

此範例示範如何使用所有組態金鑰搭配 Corretto 11 受管執行時間。

**注意**  
這些範例中使用的執行時間版本為 *11.0.13.08.1*。您可以將其取代為您想要使用的版本。如需最新支援的 Java 執行期版本，請參閱 [Java 執行期版本資訊](service-source-code-java-releases.md)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: corretto11
build:
  commands:
    pre-build:
      - yum install some-package
      - scripts/prebuild.sh
    build:
      - mvn clean package
    post-build:
      - mvn clean test
  env:
    - name: M2
      value: "/usr/local/apache-maven/bin"
    - name: M2_HOME
      value: "/usr/local/apache-maven/bin"
run:
  runtime-version: 11.0.13.08.1
  command: java -Xms256m -jar target/MyApp-1.0-SNAPSHOT.jar .
  network:
    port: 8000
    env: APP_PORT
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
```

### 完成 Corretto 11 應用程式來源
<a name="service-source-code-java.examples.end2end"></a>

此範例顯示完整 Java 應用程式的原始程式碼，您可以部署到 Corretto 11 執行時間服務。

**Example src/main/java/com/HelloWorld/HelloWorld.java**  

```
package com.HelloWorld;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorld {

    @RequestMapping("/")
    public String index(){
        String s = "Hello World";
        return s;
    }
}
```

**Example src/main/java/com/HelloWorld/Main.java**  

```
package com.HelloWorld;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Main {

    public static void main(String[] args) {

        SpringApplication.run(Main.class, args);
    }
}
```

**Example apprunner.yaml**  

```
version: 1.0
runtime: corretto11
build:
  commands:    
    build:
      - mvn clean package
run:                              
  command: java -Xms256m -jar target/HelloWorldJavaApp-1.0-SNAPSHOT.jar .
  network:
    port: 8080
```

**Example pom.xml**  

```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.1.RELEASE</version>
    <relativePath/>
  </parent>
  <groupId>com.HelloWorld</groupId>
  <artifactId>HelloWorldJavaApp</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <java.version>11</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.junit.vintage</groupId>
          <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>11</release>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
```

# Java 執行期版本資訊
<a name="service-source-code-java-releases"></a>

本主題列出 App Runner 支援的 Java 執行時間版本的完整詳細資訊。


**支援的執行時間版本 — 原始 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-java-releases.html)

**注意**  
App Runner 為最近發佈的特定主要執行時間提供修訂後的建置程序。因此，您會在本文件的特定章節中看到*修訂後的 App Runner 組建*和*原始 App Runner 組建*的參考。如需詳細資訊，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail)。

# 使用 .NET 平台
<a name="service-source-code-net6"></a>

**重要**  
App Runner 將於 **2025 年 12 月 1 日結束對 .NET 6** 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

 AWS App Runner .NET 平台提供受管執行時間。每個執行時間都可讓您根據 .NET 版本使用 Web 應用程式輕鬆建置和執行容器。當您使用 .NET 執行期時，App Runner 會從受管 .NET 執行期映像開始。此映像以 [Amazon Linux Docker 映像](https://hub.docker.com/_/amazonlinux)為基礎，包含 .NET 版本的執行時間套件，以及一些工具和熱門相依性套件。App Runner 使用此受管執行期映像做為基礎映像，並新增您的應用程式程式碼來建置 Docker 映像。然後，它會部署此映像，以在容器中執行您的 Web 服務。

 當您使用 App Runner 主控台或 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) API 操作[建立服務時，](manage-create.md)您可以指定 App Runner 服務的執行時間。您也可以指定執行時間做為原始程式碼的一部分。在程式碼儲存庫中包含的 [App Runner 組態檔案中](config-file.md)使用 `runtime`關鍵字。受管執行時間的命名慣例為 *<language-name><major-version>*。

如需有效的 .NET 執行期名稱和版本，請參閱 [.NET 執行時間版本資訊](service-source-code-dotnet-releases.md)。

App Runner 會在每次部署或服務更新時，將服務的執行時間更新為最新版本。如果您的應用程式需要特定版本的受管執行時間，您可以使用 [App Runner 組態檔案中](config-file.md)的 `runtime-version`關鍵字來指定它。您可以鎖定任何層級的版本，包括主要或次要版本。App Runner 只會對服務的執行時間進行較低層級的更新。

.NET 執行時間的版本語法： `major[.minor[.patch]]`

例如：`6.0.9`

下列範例示範版本鎖定：
+ `6.0` – 鎖定主要和次要版本。App Runner 只會更新修補程式版本。
+ `6.0.9` – 鎖定至特定修補程式版本。App Runner 不會更新您的執行時間版本。

**Topics**
+ [.NET 執行時間組態](#service-source-code-net6.config)
+ [.NET 執行時間範例](#service-source-code-net6.examples)
+ [.NET 執行時間版本資訊](service-source-code-dotnet-releases.md)

## .NET 執行時間組態
<a name="service-source-code-net6.config"></a>

當您選擇受管執行時間時，您也必須至少設定建置和執行命令。您可以在[建立](manage-create.md)或[更新](manage-configure.md) App Runner 服務時設定它們。您可以使用下列其中一種方法執行此操作：
+ **使用 App Runner 主控台** – 在建立程序或組態索引標籤**的設定建置**區段中指定命令。
+ **使用 App Runner API** – 呼叫 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) 或 [UpdateService](https://docs.aws.amazon.com/apprunner/latest/api/API_UpdateService.html) API 操作。使用 [CodeConfigurationValues](https://docs.aws.amazon.com/apprunner/latest/api/API_CodeConfigurationValues.html) 資料類型的 `BuildCommand`和 `StartCommand`成員指定命令。
+ **使用[組態檔案](config-file.md)** – 在最多三個建置階段指定一或多個建置命令，以及用於啟動應用程式的單一執行命令。還有其他選用的組態設定。

提供組態檔案是選用的。當您使用主控台或 API 建立 App Runner 服務時，您可以指定 App Runner 在建立時直接從組態檔案取得您的組態設定。

## .NET 執行時間範例
<a name="service-source-code-net6.examples"></a>

下列範例顯示用於建置和執行 .NET 服務的 App Runner 組態檔案。最後一個範例是完整 .NET 應用程式的原始程式碼，您可以部署到 .NET 執行時間服務。

**注意**  
這些範例中使用的執行時間版本為 *6.0.9*。您可以將其取代為您想要使用的版本。如需最新支援的 .NET 執行時間版本，請參閱 [.NET 執行時間版本資訊](service-source-code-dotnet-releases.md)。

### 最小 .NET 組態檔案
<a name="service-source-code-net6.examples.minimal"></a>

此範例顯示您可以搭配 .NET 受管執行時間使用的最小組態檔案。如需 App Runner 使用最小組態檔案所做的假設，請參閱 [組態檔案範例](config-file-examples.md#config-file-examples.managed)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: dotnet6
build:
  commands:    
    build:
      - dotnet publish -c Release -o out
run:                              
  command: dotnet out/HelloWorldDotNetApp.dll
```

### 擴充的 .NET 組態檔案
<a name="service-source-code-net6.examples.extended"></a>

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

**注意**  
這些範例中使用的執行時間版本為 *6.0.9*。您可以將其取代為您想要使用的版本。如需最新支援的 .NET 執行時間版本，請參閱 [.NET 執行時間版本資訊](service-source-code-dotnet-releases.md)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: dotnet6
build:
  commands:
    pre-build:
      - scripts/prebuild.sh
    build:
      - dotnet publish -c Release -o out
    post-build:
      - scripts/postbuild.sh
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"    
run:
  runtime-version: 6.0.9
  command: dotnet out/HelloWorldDotNetApp.dll
  network:
    port: 5000
    env: APP_PORT
  env:
    - name: ASPNETCORE_URLS
      value: "http://*:5000"
```

### 完成 .NET 應用程式來源
<a name="service-source-code-net6.examples.end2end"></a>

此範例顯示您可以部署到 .NET 執行時間服務的完整 .NET 應用程式的原始碼。

**注意**  
 執行下列命令來建立簡單的 .NET 6 Web 應用程式： ` dotnet new web --name HelloWorldDotNetApp -f net6.0`
 將 `apprunner.yaml`新增至建立的 .NET 6 Web 應用程式。

**Example HelloWorldDotNetApp**  

```
version: 1.0
runtime: dotnet6
build:
  commands:
    build:
      - dotnet publish -c Release -o out
run:
  command: dotnet out/HelloWorldDotNetApp.dll
  network:
    port: 5000
    env: APP_PORT
  env:
    - name: ASPNETCORE_URLS
      value: "http://*:5000"
```

# .NET 執行時間版本資訊
<a name="service-source-code-dotnet-releases"></a>

**重要**  
App Runner 將於 **2025 年 12 月 1 日結束對 .NET 6** 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

本主題列出 App Runner 支援的 .NET 執行時間版本的完整詳細資訊。


**支援的執行時間版本 — 原始 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-dotnet-releases.html)

**注意**  
App Runner 為最近發佈的特定主要執行時間提供修訂後的建置程序。因此，您會在本文件的特定章節中看到已*修訂的 App Runner 組建*和*原始 App Runner 組建*的參考。如需詳細資訊，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail)。

# 使用 PHP 平台
<a name="service-source-code-php"></a>

**重要**  
App Runner 將於 2025 年 12 月 31 日結束對 **PHP 8**.1 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

 AWS App Runner PHP 平台提供受管執行時間。您可以使用每個執行時間，根據 PHP 版本使用 Web 應用程式建置和執行容器。當您使用 PHP 執行期時，App Runner 會從受管 PHP 執行期映像開始。此映像是以 [Amazon Linux Docker 映像](https://hub.docker.com/_/amazonlinux)為基礎，並包含 PHP 版本和一些工具的執行時間套件。App Runner 使用此受管執行期映像做為基礎映像，並新增您的應用程式程式碼來建置 Docker 映像。然後，它會部署此映像，以在容器中執行您的 Web 服務。

 當您使用 App Runner 主控台或 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) API 操作[建立服務時，](manage-create.md)您可以指定 App Runner 服務的執行時間。您也可以指定執行時間做為原始程式碼的一部分。在程式碼儲存庫中包含的 [App Runner 組態檔案中](config-file.md)使用 `runtime`關鍵字。受管執行時間的命名慣例為 *<language-name><major-version>*。

如需有效的 PHP 執行期名稱和版本，請參閱 [PHP 執行期版本資訊](service-source-code-php-releases.md)。

App Runner 會在每次部署或服務更新時，將服務的執行時間更新為最新版本。如果您的應用程式需要特定版本的受管執行時間，您可以使用 [App Runner 組態檔案中](config-file.md)的 `runtime-version`關鍵字來指定它。您可以鎖定任何層級的版本，包括主要或次要版本。App Runner 只會對服務的執行時間進行較低層級的更新。

PHP 執行時間的版本語法： `major[.minor[.patch]]`

例如：`8.1.10`

以下是版本鎖定的範例：
+ `8.1` – 鎖定主要和次要版本。App Runner 只會更新修補程式版本。
+ `8.1.10` – 鎖定至特定修補程式版本。App Runner 不會更新您的執行時間版本。

**重要**  
  如果您想要在預設儲存庫根[目錄以外的位置指定 App Runner](service-source-code.md#service-source-code.source-directory) 服務的程式碼儲存庫來源目錄，您的 PHP 受管執行時間版本必須是 PHP `8.1.22`或更新版本。之前的 PHP 執行時間版本`8.1.22`只能使用預設的根來源目錄。 

**Topics**
+ [PHP 執行期組態](#service-source-code-php.config)
+ [相容性](#service-source-code-php.compatibility)
+ [PHP 執行時間範例](#service-source-code-php.examples)
+ [PHP 執行期版本資訊](service-source-code-php-releases.md)

## PHP 執行期組態
<a name="service-source-code-php.config"></a>

當您選擇受管執行時間時，您也必須至少設定建置和執行命令。您可以在[建立](manage-create.md)或[更新](manage-configure.md) App Runner 服務時設定它們。您可以使用下列其中一種方法執行此操作：
+ **使用 App Runner 主控台** – 在建立程序或組態索引標籤的設定**建置**區段中指定命令。
+ **使用 App Runner API** – 呼叫 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) 或 [UpdateService](https://docs.aws.amazon.com/apprunner/latest/api/API_UpdateService.html) API 操作。使用 [CodeConfigurationValues](https://docs.aws.amazon.com/apprunner/latest/api/API_CodeConfigurationValues.html) 資料類型的 `BuildCommand`和 `StartCommand`成員指定命令。
+ **使用[組態檔案](config-file.md)** – 在最多三個建置階段指定一或多個建置命令，以及用於啟動應用程式的單一執行命令。還有其他選用的組態設定。

提供組態檔案是選用的。當您使用主控台或 API 建立 App Runner 服務時，您可以指定 App Runner 在建立時直接從組態檔案取得您的組態設定。

## 相容性
<a name="service-source-code-php.compatibility"></a>

您可以使用下列其中一個 Web 伺服器在 PHP 平台上執行 App Runner 服務：
+ Apache HTTP Server
+ NGINX

Apache HTTP Server 和 NGINX 與 PHP-FPM 相容。您可以使用下列*NGINX*其中一項啟動 *Apache HTTP Server*和 ：
+ [監督](http://supervisord.org/introduction.html#supervisor-components/) - 如需執行 的詳細資訊*supervisord*，請參閱[執行監督](http://supervisord.org/running.html#running-supervisord)。
+ 啟動指令碼 

如需如何使用 *Apache HTTP Server* 或 *NGINX* 透過 PHP 平台設定 App Runner 服務的範例，請參閱 [完成 PHP 應用程式來源](#service-source-code-php.examples.end2end)。

### 檔案結構
<a name="service-source-code-php.compatibility.file-structure"></a>

`index.php` 必須安裝在 Web 伺服器 `root`目錄下的 `public` 資料夾中。

**注意**  
建議您將 `startup.sh`或 `supervisord.conf` 檔案存放在 Web 伺服器的根目錄中。請確定`start`命令指向存放 `startup.sh`或 `supervisord.conf` 檔案的位置。

 如果您使用的是 ，以下是 檔案結構的範例*supervisord*。

```
/
├─ public/
│  ├─ index.php
├─ apprunner.yaml
├─ supervisord.conf
```

如果您使用的是*啟動指令碼*，下列是檔案結構的範例。

```
/
├─ public/
│  ├─ index.php
├─ apprunner.yaml
├─ startup.sh
```

我們建議您將這些檔案結構存放在為 App Runner 服務指定的程式碼儲存庫[來源目錄中](service-source-code.md#service-source-code.source-directory)。

```
/<sourceDirectory>/
├─ public/
│  ├─ index.php
├─ apprunner.yaml
├─ startup.sh
```

**重要**  
  如果您想要在預設儲存庫根[目錄以外的位置指定 App Runner](service-source-code.md#service-source-code.source-directory) 服務的程式碼儲存庫來源目錄，您的 PHP 受管執行時間版本必須是 PHP `8.1.22`或更新版本。之前的 PHP 執行時間版本`8.1.22`只能使用預設的根來源目錄。   
App Runner 會在每次部署或服務更新時，將服務的執行時間更新為最新版本。您的服務預設會使用最新的執行時間，除非您使用 [App Runner 組態檔案中](config-file.md)的 `runtime-version`關鍵字指定版本鎖定。

## PHP 執行時間範例
<a name="service-source-code-php.examples"></a>

以下是用於建置和執行 PHP 服務的 App Runner 組態檔案範例。

### 最小 PHP 組態檔案
<a name="service-source-code-php.examples.minimal"></a>

下列範例是您可以搭配 PHP 受管執行時間使用的最小組態檔案。如需最小組態檔案的詳細資訊，請參閱 [組態檔案範例](config-file-examples.md#config-file-examples.managed)。

**Example apprunner.yaml**  

```
version: 1.0 
runtime: php81
build:
  commands:
    build:
      - echo example build command for PHP
run:
  command: ./startup.sh
```

### 擴充 PHP 組態檔案
<a name="service-source-code-php.examples.extended"></a>

下列範例使用具有 PHP 受管執行時間的所有組態金鑰。

**注意**  
這些範例中使用的執行時間版本為 *8.1.10*。您可以將其取代為您想要使用的版本。如需最新支援的 PHP 執行期版本，請參閱 [PHP 執行期版本資訊](service-source-code-php-releases.md)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: php81
build:
  commands:
     pre-build:
      - scripts/prebuild.sh
    build:
      - echo example build command for PHP
    post-build:
      - scripts/postbuild.sh
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
run:
  runtime-version: 8.1.10
  command: ./startup.sh
  network:
    port: 5000
    env: APP_PORT
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
```

### 完成 PHP 應用程式來源
<a name="service-source-code-php.examples.end2end"></a>

下列範例是 PHP 應用程式原始碼，您可以使用 *Apache HTTP Server*或 來部署至 PHP 執行時間服務*NGINX*。這些範例假設您使用預設檔案結構。

#### Apache HTTP Server 使用 搭配 執行 PHP 平台 supervisord
<a name="service-source-code-php.examples.end2end.appache-supervisord"></a>

**Example 檔案結構**  
+ `supervisord.conf` 檔案可以存放在儲存庫中的任何位置。請確定`start`命令指向`supervisord.conf`檔案的存放位置。
+ `index.php` 必須安裝在 `root`目錄下的 `public` 資料夾中。

```
/
├─ public/
│  ├─ index.php
├─ apprunner.yaml
├─ supervisord.conf
```

**Example supervisord.conf**  

```
[supervisord]
nodaemon=true

[program:httpd]
command=httpd -DFOREGROUND
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:php-fpm]
command=php-fpm -F
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
```

**Example apprunner.yaml**  

```
version: 1.0
runtime: php81
build:
  commands:
    build:
      - PYTHON=python2 amazon-linux-extras install epel
      - yum -y install supervisor
run:
  command: supervisord
  network:
    port: 8080
    env: APP_PORT
```

**Example index.php**  

```
<html>
<head> <title>First PHP App</title> </head>
<body>
<?php
    print("Hello World!");
    print("<br>");
?>
</body>
</html>
```

#### Apache HTTP Server 使用 搭配 執行 PHP 平台 startup script
<a name="service-source-code-php.examples.end2end.appache-startupscript"></a>

**Example 檔案結構**  
+ `startup.sh` 檔案可以存放在儲存庫的任何位置。請確定`start`命令指向`startup.sh`檔案的存放位置。
+ `index.php` 必須安裝在 `root`目錄下的 `public` 資料夾中。

```
/
├─ public/
│  ├─ index.php
├─ apprunner.yaml
├─ startup.sh
```

**Example startup.sh**  

```
#!/bin/bash

set -o monitor

trap exit SIGCHLD

# Start apache
httpd -DFOREGROUND &

# Start php-fpm
php-fpm -F &

wait
```

**注意**  
請務必先將`startup.sh`檔案儲存為可執行檔，再將其遞交至 Git 儲存庫。使用 `chmod +x startup.sh` 設定 `startup.sh` 檔案的執行許可。
如果您未將`startup.sh`檔案儲存為可執行檔，請在您的`apprunner.yaml`檔案中輸入 `chmod +x startup.sh`作為`build`命令。

**Example apprunner.yaml**  

```
version: 1.0
runtime: php81
build:
  commands:
    build:
      - echo example build command for PHP
run:
  command: ./startup.sh
  network:
    port: 8080
    env: APP_PORT
```

**Example index.php**  

```
<html>
<head> <title>First PHP App</title> </head>
<body>
<?php
    print("Hello World!");
    print("<br>");
?>
</body>
</html>
```

#### NGINX 使用 搭配 執行 PHP 平台 supervisord
<a name="service-source-code-php.examples.end2end.nginx-supervisord"></a>

**Example 檔案結構**  
+ `supervisord.conf` 檔案可以存放在儲存庫中的任何位置。請確定`start`命令指向`supervisord.conf`檔案的存放位置。
+ `index.php` 必須安裝在 `root`目錄下的 `public` 資料夾中。

```
/
├─ public/
│  ├─ index.php
├─ apprunner.yaml
├─ supervisord.conf
```

**Example supervisord.conf**  

```
[supervisord]
nodaemon=true

[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:php-fpm]
command=php-fpm -F
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
```

**Example apprunner.yaml**  

```
version: 1.0
runtime: php81
build:
  commands:
    build:
      - PYTHON=python2 amazon-linux-extras install epel
      - yum -y install supervisor
run:
  command: supervisord
  network:
    port: 8080
    env: APP_PORT
```

**Example index.php**  

```
<html>
<head> <title>First PHP App</title> </head>
<body>
<?php
    print("Hello World!");
    print("<br>");
?>
</body>
</html>
```

#### NGINX 使用 搭配 執行 PHP 平台 startup script
<a name="service-source-code-php.examples.end2end.nginx-startupscript"></a>

**Example 檔案結構**  
+ `startup.sh` 檔案可以存放在儲存庫的任何位置。請確定`start`命令指向`startup.sh`檔案的存放位置。
+ `index.php` 必須安裝在 `root`目錄下的 `public` 資料夾中。

```
/
├─ public/
│  ├─ index.php
├─ apprunner.yaml
├─ startup.sh
```

**Example startup.sh**  

```
#!/bin/bash

set -o monitor

trap exit SIGCHLD

# Start nginx 
nginx -g 'daemon off;' &

# Start php-fpm
php-fpm -F &

wait
```

**注意**  
請務必先將`startup.sh`檔案儲存為可執行檔，再將其遞交至 Git 儲存庫。使用 `chmod +x startup.sh` 設定 `startup.sh` 檔案的執行許可。
如果您未將`startup.sh`檔案儲存為可執行檔，請在您的`apprunner.yaml`檔案中輸入 `chmod +x startup.sh`作為`build`命令。

**Example apprunner.yaml**  

```
version: 1.0
runtime: php81
build:
  commands:
    build:
      - echo example build command for PHP
run:
  command: ./startup.sh
  network:
    port: 8080
    env: APP_PORT
```

**Example index.php**  

```
<html>
<head> <title>First PHP App</title> </head>
<body>
<?php
    print("Hello World!");
    print("<br>");
?>
</body>
</html>
```

# PHP 執行期版本資訊
<a name="service-source-code-php-releases"></a>

**重要**  
App Runner 將於 2025 年 12 月 31 日終止對 **PHP 8**.1 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

本主題列出 App Runner 支援的 PHP 執行時間版本的完整詳細資訊。


**支援的執行時間版本 — 原始 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-php-releases.html)

**注意**  
App Runner 為最近發佈的特定主要執行時間提供修訂後的建置程序。因此，您會在本文件的特定章節中看到已*修訂的 App Runner 組建*和*原始 App Runner 組建*的參考。如需詳細資訊，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail)。

# 使用 Ruby 平台
<a name="service-source-code-ruby"></a>

**重要**  
App Runner 將於 2025 年 12 月 1 日結束對 **Ruby 3**.1 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

 AWS App Runner Ruby 平台提供受管執行期。每個執行時間都可讓您根據 Ruby 版本使用 Web 應用程式輕鬆建置和執行容器。當您使用 Ruby 執行期時，App Runner 會從受管 Ruby 執行期映像開始。此映像以 [Amazon Linux Docker 映像](https://hub.docker.com/_/amazonlinux)為基礎，並包含 Ruby 版本的執行時間套件和一些工具。App Runner 使用此受管執行期映像做為基礎映像，並新增您的應用程式程式碼來建置 Docker 映像。然後，它會部署此映像，以在容器中執行您的 Web 服務。

 當您使用 App Runner 主控台或 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) API 操作[建立服務時，](manage-create.md)您可以指定 App Runner 服務的執行時間。您也可以指定執行時間做為原始程式碼的一部分。在程式碼儲存庫中包含的 [App Runner 組態檔案中](config-file.md)使用 `runtime`關鍵字。受管執行時間的命名慣例為 *<language-name><major-version>*。

如需有效的 Ruby 執行時間名稱和版本，請參閱 [Ruby 執行時間版本資訊](service-source-code-ruby-releases.md)。

App Runner 會在每次部署或服務更新時，將服務的執行時間更新為最新版本。如果您的應用程式需要特定版本的受管執行時間，您可以使用 [App Runner 組態檔案中](config-file.md)的 `runtime-version`關鍵字來指定它。您可以鎖定任何層級的版本，包括主要或次要版本。App Runner 只會對服務的執行時間進行較低層級的更新。

Ruby 執行時間的版本語法： `major[.minor[.patch]]`

例如：`3.1.2`

下列範例示範版本鎖定：
+ `3.1` – 鎖定主要和次要版本。App Runner 只會更新修補程式版本。
+ `3.1.2` – 鎖定至特定修補程式版本。App Runner 不會更新您的執行時間版本。

**Topics**
+ [Ruby 執行時間組態](#service-source-code-ruby.config)
+ [Ruby 執行時間範例](#service-source-code-ruby.examples)
+ [Ruby 執行時間版本資訊](service-source-code-ruby-releases.md)

## Ruby 執行時間組態
<a name="service-source-code-ruby.config"></a>

當您選擇受管執行時間時，您也必須至少設定建置和執行命令。您可以在[建立](manage-create.md)或[更新](manage-configure.md) App Runner 服務時設定它們。您可以使用下列其中一種方法執行此操作：
+ **使用 App Runner 主控台** – 在建立程序或組態索引標籤的設定**建置**區段中指定命令。
+ **使用 App Runner API** – 呼叫 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) 或 [UpdateService](https://docs.aws.amazon.com/apprunner/latest/api/API_UpdateService.html) API 操作。使用 [CodeConfigurationValues](https://docs.aws.amazon.com/apprunner/latest/api/API_CodeConfigurationValues.html) 資料類型的 `BuildCommand`和 `StartCommand`成員指定命令。
+ **使用[組態檔案](config-file.md)** – 在最多三個建置階段指定一或多個建置命令，以及用於啟動應用程式的單一執行命令。還有其他選用的組態設定。

提供組態檔案是選用的。當您使用主控台或 API 建立 App Runner 服務時，您可以指定 App Runner 在建立時直接從組態檔案取得您的組態設定。

## Ruby 執行時間範例
<a name="service-source-code-ruby.examples"></a>

下列範例顯示用於建置和執行 Ruby 服務的 App Runner 組態檔案。

### 最小 Ruby 組態檔案
<a name="service-source-code-ruby.examples.minimal"></a>

此範例顯示您可以搭配 Ruby 受管執行時間使用的最小組態檔案。如需 App Runner 使用最小組態檔案所做的假設，請參閱 [組態檔案範例](config-file-examples.md#config-file-examples.managed)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: ruby31
build:
  commands:
    build:
      - bundle install
run:
  command: bundle exec rackup --host 0.0.0.0 -p 8080
```

### 擴充 Ruby 組態檔案
<a name="service-source-code-ruby.examples.extended"></a>

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

**注意**  
這些範例中使用的執行時間版本是 *3.1.2。*您可以將其取代為您想要使用的版本。如需最新支援的 Ruby 執行時間版本，請參閱 [Ruby 執行時間版本資訊](service-source-code-ruby-releases.md)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: ruby31
build:
  commands:
     pre-build:
      - scripts/prebuild.sh
    build:
      - bundle install
    post-build:
      - scripts/postbuild.sh
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
run:
  runtime-version: 3.1.2
  command: bundle exec rackup --host 0.0.0.0 -p 4567
  network:
    port: 4567
    env: APP_PORT
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
```

### 完整的 Ruby 應用程式來源
<a name="service-source-code-ruby.examples.end2end"></a>

這些範例顯示完整 Ruby 應用程式的原始程式碼，您可以部署到 Ruby 執行時間服務。

**Example server.rb**  

```
# server.rb
require 'sinatra'

get '/' do    
  'Hello World!'
end
```

**Example config.ru**  

```
# config.ru

require './server'

run Sinatra::Application
```

**Example Gemfile**  

```
# Gemfile
source 'https://rubygems.org (https://rubygems.org/)'

gem 'sinatra'
gem 'puma'
```

**Example apprunner.yaml**  

```
version: 1.0
runtime: ruby31
build:
  commands:
    build:
      - bundle install
run:
  command: bundle exec rackup --host 0.0.0.0 -p 4567
  network:
    port: 4567
    env: APP_PORT
```

# Ruby 執行時間版本資訊
<a name="service-source-code-ruby-releases"></a>

**重要**  
App Runner 將於 2025 年 12 月 1 日結束對 **Ruby 3**.1 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

本主題列出 App Runner 支援的 Ruby 執行時間版本的完整詳細資訊。


**支援的執行時間版本 — 原始 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-ruby-releases.html)

**注意**  
App Runner 為最近發佈的特定主要執行時間提供修訂後的建置程序。因此，您會在本文件的特定章節中看到已*修訂的 App Runner 組建*和*原始 App Runner 組建*的參考。如需詳細資訊，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail)。

# 使用 Go 平台
<a name="service-source-code-go1"></a>

**重要**  
App Runner 將於 2025 年 12 月 1 日結束對 **Go 1.18** 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

 AWS App Runner Go 平台提供受管執行時間。每個執行時間都可讓您根據 Go 版本使用 Web 應用程式輕鬆建置和執行容器。當您使用 Go 執行時間時，App Runner 會從受管 Go 執行時間映像開始。此映像以 [Amazon Linux Docker 映像](https://hub.docker.com/_/amazonlinux)為基礎，並包含 Go 版本和一些工具的執行時間套件。App Runner 使用此受管執行期映像做為基礎映像，並新增您的應用程式程式碼來建置 Docker 映像。然後，它會部署此映像，以在容器中執行您的 Web 服務。

 當您使用 App Runner 主控台或 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) API 操作[建立服務時，](manage-create.md)您可以指定 App Runner 服務的執行時間。您也可以指定執行時間做為原始程式碼的一部分。在程式碼儲存庫中包含的 [App Runner 組態檔案中](config-file.md)使用 `runtime`關鍵字。受管執行時間的命名慣例為 *<language-name><major-version>*。

如需有效的 Go 執行時間名稱和版本，請參閱 [Go 執行時間版本資訊](service-source-code-go-releases.md)。

App Runner 會在每次部署或服務更新時，將服務的執行時間更新為最新版本。如果您的應用程式需要特定版本的受管執行時間，您可以使用 [App Runner 組態檔案中](config-file.md)的 `runtime-version`關鍵字來指定它。您可以鎖定任何層級的版本，包括主要或次要版本。App Runner 只會對服務的執行時間進行較低層級的更新。

Go 執行時間的版本語法： `major[.minor[.patch]]`

例如：`1.18.7`

下列範例示範版本鎖定：
+ `1.18` – 鎖定主要和次要版本。App Runner 只會更新修補程式版本。
+ `1.18.7` – 鎖定至特定修補程式版本。App Runner 不會更新您的執行時間版本。

**Topics**
+ [Go 執行時間組態](#service-source-code-go1.config)
+ [Go 執行時間範例](#service-source-code-go1.examples)
+ [Go 執行時間版本資訊](service-source-code-go-releases.md)

## Go 執行時間組態
<a name="service-source-code-go1.config"></a>

當您選擇受管執行時間時，您也必須至少設定建置和執行命令。您可以在[建立](manage-create.md)或[更新](manage-configure.md) App Runner 服務時設定它們。您可以使用下列其中一種方法執行此操作：
+ **使用 App Runner 主控台** – 在建立程序或組態索引標籤**的設定建置**區段中指定命令。
+ **使用 App Runner API** – 呼叫 [CreateService](https://docs.aws.amazon.com/apprunner/latest/api/API_CreateService.html) 或 [UpdateService](https://docs.aws.amazon.com/apprunner/latest/api/API_UpdateService.html) API 操作。使用 [CodeConfigurationValues](https://docs.aws.amazon.com/apprunner/latest/api/API_CodeConfigurationValues.html) 資料類型的 `BuildCommand`和 `StartCommand`成員指定命令。
+ **使用[組態檔案](config-file.md)** – 在最多三個建置階段指定一或多個建置命令，以及用於啟動應用程式的單一執行命令。還有其他選用的組態設定。

提供組態檔案是選用的。當您使用主控台或 API 建立 App Runner 服務時，您可以指定 App Runner 在建立時直接從組態檔案取得您的組態設定。

## Go 執行時間範例
<a name="service-source-code-go1.examples"></a>

下列範例顯示用於建置和執行 Go 服務的 App Runner 組態檔案。

### Minimal Go 組態檔案
<a name="service-source-code-go1.examples.minimal"></a>

此範例顯示您可以搭配 Go 受管執行時間使用的最小組態檔案。如需 App Runner 使用最小組態檔案所做的假設，請參閱 [組態檔案範例](config-file-examples.md#config-file-examples.managed)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: go1
build:
  commands:
    build:
      - go build main.go
run:
  command: ./main
```

### Extended Go 組態檔案
<a name="service-source-code-go1.examples.extended"></a>

此範例顯示使用 Go 受管執行時間的所有組態金鑰。

**注意**  
這些範例中使用的執行時間版本為 *1.18.7。*您可以將其取代為您想要使用的版本。如需最新支援的 Go 執行時間版本，請參閱 [Go 執行時間版本資訊](service-source-code-go-releases.md)。

**Example apprunner.yaml**  

```
version: 1.0
runtime: go1
build:
  commands:
     pre-build:
      - scripts/prebuild.sh
    build:
      - go build main.go
    post-build:
      - scripts/postbuild.sh
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
run:
  runtime-version: 1.18.7
  command: ./main
  network:
    port: 3000
    env: APP_PORT
  env:
    - name: MY_VAR_EXAMPLE
      value: "example"
```

### 完成 Go 應用程式來源
<a name="service-source-code-go1.examples.end2end"></a>

這些範例顯示您可以部署到 Go 執行時間服務的完整 Go 應用程式的原始碼。

**Example main.go**  

```
package main
import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "<h1>Welcome to App Runner</h1>")
    })
    fmt.Println("Starting the server on :3000...")
    http.ListenAndServe(":3000", nil)
}
```

**Example apprunner.yaml**  

```
version: 1.0
runtime: go1
build:
  commands:
    build:
      - go build main.go
run:
  command: ./main
  network:
    port: 3000
    env: APP_PORT
```

# Go 執行時間版本資訊
<a name="service-source-code-go-releases"></a>

**重要**  
App Runner 將於 2025 年 12 月 1 日結束對 **Go 1.18** 的支援。如需建議和詳細資訊，請參閱 [受管執行時間版本的終止支援](service-source-code.md#service-source-code.managed-platforms.eos)。

本主題列出 App Runner 支援的 Go 執行時間版本的完整詳細資訊。


**支援的執行時間版本 — 原始 App Runner 組建**  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/apprunner/latest/dg/service-source-code-go-releases.html)

**注意**  
App Runner 為最近發佈的特定主要執行時間提供修訂後的建置程序。因此，您會在本文件的特定章節中看到已*修訂的 App Runner 組建*和*原始 App Runner 組建*的參考。如需詳細資訊，請參閱 [受管執行期版本和 App Runner 組建](service-source-code.md#service-source-code.build-detail)。