

AWS App Runner は、2026 年 4 月 30 日以降、新規のお客様に公開されなくなります。App Runner を使用する場合は、その日付より前にサインアップします。既存のお客様は、通常どおりサービスを引き続き使用できます。詳細については、「[AWS App Runner  可用性の変更](https://docs.aws.amazon.com/apprunner/latest/dg/apprunner-availability-change.html)」を参照してください。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# 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)。

Python AWS App Runner プラットフォームはマネージドランタイムを提供します。各ランタイムにより、Python バージョンに基づいてウェブアプリケーションを使用してコンテナを簡単に構築および実行できます。Python ランタイムを使用すると、App Runner はマネージド Python ランタイムイメージから開始します。このイメージは [Amazon Linux Docker イメージ](https://hub.docker.com/_/amazonlinux)に基づいており、Python のバージョン用のランタイムパッケージと、いくつかのツールと一般的な依存関係パッケージが含まれています。App Runner はこのマネージドランタイムイメージをベースイメージとして使用し、アプリケーションコードを追加して Docker イメージを構築します。次に、このイメージをデプロイして、コンテナでウェブサービスを実行します。

 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>

マネージドランタイムを選択するときは、少なくとも コマンドを構築して実行することも設定する必要があります。App Runner サービス[を作成](manage-create.md)または[更新](manage-configure.md)するときに設定します。これは、次のいずれかの方法を使用して実行できます。
+ **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)の使用** – 最大 3 つのビルドフェーズで 1 つ以上のビルドコマンドと、アプリケーションを起動する 1 つの実行コマンドを指定します。追加のオプションの設定があります。

設定ファイルの提供はオプションです。コンソールまたは 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
  ```
+ 依存関係をインストールする`pip`には、 `pip3`の代わりに を使用します。
+ の代わりに `python3` インタープリタを使用します`python`。
+ `pip3` インストーラを`pre-run`コマンドとして実行します。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`。この例では、このバージョンの Python は改訂された App Runner ビルドを使用するため、 `pre-run`セクションが含まれています。

`pre-run` パラメータは、改訂された App Runner ビルドでのみサポートされます。アプリケーションが元の 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/ja_jp/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/ja_jp/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)」を参照してください。