将Amazon Transfer Family服务器端点类型从 VPC_ENDPOINT 更新为 VPC - Amazon Transfer Family
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

将Amazon Transfer Family服务器端点类型从 VPC_ENDPOINT 更新为 VPC

您可以使用Amazon Web Services Management Console、Amazon CloudFormation、或 Transfer Family API 将服务器EndpointTypeVPC_ENDPOINT更新为VPC。以下各部分提供了使用每种方法更新服务器端点类型的详细过程和示例。如果您在多个Amazon区域和多个Amazon账户中拥有服务器,则可以使用下一部分中提供的示例脚本进行修改,使用需要更新的VPC_ENDPOINT类型来识别服务器。

使用VPC_ENDPOINT端点类型识别服务器

您可以使用VPC_ENDPOINT来识别哪些服务器正在使用Amazon Web Services Management Console。

识别通过控制台使用VPC_ENDPOINT端点类型的服务器
  1. 打开Amazon Transfer Family控制台,网址为 https://console.aws.amazon.com/transfer/

  2. 在导航窗格中选择服务器,显示该区域中您账户中的服务器列表。

  3. 端点类型对服务器列表进行排序,以查看所有使用VPC_ENDPOINT的服务器。

识别跨多个VPC_ENDPOINT区域和账户使用Amazon的服务器

如果您在多个Amazon区域和多个Amazon帐户中拥有服务器,则可以使用以下示例脚本进行修改,以使用VPC_ENDPOINT端点类型标识服务器。该示例脚本使用 Amazon EC2 DescribeRegions和 Transfer Family ListServers API 调用来获取所有使用服务器的服务器 ID 和区域的列表VPC_ENDPOINT。如果您有许多Amazon账户,如果您使用身份提供商的会话配置文件进行身份验证,则可以使用具有只读审计员访问权限的 IAM 角色遍历您的账户。

  1. 以下是一个简单示例。

    import boto3 profile = input("Enter the name of the Amazon 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)
  2. 获得要更新的服务器列表后,您可以使用以下各部分中描述的方法之一将EndpointType更新为VPC

使用Amazon Web Services Management Console更新服务端点类型

  1. 打开Amazon Transfer Family控制台,网址为 https://console.aws.amazon.com/transfer/

  2. 在导航窗格中,选择 Servers (服务器)

  3. 选中要更改其端点类型的服务器的复选框。

    重要

    您必须先停止服务器,然后才能更改其终端节点。

  4. 对于操作,请选择停止

  5. 在出现的确认对话框中,通过选择停止来确认您要停止服务器。

    注意

    在继续下一步之前,请等待服务器的状态变为离线;这可能需要几分钟。您可能必须在服务器页面上选择刷新才能查看状态更改。

  6. 状态更改为离线后,选择服务器以显示服务器详细信息页面。

  7. 端点详细信息部分中,选择编辑

  8. 端点类型选择 VPC 托管

  9. 选择保存

  10. 操作中,选择启动,然后等待服务器状态更改为在线;这可能需要几分钟。

使用Amazon CloudFormation更新服务器端点类型

本部分介绍如何使用Amazon CloudFormation将服务器EndpointType更新为VPC。对于已使用Amazon CloudFormation部署的 Transfer Family 服务器,请使用以下步骤。在此示例中,用于部署 Transfer Family 服务器的原始Amazon CloudFormation模板如下所示:

AmazonTemplateFormatVersion: '2010-09-09' Description: 'Create Amazon Transfer Server with VPC_ENDPOINT endpoint type' Parameters: SecurityGroupId: Type: Amazon::EC2::SecurityGroup::Id SubnetIds: Type: List<Amazon::EC2::Subnet::Id> VpcId: Type: Amazon::EC2::VPC::Id Resources: TransferServer: Type: Amazon::Transfer::Server Properties: Domain: S3 EndpointDetails: VpcEndpointId: !Ref VPCEndpoint EndpointType: VPC_ENDPOINT IdentityProviderType: SERVICE_MANAGED Protocols: - SFTP VPCEndpoint: Type: Amazon::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资源已删除。

  • SecurityGroupIdSubnetIds、和VpcId已移至EndpointDetails资源AWS::Transfer::Server部分,

  • VpcEndpointIdEndpointDetails属性已删除。

更新后的模板如下所示:

AmazonTemplateFormatVersion: '2010-09-09' Description: 'Create Amazon Transfer Server with VPC endpoint type' Parameters: SecurityGroupId: Type: Amazon::EC2::SecurityGroup::Id SubnetIds: Type: List<Amazon::EC2::Subnet::Id> VpcId: Type: Amazon::EC2::VPC::Id Resources: TransferServer: Type: Amazon::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
Amazon CloudFormation要更新使用部署的 Transfer Family 服务器的端点类型
  1. 使用以下步骤停止要更新的服务器。

    1. 打开Amazon Transfer Family控制台,网址为 https://console.aws.amazon.com/transfer/

    2. 在导航窗格中,选择 Servers (服务器)

    3. 选中要更改其端点类型的服务器的复选框。

      重要

      您必须先停止服务器,然后才能更改其终端节点。

    4. 对于操作,请选择停止

    5. 在出现的确认对话框中,通过选择停止来确认您要停止服务器。

      注意

      在继续下一步之前,请等待服务器的状态变为离线;这可能需要几分钟。您可能必须在服务器页面上选择刷新才能查看状态更改。

  2. 更新堆 CloudFormation 栈

    1. 打开 Amazon CloudFormation 控制台,地址:https://console.aws.amazon.com/cloudformation

    2. 选择用于创建 Transfer Family 服务器的堆栈。

    3. 选择更新

    4. 选择替换当前模板

    5. 上传新模板。 CloudFormation 更改集可帮助您在实施模板更改之前了解模板更改将如何影响正在运行的资源。在此示例中,将修改 Transfer 服务器资源,并删除 VPCEndpoint 资源。VPC 端点类型服务器代表您创建 VPC 端点,替换原始VPCEndpoint资源。

      上传新模板后,更改集将与以下所示类似:

    6. 更新堆栈。

  3. 堆栈更新完成后,导航至 Transfer Family 管理控制台 https://console.aws.amazon.com/transfer/

  4. 重新启动服务器。选择在Amazon CloudFormation中更新的服务器,然后从操作菜单中选择启动

EndpointType 使用 API 更新服务器

您可以使用 describe-server Amazon CLI命令或 UpdateServerAPI 命令。以下示例脚本停止 Transfer Family 服务器、更新 EndpointType、移除 VPC_ENDPOINT 并启动服务器。

import boto3 import time profile = input("Enter the name of the Amazon account you'll be working in: ") region_name = input("Enter the Amazon Region you're working in: ") server_id = input("Enter the Amazon 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])