

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

# AWS Transfer Family サーバーエンドポイントタイプを VPC\$1ENDPOINT から VPC に更新する
<a name="update-endpoint-type-vpc"></a>

 AWS マネジメントコンソール、 CloudFormation、または Transfer Family API を使用して、サーバーの を `EndpointType`から `VPC_ENDPOINT`に更新できます`VPC`。以下のセクションでは、これらの各メソッドを使用してサーバーエンドポイントタイプを更新するための詳細な手順と例について説明します。複数の AWS リージョンと複数の AWS アカウントにサーバーがある場合は、次のセクションで提供されているサンプルスクリプトを変更して使用して、更新する必要がある`VPC_ENDPOINT`タイプを使用してサーバーを識別できます。

**Topics**
+ [`VPC_ENDPOINT` エンドポイントタイプを使用したサーバーの識別](#id-servers)
+ [を使用したサーバーエンドポイントタイプの更新 AWS マネジメントコンソール](#update-endpoint-console)
+ [を使用したサーバーエンドポイントタイプの更新 CloudFormation](#update-endpoint-cloudformation)
+ [API を使用したサーバーの EndpointType の更新](#update-endpoint-cli)

## `VPC_ENDPOINT` エンドポイントタイプを使用したサーバーの識別
<a name="id-servers"></a>

 AWS マネジメントコンソールを使用することで、どのサーバーで `VPC_ENDPOINT` を使用しているかを特定できます。

**`VPC_ENDPOINT` エンドポイントタイプを使用するサーバーをコンソールで識別するには**

1. [https://console.aws.amazon.com/transfer/](https://console.aws.amazon.com/transfer/) で AWS Transfer Family コンソールを開きます。

1. ナビゲーションペインの [**Servers**] (サーバー) で、そのリージョンのアカウント内のサーバーの一覧を表示します。

1. [**Endpoint type**] (エンドポイントタイプ) を使用してサーバーのリストを並べ替えると、`VPC_ENDPOINT` を使用してすべてのサーバーを見ることができます。

**複数の AWS リージョンとアカウント`VPC_ENDPOINT`で を使用しているサーバーを特定するには**

複数の AWS リージョンと複数の AWS アカウントにサーバーがある場合は、次のスクリプト例を変更して、`VPC_ENDPOINT`エンドポイントタイプを使用してサーバーを識別できます。サンプルスクリプトは、Amazon EC2 [DescribeRegions](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeRegions.html) および Transfer Family [https://docs.aws.amazon.com/transfer/latest/APIReference/API_ListServers.html](https://docs.aws.amazon.com/transfer/latest/APIReference/API_ListServers.html) API オペレーションを使用します。多数の AWS アカウントがある場合、ID プロバイダーのセッションプロファイルを使用して認証すれば、読み取り専用監査アクセス権を持つ IAM ロールを使用してアカウントをループ処理できます。

1. 以下に単純な例を示します。

   ```
   import boto3
   
   profile = input("Enter the name of the AWS account you'll be working in: ")
   session = boto3.Session(profile_name=profile)
   
   ec2 = session.client("ec2")
   
   regions = ec2.describe_regions()
   
   for region in regions['Regions']:
       region_name = region['RegionName']
       if region_name=='ap-northeast-3': #https://github.com/boto/boto3/issues/1943
           continue
       transfer = session.client("transfer", region_name=region_name)
       servers = transfer.list_servers()
       for server in servers['Servers']:
          if server['EndpointType']=='VPC_ENDPOINT':
              print(server['ServerId'], region_name)
   ```

1. 更新するサーバーのリストができたら、以下のセクションで説明する方法のいずれかを使って、`EndpointType` を `VPC` に更新することができます。

## を使用したサーバーエンドポイントタイプの更新 AWS マネジメントコンソール
<a name="update-endpoint-console"></a>

1. [https://console.aws.amazon.com/transfer/](https://console.aws.amazon.com/transfer/) で AWS Transfer Family コンソールを開きます。

1. ナビゲーションペインで [**Servers**] (サーバー) を選択します。

1. エンドポイントタイプを変更したいサーバーのチェックボックスをオンにします。
**重要**  
エンドポイントを変更するには、その前にサーバーを停止する必要があります。

1. [**Actions**] (アクション) で [**Stop**] (停止) を選択します。

1. 表示される確認ダイアログボックスで [**Stop**] (停止) を選択して、サーバーを停止したいことを確認します。
**注記**  
次のステップに進む前に、サーバーの [**Status**] (ステータス) が [**Offline**] (オフライン) に変わるのを待ちますが、これには数分かかる場合があります。ステータスの変更を見るには、**[Servers]** (サーバー) ページで **[Refresh]** (更新) の選択が必要になる場合があります。

1. ステータスが「**オフライン**」に変わったら、サーバーを選択してサーバーの詳細ページを表示します。

1. 「**エンドポイントの詳細**」セクションで、「**編集**」を選択します。

1. [**Edit endpoint type**] (エンドポイントタイプ) で [**VPC hosted**] (VPC ホステッド) を選択します。

1. [**Save**] (保存) を選択します。

1. [**Actions**] (アクション) で [**Start**] (開始) を選択してサーバーのステータスが [**Online**] (オンライン) になるのを待ちますが、これには数分かかる場合があります。

## を使用したサーバーエンドポイントタイプの更新 CloudFormation
<a name="update-endpoint-cloudformation"></a>

このセクションでは、 CloudFormation を使用してサーバーの を `EndpointType`に更新する方法について説明します`VPC`。を使用してデプロイした Transfer Family サーバーの場合は、この手順を使用します CloudFormation。この例では、Transfer Family サーバーのデプロイに使用される元の CloudFormation テンプレートは次のとおりです。

```
AWS TemplateFormatVersion: '2010-09-09'
Description: 'Create AWS Transfer Server with VPC_ENDPOINT endpoint type'
Parameters:
  SecurityGroupId:
    Type: AWS::EC2::SecurityGroup::Id
  SubnetIds:
    Type: List<AWS::EC2::Subnet::Id>
  VpcId:
    Type: AWS::EC2::VPC::Id
Resources:
  TransferServer:
    Type: AWS::Transfer::Server
    Properties:
      Domain: S3
      EndpointDetails:
        VpcEndpointId: !Ref VPCEndpoint
      EndpointType: VPC_ENDPOINT
      IdentityProviderType: SERVICE_MANAGED
      Protocols:
        - SFTP
  VPCEndpoint:
    Type: AWS::EC2::VPCEndpoint
    Properties:
      ServiceName: com.amazonaws.us-east-1.transfer.server
      SecurityGroupIds:
        - !Ref SecurityGroupId
      SubnetIds:
        - !Select [0, !Ref SubnetIds]
        - !Select [1, !Ref SubnetIds]
        - !Select [2, !Ref SubnetIds]
      VpcEndpointType: Interface
      VpcId: !Ref VpcId
```

テンプレートは以下の変更によって更新されます。
+ `EndpointType` は `VPC` に変更されました。
+ `AWS::EC2::VPCEndpoint` リソースは削除されます。
+ `SecurityGroupId`、`SubnetIds`、および `VpcId` を `AWS::Transfer::Server` リソースの `EndpointDetails` セクションに移動しました。
+ `EndpointDetails` の `VpcEndpointId` プロパティは削除されました。

更新されたテンプレートは次のようになります。

```
AWS TemplateFormatVersion: '2010-09-09'
Description: 'Create AWS Transfer Server with VPC endpoint type'
Parameters:
  SecurityGroupId:
    Type: AWS::EC2::SecurityGroup::Id
  SubnetIds:
    Type: List<AWS::EC2::Subnet::Id>
  VpcId:
    Type: AWS::EC2::VPC::Id
Resources:
  TransferServer:
    Type: AWS::Transfer::Server
    Properties:
      Domain: S3
      EndpointDetails:
        SecurityGroupIds:
          - !Ref SecurityGroupId
        SubnetIds:
          - !Select [0, !Ref SubnetIds]
          - !Select [1, !Ref SubnetIds]
          - !Select [2, !Ref SubnetIds]
        VpcId: !Ref VpcId
      EndpointType: VPC
      IdentityProviderType: SERVICE_MANAGED
      Protocols:
        - SFTP
```

**を使用してデプロイされた Transfer Family サーバーのエンドポイントタイプを更新するには CloudFormation**

1. 次の手順に従って、更新したいサーバーを停止します。

   1. [https://console.aws.amazon.com/transfer/](https://console.aws.amazon.com/transfer/) で AWS Transfer Family コンソールを開きます。

   1. ナビゲーションペインで [**Servers**] (サーバー) を選択します。

   1. エンドポイントタイプを変更したいサーバーのチェックボックスをオンにします。
**重要**  
エンドポイントを変更するには、その前にサーバーを停止する必要があります。

   1. [**Actions**] (アクション) で [**Stop**] (停止) を選択します。

   1. 表示される確認ダイアログボックスで [**Stop**] (停止) を選択して、サーバーを停止したいことを確認します。
**注記**  
次のステップに進む前に、サーバーの [**Status**] (ステータス) が [**Offline**] (オフライン) に変わるのを待ちますが、これには数分かかる場合があります。ステータスの変更を見るには、**[Servers]** (サーバー) ページで **[Refresh]** (更新) の選択が必要になる場合があります。

1. CloudFormation スタックを更新する

   1. [https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/) で CloudFormation コンソールを開きます。

   1. Transfer Family サーバーの作成に使用するスタックを選択します。

   1. [**Update**] (更新) を選択します。

   1. [**Replace current template**] (現在のテンプレートを置換) を選択します。

   1. 新しいテンプレートをアップロードします。CloudFormation 変更セットは、テンプレートの変更を実装する前に、実行中のリソースに与える影響を理解するうえで役立ちます。この例では、Transfer サーバーリソースが変更され、vpcendPoint リソースが削除されます。VPC エンドポイントタイプサーバーはユーザーに代わって VPC エンドポイントを作成し、元の `VPCEndpoint` リソースを置き換えます。

      新しいテンプレートをアップロードすると、変更セットは以下のようになります。  
![\[現在の CloudFormation テンプレートを置き換えるための変更セットのプレビューページを表示します。\]](http://docs.aws.amazon.com/ja_jp/transfer/latest/userguide/images/vpc-endpoint-update-cfn.png)

   1. スタックを更新します。

1. スタックの更新が完了したら、Transfer Family 管理コンソール ([https://console.aws.amazon.com/transfer/](https://console.aws.amazon.com/transfer/)) に移動します。

1. サーバーを再起動します。更新したサーバーを選択し CloudFormation、**アクション**メニューから**開始**を選択します。

## API を使用したサーバーの EndpointType の更新
<a name="update-endpoint-cli"></a>

[describe-server](https://docs.aws.amazon.com/cli/latest/reference/transfer/update-server.html) AWS CLI コマンドまたは [UpdateServer](https://docs.aws.amazon.com/transfer/latest/APIReference/API_UpdateServer.html) API コマンドを使用できます。次のスクリプト例では、Transfer Family サーバーを停止し、EndpointType を更新し、VPC\$1ENDPOINT を削除し、サーバーを起動します。

```
import boto3
import time

profile = input("Enter the name of the AWS account you'll be working in: ")
region_name = input("Enter the AWS Region you're working in: ")
server_id = input("Enter the AWS Transfer Server Id: ")

session = boto3.Session(profile_name=profile)

ec2 = session.client("ec2", region_name=region_name)
transfer = session.client("transfer", region_name=region_name)

group_ids=[]

transfer_description = transfer.describe_server(ServerId=server_id)
if transfer_description['Server']['EndpointType']=='VPC_ENDPOINT':
    transfer_vpc_endpoint = transfer_description['Server']['EndpointDetails']['VpcEndpointId']
    transfer_vpc_endpoint_descriptions = ec2.describe_vpc_endpoints(VpcEndpointIds=[transfer_vpc_endpoint])
    for transfer_vpc_endpoint_description in transfer_vpc_endpoint_descriptions['VpcEndpoints']:
        subnet_ids=transfer_vpc_endpoint_description['SubnetIds']
        group_id_list=transfer_vpc_endpoint_description['Groups']
        vpc_id=transfer_vpc_endpoint_description['VpcId']
        for group_id in group_id_list:
             group_ids.append(group_id['GroupId'])
    if transfer_description['Server']['State']=='ONLINE':
        transfer_stop = transfer.stop_server(ServerId=server_id)
        print(transfer_stop)
        time.sleep(300) #safe
        transfer_update = transfer.update_server(ServerId=server_id,EndpointType='VPC',EndpointDetails={'SecurityGroupIds':group_ids,'SubnetIds':subnet_ids,'VpcId':vpc_id})
        print(transfer_update)
        time.sleep(10) 
        transfer_start = transfer.start_server(ServerId=server_id)
        print(transfer_start)
        delete_vpc_endpoint = ec2.delete_vpc_endpoints(VpcEndpointIds=[transfer_vpc_endpoint])
```