本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 Amazon EC2 進行測試設定
此設定示範從 Amazon EC2 執行個體到 Amazon Simple Storage Service 的AWS 管理主控台私有存取連線。此範例使用 CloudFormation建立網路組態,並使用遠端桌面通訊協定 (RDPAWS Systems Manager) 透過 Fleet Manager ( 的功能) 連線至 Amazon EC2 Windows 執行個體。
下圖說明使用 Amazon EC2 存取 AWS 管理主控台 私有存取設定的工作流程。它顯示使用者如何使用私有端點連接到 Amazon S3。
複製下列CloudFormation範本,並將其儲存到您在設定網路程序的步驟三中使用的檔案。
Description: | AWS Management Console Private Access. Parameters: VpcCIDR: Type: String Default: 172.16.0.0/16 Description: CIDR range for VPC PrivateSubnet1CIDR: Type: String Default: 172.16.1.0/24 Description: CIDR range for Private Subnet 1 PrivateSubnet2CIDR: Type: String Default: 172.16.2.0/24 Description: CIDR range for Private Subnet 2 Ec2KeyPair: Type: AWS::EC2::KeyPair::KeyName Description: The EC2 KeyPair to use to connect to the Windows instance LatestWindowsAmiId: Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id> Default: /aws/service/ami-windows-latest/Windows_Server-2022-English-Full-Base InstanceTypeParameter: Type: String Default: m5.large Resources: ######################### # VPC AND SUBNETS ######################### AppVPC: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref VpcCIDR InstanceTenancy: default EnableDnsSupport: true EnableDnsHostnames: true PrivateSubnet1: Type: AWS::EC2::Subnet Properties: VpcId: !Ref AppVPC CidrBlock: !Ref PrivateSubnet1CIDR AvailabilityZone: Fn::Select: - 0 - Fn::GetAZs: "" PrivateSubnet2: Type: AWS::EC2::Subnet Properties: VpcId: !Ref AppVPC CidrBlock: !Ref PrivateSubnet2CIDR AvailabilityZone: Fn::Select: - 1 - Fn::GetAZs: "" ######################### # Route Tables ######################### PrivateRouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref AppVPC PrivateSubnet1RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: !Ref PrivateRouteTable SubnetId: !Ref PrivateSubnet1 PrivateSubnet2RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: !Ref PrivateRouteTable SubnetId: !Ref PrivateSubnet2 ######################### # SECURITY GROUPS ######################### VPCEndpointSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Allow TLS for VPC Endpoint VpcId: !Ref AppVPC SecurityGroupIngress: - IpProtocol: tcp FromPort: 443 ToPort: 443 CidrIp: !GetAtt AppVPC.CidrBlock EC2SecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Default EC2 Instance SG VpcId: !Ref AppVPC SecurityGroupIngress: - IpProtocol: tcp FromPort: 3389 ToPort: 3389 CidrIp: !Ref VpcCIDR ######################### # VPC ENDPOINTS ######################### VPCEndpointInterfaceSsm: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnet1 - !Ref PrivateSubnet2 SecurityGroupIds: - !Ref VPCEndpointSecurityGroup ServiceName: !Sub com.amazonaws.${AWS::Region}.ssm VpcId: !Ref AppVPC PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: '*' Action: '*' Resource: '*' Condition: StringEquals: aws:PrincipalAccount: !Ref AWS::AccountId aws:ResourceAccount: !Ref AWS::AccountId aws:SourceVpc: !Ref AppVPC - Effect: Deny Principal: '*' Action: '*' Resource: '*' Condition: StringNotEquals: aws:PrincipalAccount: !Ref AWS::AccountId aws:ResourceAccount: !Ref AWS::AccountId aws:SourceVpc: !Ref AppVPC VPCEndpointInterfaceEc2Messages: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnet1 - !Ref PrivateSubnet2 SecurityGroupIds: - !Ref VPCEndpointSecurityGroup ServiceName: !Sub com.amazonaws.${AWS::Region}.ec2messages VpcId: !Ref AppVPC PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: '*' Action: '*' Resource: '*' Condition: StringEquals: aws:PrincipalAccount: !Ref AWS::AccountId aws:ResourceAccount: !Ref AWS::AccountId aws:SourceVpc: !Ref AppVPC - Effect: Deny Principal: '*' Action: '*' Resource: '*' Condition: StringNotEquals: aws:PrincipalAccount: !Ref AWS::AccountId aws:ResourceAccount: !Ref AWS::AccountId aws:SourceVpc: !Ref AppVPC VPCEndpointInterfaceSsmMessages: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnet1 - !Ref PrivateSubnet2 SecurityGroupIds: - !Ref VPCEndpointSecurityGroup ServiceName: !Sub com.amazonaws.${AWS::Region}.ssmmessages VpcId: !Ref AppVPC PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: '*' Action: '*' Resource: '*' Condition: StringEquals: aws:PrincipalAccount: !Ref AWS::AccountId aws:ResourceAccount: !Ref AWS::AccountId aws:SourceVpc: !Ref AppVPC - Effect: Deny Principal: '*' Action: '*' Resource: '*' Condition: StringNotEquals: aws:PrincipalAccount: !Ref AWS::AccountId aws:ResourceAccount: !Ref AWS::AccountId aws:SourceVpc: !Ref AppVPC VPCEndpointInterfaceSignin: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnet1 - !Ref PrivateSubnet2 SecurityGroupIds: - !Ref VPCEndpointSecurityGroup ServiceName: !Sub com.amazonaws.${AWS::Region}.signin VpcId: !Ref AppVPC PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: '*' Action: signin:Authenticate Resource: '*' Condition: StringEquals: aws:ResourceAccount: !Ref AWS::AccountId - Effect: Allow Principal: '*' Action: - signin:AuthorizeOAuth2Access - signin:CreateOAuth2Token Resource: '*' Condition: StringEquals: aws:PrincipalAccount: !Ref AWS::AccountId VPCEndpointInterfaceConsole: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnet1 - !Ref PrivateSubnet2 SecurityGroupIds: - !Ref VPCEndpointSecurityGroup ServiceName: !Sub com.amazonaws.${AWS::Region}.console VpcId: !Ref AppVPC PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: '*' Action: '*' Resource: '*' Condition: StringEquals: aws:PrincipalAccount: !Ref AWS::AccountId aws:ResourceAccount: !Ref AWS::AccountId aws:SourceVpc: !Ref AppVPC - Effect: Deny Principal: '*' Action: '*' Resource: '*' Condition: StringNotEquals: aws:PrincipalAccount: !Ref AWS::AccountId aws:ResourceAccount: !Ref AWS::AccountId aws:SourceVpc: !Ref AppVPC VPCEndpointInterfaceConsoleStatic: # console-static only supports the full access endpoint policy Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnet1 - !Ref PrivateSubnet2 SecurityGroupIds: - !Ref VPCEndpointSecurityGroup ServiceName: !Sub com.amazonaws.${AWS::Region}.console-static VpcId: !Ref AppVPC ######################### # EC2 INSTANCE ######################### Ec2InstanceRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: - ec2.amazonaws.com Action: - sts:AssumeRole Path: / ManagedPolicyArns: - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore Ec2InstanceProfile: Type: AWS::IAM::InstanceProfile Properties: Path: / Roles: - !Ref Ec2InstanceRole Ec2LaunchTemplate: Type: AWS::EC2::LaunchTemplate Properties: LaunchTemplateData: MetadataOptions: HttpTokens: required EC2WinInstance: Type: AWS::EC2::Instance Properties: ImageId: !Ref LatestWindowsAmiId IamInstanceProfile: !Ref Ec2InstanceProfile KeyName: !Ref Ec2KeyPair InstanceType: !Ref InstanceTypeParameter SubnetId: !Ref PrivateSubnet1 SecurityGroupIds: - !Ref EC2SecurityGroup BlockDeviceMappings: - DeviceName: /dev/sda1 Ebs: VolumeSize: 50 LaunchTemplate: LaunchTemplateId: !Ref Ec2LaunchTemplate Version: !GetAtt Ec2LaunchTemplate.LatestVersionNumber Tags: - Key: Name Value: Console VPCE test instance
若要設定網路
-
登入您組織的管理帳戶,並開啟 CloudFormation 主控台
。 -
選擇建立堆疊。
-
選擇 With new resources (standard) (使用新資源 (標準))。上傳您先前建立的CloudFormation範本檔案,然後選擇下一步。
-
輸入堆疊名稱,例如
PrivateConsoleNetworkForS3,然後選擇 下一步。 -
對於 VPC 和子網路,請輸入您偏好的 IP CIDR 範圍,或使用提供的預設值。如果您使用預設值,請確認它們未與 中的現有 VPC 資源重疊AWS 帳戶。
-
對於 EC2KeyPair 參數,請從帳戶中現有的 Amazon EC2 金鑰對中選取一個金鑰。如果沒有現有的 Amazon EC2 金鑰對,您必須先建立一個,然後再進行下一個步驟。如需詳細資訊,請參閱《Amazon EC2 使用者指南》中的使用 Amazon EC2 建立金鑰對。 Amazon EC2
-
選擇建立堆疊。
-
建立堆疊後,選擇 資源 索引標籤以檢視已建立的資源。
如要連線到 Amazon EC2 執行個體
-
登入您組織的管理帳戶,並開啟 Amazon EC2 主控台
。 -
在導覽窗格中,選擇執行個體。
-
在執行個體頁面上,選取CloudFormation範本建立的主控台 VPCE 測試執行個體。然後選擇 連線。
注意
此範例使用 Fleet Manager 來連線至您的 Windows ServerAWS Systems Manager Explorer。可能需要幾分鐘才會開始連接。
-
在 連線至執行個體 頁面上,選擇 RDP 用戶端,然後選擇 使用 Fleet Manager 連線。
-
選擇 Fleet Manager 遠端桌面。
-
若要取得 Amazon EC2 執行個體的管理密碼並使用 Web 介面存取 Windows 桌面,請使用與您在建立CloudFormation範本 時使用的 Amazon EC2 金鑰對相關聯的私有金鑰。
-
從 Amazon EC2 Windows 執行個體,在瀏覽器AWS 管理主控台中開啟 。
-
使用AWS登入資料登入後,請開啟 Amazon S3 主控台
,並驗證您使用 Private Access 連線AWS 管理主控台。
測試AWS 管理主控台私有存取設定
-
登入您組織的管理帳戶,並開啟 Amazon S3 主控台
。 -
選擇導覽列中的鎖定私有圖示,以檢視使用中的 VPC 端點。下列螢幕擷取畫面顯示鎖定私有圖示的位置和 VPC 資訊。