使用 管理和連線至 Amazon Aurora DSQL 叢集 AWS PrivateLink - Amazon Aurora DSQL

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 管理和連線至 Amazon Aurora DSQL 叢集 AWS PrivateLink

使用 AWS PrivateLink for Amazon Aurora DSQL,您可以在 Amazon Virtual Private Cloud 中佈建介面 Amazon VPC 端點 (介面端點)。這些端點可直接透過 Amazon VPC 和 內部部署的應用程式存取 AWS Direct Connect,或在 AWS 區域 Amazon VPC 對等互連的不同 中存取。使用 AWS PrivateLink 和 介面端點,您可以簡化從應用程式到 Aurora DSQL 的私有網路連線。

Amazon VPC 內的應用程式可以使用 Amazon VPC 介面端點存取 Aurora DSQL,而不需要公有 IP 地址。

介面端點由一或多個彈性網路介面 (ENIs) 表示,這些介面會從 Amazon VPC 中的子網路指派私有 IP 地址。透過介面端點對 Aurora DSQL 的請求會保留在 AWS 網路上。如需如何將 Amazon VPC 連線至內部部署網路的詳細資訊,請參閱 AWS Direct Connect 使用者指南AWS Site-to-Site VPN VPN 使用者指南。

如需介面端點的一般資訊,請參閱AWS PrivateLink《 使用者指南》中的使用介面 Amazon VPC 端點存取 AWS 服務

Aurora DSQL 的 Amazon VPC 端點類型

Aurora DSQL 需要兩種不同類型的 AWS PrivateLink 端點。

  1. 管理端點 — 此端點用於管理操作,例如 getdelete、、 create update和 Aurora DSQL 叢集list上的 。請參閱 使用 管理 Aurora DSQL 叢集 AWS PrivateLink

  2. 連線端點 — 此端點用於透過 PostgreSQL 用戶端連線至 Aurora DSQL 叢集。請參閱 使用 連線至 Aurora DSQL 叢集 AWS PrivateLink

Amazon VPC 考量適用於 Aurora DSQL AWS PrivateLink 的 。如需詳細資訊,請參閱《 AWS PrivateLink 指南》中的使用介面 VPC 端點和配額存取 AWS 服務AWS PrivateLink

您可以使用 AWS Command Line Interface 或 AWS 軟體開發套件 (SDKs) 透過 Aurora DSQL 介面端點管理 Aurora DSQL 叢集。

建立 Amazon VPC 端點

若要建立 Amazon VPC 介面端點,請參閱《 AWS PrivateLink 指南》中的建立 Amazon VPC 端點

aws ec2 create-vpc-endpoint \ --region region \ --service-name com.amazonaws.region.dsql \ --vpc-id your-vpc-id \ --subnet-ids your-subnet-id \ --vpc-endpoint-type Interface \ --security-group-ids client-sg-id \

若要使用 Aurora DSQL API 請求的預設區域 DNS 名稱,請勿在建立 Aurora DSQL 介面端點時停用私有 DNS。啟用私有 DNS 時,從 Amazon VPC 內對 Aurora DSQL 服務的請求會自動解析為 Amazon VPC 端點的私有 IP 地址,而不是公有 DNS 名稱。啟用私有 DNS 時,Amazon VPC 內發出的 Aurora DSQL 請求會自動解析為您的 Amazon VPC 端點。

如果未啟用私有 DNS,請使用 --region--endpoint-url 參數搭配 AWS CLI 命令,透過 Aurora DSQL 介面端點管理 Aurora DSQL 叢集。

使用端點 URL 列出叢集

在下列範例中,將 和 Amazon VPC 端點 ID 的 DNS 名稱取代 AWS 區域 us-east-1vpce-1a2b3c4d-5e6f.dynamodb.us-east-1.vpce.amazonaws.com為您自己的資訊。

aws dsql --region us-east-1 --endpoint-url https://vpce-1a2b3c4d-5e6f.dsql.us-east-1.vpce.amazonaws.com list-clusters

API 操作

如需在 Aurora DSQL 中管理資源的文件,請參閱 Aurora DSQL API 參考

管理端點政策

透過徹底測試和設定 Amazon VPC 端點政策,您可以協助確保您的 Aurora DSQL 叢集安全、合規,並符合組織的特定存取控制和控管要求。

範例:完整 Aurora DSQL 存取政策

下列政策會透過指定的 Amazon VPC 端點授予所有 Aurora DSQL 動作和資源的完整存取權。

aws ec2 modify-vpc-endpoint \ --vpc-endpoint-id vpce-xxxxxxxxxxxxxxxxx \ --region region \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "*", "Action": "dsql:*", "Resource": "*" } ] }'

範例:受限制的 Aurora DSQL 存取政策

下列政策僅允許這些 Aurora DSQL 動作。

  • CreateCluster

  • GetCluster

  • ListClusters

所有其他 Aurora DSQL 動作都會遭到拒絕。

JSON
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "*", "Action": [ "dsql:CreateCluster", "dsql:GetCluster", "dsql:ListClusters" ], "Resource": "*" } ] }

設定 AWS PrivateLink 端點並處於作用中狀態後,您可以使用 PostgreSQL 用戶端連線至 Aurora DSQL 叢集。以下連線指示概述建構適當的主機名稱以透過 AWS PrivateLink 端點連線的步驟。

步驟 1:取得叢集的服務名稱

建立端點以 AWS PrivateLink 連線至叢集時,您必須先擷取叢集特定的服務名稱。

AWS CLI
aws dsql get-vpc-endpoint-service-name \ --region us-east-1 \ --identifier your-cluster-id

回應範例

{
    "serviceName": "com.amazonaws.us-east-1.dsql-fnh4"
}

服務名稱包含識別符,例如dsql-fnh4範例中的 。建構主機名稱以連線至叢集時,也需要此識別符。

AWS SDK for Python (Boto3)
import boto3 dsql_client = boto3.client('dsql', region_name='us-east-1') response = dsql_client.get_vpc_endpoint_service_name( identifier='your-cluster-id' ) service_name = response['serviceName'] print(f"Service Name: {service_name}")
AWS SDK for Java 2.x
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.dsql.DsqlClient; import software.amazon.awssdk.services.dsql.model.GetVpcEndpointServiceNameRequest; import software.amazon.awssdk.services.dsql.model.GetVpcEndpointServiceNameResponse; String region = "us-east-1"; String clusterId = "your-cluster-id"; DsqlClient dsqlClient = DsqlClient.builder() .region(Region.of(region)) .credentialsProvider(DefaultCredentialsProvider.create()) .build(); GetVpcEndpointServiceNameResponse response = dsqlClient.getVpcEndpointServiceName( GetVpcEndpointServiceNameRequest.builder() .identifier(clusterId) .build() ); String serviceName = response.serviceName(); System.out.println("Service Name: " + serviceName);

步驟 2:建立 Amazon VPC 端點

使用上一個步驟中取得的服務名稱,建立 Amazon VPC 端點。

重要

以下連線指示僅適用於在啟用 DNS 私有時連線至叢集。建立端點時請勿使用 --no-private-dns-enabled旗標,因為這會使下列連線指示無法正常運作。如果您停用私有 DNS,則需要建立自己的萬用字元私有 DNS 記錄,以指向建立的端點。

AWS CLI
aws ec2 create-vpc-endpoint \ --region us-east-1 \ --service-name service-name-for-your-cluster \ --vpc-id your-vpc-id \ --subnet-ids subnet-id-1 subnet-id-2 \ --vpc-endpoint-type Interface \ --security-group-ids security-group-id

回應範例

{
    "VpcEndpoint": {
        "VpcEndpointId": "vpce-0123456789abcdef0",
        "VpcEndpointType": "Interface",
        "VpcId": "vpc-0123456789abcdef0",
        "ServiceName": "com.amazonaws.us-east-1.dsql-fnh4",
        "State": "pending",
        "RouteTableIds": [],
        "SubnetIds": [
            "subnet-0123456789abcdef0",
            "subnet-0123456789abcdef1"
        ],
        "Groups": [
            {
                "GroupId": "sg-0123456789abcdef0",
                "GroupName": "default"
            }
        ],
        "PrivateDnsEnabled": true,
        "RequesterManaged": false,
        "NetworkInterfaceIds": [
            "eni-0123456789abcdef0",
            "eni-0123456789abcdef1"
        ],
        "DnsEntries": [
            {
                "DnsName": "*.dsql-fnh4.us-east-1.vpce.amazonaws.com",
                "HostedZoneId": "Z7HUB22UULQXV"
            }
        ],
        "CreationTimestamp": "2025-01-01T00:00:00.000Z"
    }
} 
SDK for Python
import boto3 ec2_client = boto3.client('ec2', region_name='us-east-1') response = ec2_client.create_vpc_endpoint( VpcEndpointType='Interface', VpcId='your-vpc-id', ServiceName='com.amazonaws.us-east-1.dsql-fnh4', # Use the service name from previous step SubnetIds=[ 'subnet-id-1', 'subnet-id-2' ], SecurityGroupIds=[ 'security-group-id' ] ) vpc_endpoint_id = response['VpcEndpoint']['VpcEndpointId'] print(f"VPC Endpoint created with ID: {vpc_endpoint_id}")
SDK for Java 2.x

使用 Aurora DSQL APIs端點 URL

import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.ec2.Ec2Client; import software.amazon.awssdk.services.ec2.model.CreateVpcEndpointRequest; import software.amazon.awssdk.services.ec2.model.CreateVpcEndpointResponse; import software.amazon.awssdk.services.ec2.model.VpcEndpointType; String region = "us-east-1"; String serviceName = "com.amazonaws.us-east-1.dsql-fnh4"; // Use the service name from previous step String vpcId = "your-vpc-id"; Ec2Client ec2Client = Ec2Client.builder() .region(Region.of(region)) .credentialsProvider(DefaultCredentialsProvider.create()) .build(); CreateVpcEndpointRequest request = CreateVpcEndpointRequest.builder() .vpcId(vpcId) .serviceName(serviceName) .vpcEndpointType(VpcEndpointType.INTERFACE) .subnetIds("subnet-id-1", "subnet-id-2") .securityGroupIds("security-group-id") .build(); CreateVpcEndpointResponse response = ec2Client.createVpcEndpoint(request); String vpcEndpointId = response.vpcEndpoint().vpcEndpointId(); System.out.println("VPC Endpoint created with ID: " + vpcEndpointId);

使用連線 AWS PrivateLink 端點連線至 Aurora DSQL 叢集

設定 AWS PrivateLink 端點並處於作用中狀態 (檢查 State是否為 available) 後,您可以使用 PostgreSQL 用戶端連線至 Aurora DSQL 叢集。如需有關使用 AWS SDKs的說明,您可以遵循使用 Aurora DSQL 進行程式設計中的指南。您必須變更叢集端點以符合主機名稱格式。

建構主機名稱

透過 連線的主機名稱與公有 DNS 主機名稱 AWS PrivateLink 不同。您需要使用下列元件來建構它。

  1. Your-cluster-id

  2. 來自服務名稱的服務識別符。例如:dsql-fnh4

  3. 的 AWS 區域

使用下列格式:cluster-id.service-identifier.region.on.aws

範例:使用 PostgreSQL 的連線

# Set environment variables export CLUSTERID=your-cluster-id export REGION=us-east-1 export SERVICE_IDENTIFIER=dsql-fnh4 # This should match the identifier in your service name # Construct the hostname export HOSTNAME="$CLUSTERID.$SERVICE_IDENTIFIER.$REGION.on.aws" # Generate authentication token export PGPASSWORD=$(aws dsql --region $REGION generate-db-connect-admin-auth-token --hostname $HOSTNAME) # Connect using psql psql -d postgres -h $HOSTNAME -U admin

常見問題與解決方案

下表列出 AWS PrivateLink 與 Aurora DSQL 相關的常見問題和解決方案。

問題 可能的原因 解決方案

連線逾時

安全群組未正確設定

使用 Amazon VPC Reachability Analyzer 確保您的聯網設定允許連接埠 5432 上的流量。

DNS 解析失敗

未啟用私有 DNS

確認已在啟用私有 DNS 的情況下建立 Amazon VPC 端點。

身分驗證失敗

登入資料不正確或權杖過期

產生新的身分驗證字符並驗證使用者名稱。

找不到服務名稱

不正確的叢集 ID

擷取服務名稱 AWS 區域 時,請再次檢查您的叢集 ID 和 。

如需詳細資訊,請參閱下列資源: