本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
將 AWS Transfer Family 伺服器端點類型從 VPC_ENDPOINT 更新為 VPC
您可以使用 AWS Management Console AWS CloudFormation或 Transfer Family API,將伺服器的 EndpointType 從 更新VPC_ENDPOINT為 VPC。下列各節提供使用每種方法來更新伺服器端點類型的詳細程序和範例。如果您在多個 AWS 區域和多個帳戶中有伺服器 AWS ,您可以使用下一節提供的範例指令碼進行修改,以使用您需要更新的VPC_ENDPOINT類型來識別伺服器。
主題
使用VPC_ENDPOINT端點類型識別伺服器
您可以使用 來識別哪些伺服器正在使用 VPC_ENDPOINT AWS Management Console。
使用主控台使用VPC_ENDPOINT端點類型識別伺服器
-
在 https://https://console.aws.amazon.com/transfer/
開啟 AWS Transfer Family 主控台。 -
在導覽窗格中選擇伺服器,以顯示您帳戶中該區域的伺服器清單。
-
依端點類型排序伺服器清單,以查看使用 的所有伺服器
VPC_ENDPOINT。
VPC_ENDPOINT 跨多個 AWS 區域和帳戶使用 識別伺服器
如果您在多個 AWS 區域和多個帳戶中有伺服器 AWS ,您可以使用下列範例指令碼進行修改,以使用VPC_ENDPOINT端點類型識別伺服器。範例指令碼使用 Amazon EC2 DescribeRegions 和 Transfer Family ListServers API 操作。如果您有多個 AWS 帳戶,如果您使用工作階段設定檔向身分提供者進行身分驗證,則可以使用具有唯讀稽核程式存取權的 IAM 角色來循環通過您的帳戶。
-
以下是簡單的範例。
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) -
取得要更新的伺服器清單後,您可以使用下列各節所述的其中一種方法,將 更新
EndpointType為VPC。
使用 更新伺服器端點類型 AWS Management Console
-
在 https://https://console.aws.amazon.com/transfer/
開啟 AWS Transfer Family 主控台。 -
在導覽窗格中,選擇 Servers (伺服器)。
-
選取您要變更端點類型的伺服器的核取方塊。
重要
您必須先停止伺服器,才能變更其端點。
-
針對 Actions (動作),選擇 Stop (停止)。
-
在出現的確認對話方塊中,選擇停止以確認您想要停止伺服器。
注意
在繼續下一個步驟之前,請等待伺服器狀態變更為離線;這可能需要幾分鐘的時間。您可能必須在伺服器頁面上選擇重新整理,以查看狀態變更。
-
狀態變更為離線後,選擇要顯示伺服器詳細資訊頁面的伺服器。
-
在端點詳細資訊區段中,選擇編輯。
-
選擇端點類型的託管 VPC。
-
選擇儲存
-
對於動作,選擇開始並等待伺服器狀態變更為線上;這可能需要幾分鐘的時間。
使用 更新伺服器端點類型 AWS CloudFormation
本節說明如何使用 AWS CloudFormation 將伺服器的 更新EndpointType為 VPC。針對您已部署使用的 Transfer Family 伺服器,請使用此程序 AWS CloudFormation。在此範例中,用於部署 Transfer Family 伺服器的原始 AWS 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區段, -
的
VpcEndpointId屬性EndpointDetails已移除。
更新的範本如下所示:
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 伺服器的端點類型 AWS CloudFormation
-
使用下列步驟停止您要更新的伺服器。
-
在 https://https://console.aws.amazon.com/transfer/
開啟 AWS Transfer Family 主控台。 -
在導覽窗格中,選擇 Servers (伺服器)。
-
選取您要變更端點類型的伺服器的核取方塊。
重要
您必須先停止伺服器,才能變更其端點。
-
針對 Actions (動作),選擇 Stop (停止)。
-
在出現的確認對話方塊中,選擇停止以確認您想要停止伺服器。
注意
在繼續下一個步驟之前,請等待伺服器狀態變更為離線;這可能需要幾分鐘的時間。您可能必須在伺服器頁面上選擇重新整理,以查看狀態變更。
-
-
更新 CloudFormation 堆疊
在 https://https://console.aws.amazon.com/cloudformation
開啟 AWS CloudFormation 主控台。 -
選擇用來建立 Transfer Family 伺服器的堆疊。
-
選擇更新。
-
選擇取代目前範本
-
上傳新範本。CloudFormation 變更集可協助您了解範本變更會如何影響執行中的資源,然後再實作它們。在此範例中,將修改 Transfer 伺服器資源,並將移除 VPCEndpoint 資源。VPC 端點類型伺服器會代表您建立 VPC 端點,取代原始
VPCEndpoint資源。上傳新範本後,變更集看起來會類似以下內容:
-
更新堆疊。
-
堆疊更新完成後,請前往 Transfer Family 管理主控台,網址為 https://https://console.aws.amazon.com/transfer/
。 -
重新啟動伺服器。選擇您在其中更新的伺服器 AWS CloudFormation,然後從動作功能表中選擇開始。
使用 API 更新伺服器 EndpointType
您可以使用 describe-server AWS CLI 命令或 UpdateServer API 命令。下列範例指令碼會停止 Transfer Family 伺服器、更新 EndpointType、移除 VPC_ENDPOINT,以及啟動伺服器。
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])