

# セキュリティポリシーを変更する方法
<a name="apigateway-security-policies-update"></a>

API のセキュリティポリシーを変更することができます。カスタムドメイン名を介して API にトラフィックを送信する場合、API とカスタムドメイン名が同じセキュリティポリシーを持つ必要はありません。そのカスタムドメイン名を呼び出すと、API Gateway は API のセキュリティポリシーを使用して TLS ハンドシェイクをネゴシエートします。ただし、一貫性を保つために、カスタムドメイン名と API に同じセキュリティポリシーを使用することをお勧めします。

セキュリティポリシーを変更すると、更新が完了するまでに約 15 分かかります。API の `apiStatus` をモニタリングできます。API が更新されると、`apiStatus` は `UPDATING` になり、完了すると `AVAILABLE` になります。API が更新されても、呼び出すことができます。

------
#### [ AWS マネジメントコンソール ]

**API のセキュリティポリシーを変更するには**

1. [https://console.aws.amazon.com/apigateway](https://console.aws.amazon.com/apigateway) で API Gateway コンソールにサインインします。

1. REST API を選択します。

1. **[API の設定]**、**[Edit]** の順に選択します。

1. **[セキュリティポリシー]** で、`SecurityPolicy_` で始まる新しいポリシーを選択します。

1. **[エンドポイントアクセスモード]** で、**[厳格]** を選択します。

1. **[Save changes]** (変更の保存) をクリックします。

   変更を有効にするには、API を再デプロイします。エンドポイントアクセスモードを [厳格] に変更したため、変更が完全に反映されるまでに約 15 分かかります。

------
#### [ AWS CLI ]

次の [update-rest-api](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-rest-api.html) コマンドは、API を更新して `SecurityPolicy_TLS13_1_3_2025_09` セキュリティポリシーを使用します。

```
aws apigateway update-rest-api \
    --rest-api-id abcd1234 \
    --patch-operations '[
        {
            "op": "replace",
            "path": "/securityPolicy",
            "value": "SecurityPolicy_TLS13_1_3_2025_09"
        }, 
        {
            "op": "replace",
            "path": "/endpointAccessMode",
            "value": "STRICT"
        }
    ]'
```

出力は次のようになります。

```
{
    "id": "abcd1234",
    "name": "MyAPI",
    "description": "My API with a new security policy",
    "createdDate": "2025-02-04T11:47:06-08:00",
    "apiKeySource": "HEADER",
    "endpointConfiguration": {
        "types": [
            "REGIONAL"
        ],
        "ipAddressType": "dualstack"
    },
    "tags": {},
    "disableExecuteApiEndpoint": false,
    "securityPolicy": "SecurityPolicy_TLS13_1_3_2025_09",
    "endpointAccessMode": "STRICT"
    "rootResourceId": "efg456"
}
```

次の [update-rest-api](https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-rest-api.html) コマンドは、拡張セキュリティポリシーを使用して `TLS_1_0` セキュリティポリシーを使用していた API を更新します。

```
aws apigateway update-rest-api \
    --rest-api-id abcd1234 \
    --patch-operations '[
        {
            "op": "replace",
            "path": "/securityPolicy",
            "value": "TLS_1_0"
        }, 
        {
            "op": "replace",
            "path": "/endpointAccessMode",
            "value": ""
        }
    ]'
```

出力は次のようになります。

```
{
    "id": "abcd1234",
    "name": "MyAPI",
    "description": "My API with a new security policy",
    "createdDate": "2025-02-04T11:47:06-08:00",
    "apiKeySource": "HEADER",
    "endpointConfiguration": {
        "types": [
            "REGIONAL"
        ],
        "ipAddressType": "dualstack"
    },
    "tags": {},
    "disableExecuteApiEndpoint": false,
    "securityPolicy": "TLS_1_0",
    "rootResourceId": "efg456"
}
```

------