

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

# 對 Amazon Keyspaces 中的連線錯誤進行故障診斷
<a name="troubleshooting.connecting"></a>

連線時發生問題？ 以下是一些常見問題，以及如何解決這些問題。

## 連線至 Amazon Keyspaces 端點時發生錯誤
<a name="troubleshooting-connecting"></a>

失敗的連線和連線錯誤可能會導致不同的錯誤訊息。下一節涵蓋最常見的案例。

**Topics**
+ [我無法使用 cqlsh 連線到 Amazon Keyspaces](#troubleshooting.connection.cqlsh)
+ [我無法使用 Cassandra 用戶端驅動程式連線至 Amazon Keyspaces](#troubleshooting.connection.driver)

### 我無法使用 cqlsh 連線到 Amazon Keyspaces
<a name="troubleshooting.connection.cqlsh"></a>

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces 端點，但連線與 的連線失敗`Connection error`。**

如果您嘗試連線至 Amazon Keyspaces 資料表，但尚未正確設定 cqlsh，則連線會失敗。下節提供在您嘗試使用 cqlsh 建立連線時，導致連線錯誤的最常見組態問題範例。

**注意**  
如果您嘗試從 VPC 連線至 Amazon Keyspaces，則需要額外的許可。若要使用 VPC 端點成功設定連線，請遵循中的步驟[教學課程：使用介面 VPC 端點連線至 Amazon Keyspaces](vpc-endpoints-tutorial.md)。

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但發生連線`timed out`錯誤。**

如果您未提供正確的連接埠，則可能會發生這種情況，這會導致下列錯誤。

```
#  cqlsh cassandra.us-east-1.amazonaws.com 9140 -u "USERNAME" -p "PASSWORD" --ssl
Connection error: ('Unable to connect to any servers', {'3.234.248.199': error(None, "Tried connecting to [('3.234.248.199', 9140)]. Last error: timed out")})
```

若要解決此問題，請確認您使用連接埠 9142 進行連線。

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但發生錯誤`Name or service not known`。**

如果您使用的端點拼寫錯誤或不存在，則可能會發生這種情況。在下列範例中，端點的名稱拼錯。

```
#  cqlsh cassandra.us-east-1.amazon.com 9142 -u "USERNAME" -p "PASSWORD" --ssl
Traceback (most recent call last):
  File "/usr/bin/cqlsh.py", line 2458, in >module>
    main(*read_options(sys.argv[1:], os.environ))
  File "/usr/bin/cqlsh.py", line 2436, in main
    encoding=options.encoding)
  File "/usr/bin/cqlsh.py", line 484, in __init__
    load_balancing_policy=WhiteListRoundRobinPolicy([self.hostname]),
  File "/usr/share/cassandra/lib/cassandra-driver-internal-only-3.11.0-bb96859b.zip/cassandra-driver-3.11.0-bb96859b/cassandra/policies.py", line 417, in __init__
socket.gaierror: [Errno -2] Name or service not known
```

若要在使用公有端點進行連線時解決此問題，請從 選取可用的端點[Amazon Keyspaces 的服務端點](programmatic.endpoints.md)，並確認端點的名稱沒有任何錯誤。如果您使用 VPC 端點進行連線，請確認 cqlsh 組態中的 VPC 端點資訊正確無誤。

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但收到`OperationTimedOut`錯誤。**

Amazon Keyspaces 需要為連線啟用 SSL，以確保強大的安全性。如果您收到下列錯誤，則 SSL 參數可能會遺失。

```
# cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD"
Connection error: ('Unable to connect to any servers', {'3.234.248.192': OperationTimedOut('errors=Timed out creating connection (5 seconds), last_host=None',)})
#
```

若要解決此問題，請將下列旗標新增至 cqlsh 連線命令。

```
--ssl
```

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，並收到`SSL transport factory requires a valid certfile to be specified`錯誤。**

在此情況下，缺少 SSL/TLS 憑證的路徑，這會導致下列錯誤。

```
# cat .cassandra/cqlshrc
[connection]
port = 9142
factory = cqlshlib.ssl.ssl_transport_factory
#


# cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD" --ssl
Validation is enabled; SSL transport factory requires a valid certfile to be specified. Please provide path to the certfile in [ssl] section as 'certfile' option in /root/.cassandra/cqlshrc (or use [certfiles] section) or set SSL_CERTFILE environment variable.
#
```

若要解決此問題，請將路徑新增至電腦上的 certfile。如需詳細資訊，請參閱[如何手動設定 TLS 的`cqlsh`連線](programmatic.cqlsh.md#encrypt_using_tls)。

```
certfile =  path_to_file/keyspaces-bundle.pem
```

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但收到`No such file or directory`錯誤。**

如果電腦上憑證檔案的路徑錯誤，這可能會導致以下錯誤。

```
# cat .cassandra/cqlshrc
[connection]
port = 9142
factory = cqlshlib.ssl.ssl_transport_factory

[ssl]
validate = true
certfile = /root/wrong_path/keyspaces-bundle.pem
#



# cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD" --ssl
Connection error: ('Unable to connect to any servers', {'3.234.248.192': IOError(2, 'No such file or directory')})
#
```

若要解決此問題，請確認電腦上 certfile 的路徑正確無誤。如需詳細資訊，請參閱[如何手動設定 TLS 的`cqlsh`連線](programmatic.cqlsh.md#encrypt_using_tls)。

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但收到`[X509] PEM lib`錯誤。**

如果 SSL/TLS 憑證`pem`檔案無效，則可能會發生這種情況，這會導致下列錯誤。

```
# cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD" --ssl
Connection error: ('Unable to connect to any servers', {'3.234.248.241': error(185090057, u"Tried connecting to [('3.234.248.241', 9142)]. Last error: [X509] PEM lib (_ssl.c:3063)")})
#
```

若要解決此問題，請確定您已下載必要的數位憑證。如需詳細資訊，請參閱[如何手動設定 TLS 的`cqlsh`連線](programmatic.cqlsh.md#encrypt_using_tls)。

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但收到 `unknown` SSL 錯誤。**

如果 SSL/TLS 憑證`pem`檔案是空的，則可能會發生這種情況，這會導致下列錯誤。

```
# cqlsh cassandra.us-east-1.amazonaws.com -u "USERNAME" -p "PASSWORD" --ssl
Connection error: ('Unable to connect to any servers', {'3.234.248.220': error(0, u"Tried connecting to [('3.234.248.220', 9142)]. Last error: unknown error (_ssl.c:3063)")})
#
```

若要解決此問題，請確定您已下載必要的數位憑證。您可以使用下列主題 中的步驟來確認這一點[如何手動設定 TLS 的`cqlsh`連線](programmatic.cqlsh.md#encrypt_using_tls)。

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但收到`SSL: CERTIFICATE_VERIFY_FAILED`錯誤。**

如果無法驗證 SSL/TLS 憑證檔案，則可能會發生這種情況，這會導致下列錯誤。

```
Connection error: ('Unable to connect to any servers', {'3.234.248.223': error(1, u"Tried connecting to [('3.234.248.223', 9142)]. Last error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)")})
```

若要解決此問題，請確定您已下載必要的數位憑證。您可以使用下列主題 中的步驟來確認這一點[如何手動設定 TLS 的`cqlsh`連線](programmatic.cqlsh.md#encrypt_using_tls)。

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但收到`Last error: timed out`錯誤。**

如果您未在 Amazon EC2 安全群組中為 Amazon Keyspaces 設定傳出規則，這可能會導致以下錯誤。

```
# cqlsh cassandra.us-east-1.amazonaws.com 9142 -u  "USERNAME" -p "PASSWORD" --ssl
Connection error: ('Unable to connect to any servers', {'3.234.248.206': error(None, "Tried connecting to [('3.234.248.206', 9142)]. Last error: timed out")})
#
```

若要確認此問題是由 Amazon EC2 執行個體的組態造成，而非 `cqlsh`，您可以嘗試使用 連線到您的金鑰空間 AWS CLI，例如使用下列命令。

```
aws keyspaces list-tables --keyspace-name 'my_keyspace'
```

如果此命令也逾時，表示 Amazon EC2 執行個體未正確設定。

若要確認您有足夠的許可來存取 Amazon Keyspaces，您可以使用 AWS CloudShell 來與 連線`cqlsh`。如果連線已建立，您需要設定 Amazon EC2 執行個體。

若要解決此問題，請確認您的 Amazon EC2 執行個體具有允許流量至 Amazon Keyspaces 的傳出規則。如果不是這種情況，您需要為 EC2 執行個體建立新的安全群組，並新增允許傳出流量到 Amazon Keyspaces 資源的規則。若要更新傳出規則以允許流量到 Amazon Keyspaces，請從**類型**下拉式選單中選擇 **CQLSH/CASSANDRA**。

使用傳出流量規則建立新的安全群組之後，您需要將其新增至執行個體。選取執行個體，然後選擇**動作**、**安全性**，然後選擇**變更安全群組**。使用傳出規則新增安全群組，但請確定預設群組也保持可用。

如需如何檢視和編輯 EC2 傳出規則的詳細資訊，請參閱《[Amazon EC2 使用者指南》中的將規則新增至安全群組](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/working-with-security-groups.html#adding-security-group-rule)。

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但收到`Unauthorized`錯誤。**

如果您在 IAM 使用者政策中缺少 Amazon Keyspaces 許可，這可能會導致以下錯誤。

```
# cqlsh cassandra.us-east-1.amazonaws.com 9142 -u  "testuser-at-12345678910" -p "PASSWORD" --ssl
Connection error: ('Unable to connect to any servers', {'3.234.248.241': AuthenticationFailed('Failed to authenticate to 3.234.248.241: Error from server: code=2100 [Unauthorized] message="User arn:aws:iam::12345678910:user/testuser has no permissions."',)})
#
```

若要解決此問題，請確定 IAM 使用者`testuser-at-12345678910`具有存取 Amazon Keyspaces 的許可。如需授予 Amazon Keyspaces 存取權的 IAM 政策範例，請參閱 [Amazon Keyspaces 身分型政策範例](security_iam_id-based-policy-examples.md)。

如需 IAM 存取特定的疑難排解指引，請參閱 [對 Amazon Keyspaces 身分和存取進行故障診斷](security_iam_troubleshoot.md)。

**您嘗試使用 cqlsh 連線至 Amazon Keyspaces，但收到`Bad credentials`錯誤。**

如果使用者名稱或密碼錯誤，則可能會發生這種情況，這會導致下列錯誤。

```
# cqlsh cassandra.us-east-1.amazonaws.com 9142 -u  "USERNAME" -p "PASSWORD" --ssl
Connection error: ('Unable to connect to any servers', {'3.234.248.248': AuthenticationFailed('Failed to authenticate to 3.234.248.248: Error from server: code=0100 [Bad credentials] message="Provided username USERNAME and/or password are incorrect"',)})
#
```

若要解決此問題，請確認程式碼中的 *USERNAME* 和 *PASSWORD* 與您產生[服務特定登入](programmatic.credentials.ssc.md)資料時取得的使用者名稱和密碼相符。

**重要**  
如果您在嘗試與 cqlsh 連線時持續看到錯誤，請使用 `--debug`選項重新執行命令，並在聯絡 時包含詳細輸出 支援。

### 我無法使用 Cassandra 用戶端驅動程式連線至 Amazon Keyspaces
<a name="troubleshooting.connection.driver"></a>

下列各節顯示與 Cassandra 用戶端驅動程式連線時最常見的錯誤。

**您嘗試使用 DataStax Java 驅動程式連線至 Amazon Keyspaces 資料表，但收到`NodeUnavailableException`錯誤。**

如果嘗試請求的連線中斷，則會導致下列錯誤。

```
[com.datastax.oss.driver.api.core.NodeUnavailableException: No connection was available to Node(endPoint=vpce-22ff22f2f22222fff-aa1bb234.cassandra.us-west-2.vpce.amazonaws.com/11.1.1111.222:9142, hostId=1a23456b-c77d-8888-9d99-146cb22d6ef6, hashCode=123ca4567)]
```

若要解決此問題，請尋找活動訊號值，如果訊號值較高，請將其降至 30 秒。

```
advanced.heartbeat.interval = 30 seconds
```

然後尋找相關聯的逾時，並確保值設定為至少 5 秒。

```
advanced.connection.init-query-timeout = 5 seconds
```

**您嘗試使用驅動程式和 SigV4 外掛程式連線至 Amazon Keyspaces 資料表，但收到`AttributeError`錯誤。**

如果登入資料未正確設定，則會導致下列錯誤。

```
cassandra.cluster.NoHostAvailable: (‘Unable to connect to any servers’,
 {‘44.234.22.154:9142’: AttributeError(“‘NoneType’ object has no attribute ‘access_key’“)})
```

若要解決此問題，請確認您在使用 SigV4 外掛程式時，傳遞與您的 IAM 使用者或角色相關聯的登入資料。SigV4 外掛程式需要下列登入資料。
+ `AWS_ACCESS_KEY_ID` – 指定與 IAM 使用者或角色相關聯的 AWS 存取金鑰。
+ `AWS_SECRET_ACCESS_KEY`– 指定與存取金鑰相關聯的私密金鑰。這基本上是存取金鑰的「密碼」。

若要進一步了解存取金鑰和 SigV4 外掛程式，請參閱 [建立和設定 Amazon Keyspaces 的 AWS 登入資料](access.credentials.md)。

**您嘗試使用驅動程式連線至 Amazon Keyspaces 資料表，但收到`PartialCredentialsError`錯誤。**

如果遺失 `AWS_SECRET_ACCESS_KEY` ，可能會導致下列錯誤。

```
cassandra.cluster.NoHostAvailable: (‘Unable to connect to any servers’, {‘44.234.22.153:9142’: 
 PartialCredentialsError(‘Partial credentials found in config-file, missing: aws_secret_access_key’)})
```

若要解決此問題，請確認您使用 SigV4 外掛程式`AWS_SECRET_ACCESS_KEY`時同時傳遞 `AWS_ACCESS_KEY_ID`和 。若要進一步了解存取金鑰和 SigV4 外掛程式，請參閱 [建立和設定 Amazon Keyspaces 的 AWS 登入資料](access.credentials.md)。

**您嘗試使用驅動程式連線至 Amazon Keyspaces 資料表，但收到`Invalid signature`錯誤。**

如果簽章所需的任何元件錯誤或未正確定義工作階段，則可能會發生這種情況。
+ `AWS_ACCESS_KEY_ID`
+ `AWS_SECRET_ACCESS_KEY`
+ `AWS_DEFAULT_REGION`

下列錯誤是無效的存取金鑰範例。

```
cassandra.cluster.NoHostAvailable: (‘Unable to connect to any servers’, {‘11.234.11.234:9142’: 
 AuthenticationFailed(‘Failed to authenticate to 11.234.11.234:9142: Error from server: code=0100 
 [Bad credentials] message=“Authentication failure: Invalid signature”’)})
```

若要解決此問題，請確認存取金鑰和 AWS 區域 已正確設定供 SigV4 外掛程式存取 Amazon Keyspaces。若要進一步了解存取金鑰和 SigV4 外掛程式，請參閱 [建立和設定 Amazon Keyspaces 的 AWS 登入資料](access.credentials.md)。

#### 我的 VPC 端點連線無法正常運作
<a name="troubleshooting.connection.vpce"></a>

**您嘗試使用 VPC 端點連線至 Amazon Keyspaces，但收到字符映射錯誤或輸送量低。 **

如果 VPC 端點連線未正確設定，則可能會發生這種情況。

若要解決這些問題，請確認下列組態詳細資訊。若要遵循step-by-step教學，了解如何透過 Amazon Keyspaces 的介面 VPC 端點設定連線，請參閱 [教學課程：使用介面 VPC 端點連線至 Amazon Keyspaces](vpc-endpoints-tutorial.md)。

1. 確認用於連線至 Amazon Keyspaces 的 IAM 實體具有使用者資料表的讀取/寫入存取權，以及對系統資料表的讀取存取權，如下列範例所示。

   ```
   {
      "Version":"2012-10-17",		 	 	 
      "Statement":[
         {
            "Effect":"Allow",
            "Action":[
               "cassandra:Select",
               "cassandra:Modify"
            ],
            "Resource":[
               "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable",
               "arn:aws:cassandra:us-east-1:111122223333:/keyspace/system*"
            ]
         }
      ]
   }
   ```

1. 確認用於連線至 Amazon Keyspaces 的 IAM 實體具有存取 Amazon EC2 執行個體上 VPC 端點資訊所需的讀取許可，如下列範例所示。

   ```
   {
      "Version":"2012-10-17",		 	 	 
      "Statement":[
         {
            "Sid":"ListVPCEndpoints",
            "Effect":"Allow",
            "Action":[
               "ec2:DescribeNetworkInterfaces",
               "ec2:DescribeVpcEndpoints"
            ],
            "Resource":"*"
         }
      ]
   }
   ```
**注意**  
受管政策`AmazonKeyspacesReadOnlyAccess_v2`並`AmazonKeyspacesFullAccess`包含必要許可，讓 Amazon Keyspaces 存取 Amazon EC2 執行個體，以讀取可用介面 VPC 端點的相關資訊。

   如需 VPC 端點的詳細資訊，請參閱 [使用 Amazon Keyspaces 的介面 VPC 端點](vpc-endpoints.md#using-interface-vpc-endpoints)

1. 確認 Java 驅動程式的 SSL 組態將主機名稱驗證設定為 false，如本範例所示。

   ```
   hostname-validation = false
   ```

   如需驅動程式組態的詳細資訊，請參閱 [步驟 2：設定驅動程式](using_java_driver.md#java_tutorial.driverconfiguration)。

1. 若要確認 VPC 端點已正確設定，您可以從 VPC *內*執行下列陳述式。
**注意**  
您無法使用本機開發人員環境或 Amazon Keyspaces CQL 編輯器來確認此組態，因為它們使用公有端點。

   ```
   SELECT peer FROM system.peers;
   ```

   輸出看起來應該類似此範例，並在從 IPv4 網路連線時傳回 2 到 6 個具有私有 IPv4 地址的節點，視您的 VPC 設定和 AWS 區域而定。

   ```
   peer
   ---------------
    192.0.2.0.15
    192.0.2.0.24
    192.0.2.0.13
    192.0.2.0.7
    192.0.2.0.8
   
   (5 rows)
   ```

#### 我無法使用 連線 `cassandra-stress`
<a name="troubleshooting.connection.cassandra-stress"></a>

**您嘗試使用 `cassandra-stress`命令連線至 Amazon Keyspaces，但收到`SSL context`錯誤。 **

如果您嘗試連線至 Amazon Keyspaces，但您未正確設定 trustStore，就會發生這種情況。Amazon Keyspaces 需要使用 Transport Layer Security (TLS) 來協助保護與用戶端的連線。

在此情況下，您會看到下列錯誤。

```
Error creating the initializing the SSL Context
```

若要解決此問題，請依照指示設定 trustStore，如本主題 所示[開始之前](using_java_driver.md#using_java_driver.BeforeYouBegin)。

設定 trustStore 後，您應該能夠使用下列命令進行連線。

```
./cassandra-stress user profile=./profile.yaml n=100 "ops(insert=1,select=1)" cl=LOCAL_QUORUM -node "cassandra.eu-north-1.amazonaws.com" -port native=9142 -transport ssl-alg="PKIX" truststore="./cassandra_truststore.jks" truststore-password="trustStore_pw" -mode native cql3 user="user_name" password="password"
```

#### 我無法使用 IAM 身分連線
<a name="troubleshooting.connection.IAM"></a>

**您嘗試使用 IAM 身分連線至 Amazon Keyspaces 資料表，但收到`Unauthorized`錯誤。 **

如果您嘗試使用 IAM 身分 （例如 IAM 使用者） 連線到 Amazon Keyspaces 資料表，但未實作政策並先提供使用者所需的許可，就會發生這種情況。

在此情況下，您會看到下列錯誤。

```
Connection error: ('Unable to connect to any servers', {'3.234.248.202': AuthenticationFailed('Failed to authenticate to 3.234.248.202: 
Error from server: code=2100 [Unauthorized] message="User arn:aws:iam::1234567890123:user/testuser has no permissions."',)})
```

若要解決此問題，請驗證 IAM 使用者的許可。若要與標準驅動程式連線，使用者必須至少`SELECT`存取系統資料表，因為大多數驅動程式會在建立連線時讀取系統金鑰空間/資料表。

如需授予 Amazon Keyspaces 系統和使用者資料表存取權的 IAM 政策範例，請參閱 [存取 Amazon Keyspaces 資料表](security_iam_id-based-policy-examples.md#security_iam_id-based-policy-examples-access-one-table)。

若要檢閱 IAM 特定的疑難排解區段，請參閱 [對 Amazon Keyspaces 身分和存取進行故障診斷](security_iam_troubleshoot.md)。

#### 我嘗試使用 cqlsh 匯入資料，且與 Amazon Keyspaces 資料表的連線遺失
<a name="troubleshooting.connection.import"></a>

**您嘗試使用 cqlsh 將資料上傳至 Amazon Keyspaces，但收到連線錯誤。**

cqlsh 用戶端從伺服器收到任何類型的連續三次錯誤後，與 Amazon Keyspaces 的連線會失敗。cqlsh 用戶端失敗，並顯示下列訊息。

```
Failed to import 1 rows: NoHostAvailable - , will retry later, attempt 3 of 100
```

若要解決此錯誤，您需要確定要匯入的資料符合 Amazon Keyspaces 中的資料表結構描述。檢閱匯入檔案是否有剖析錯誤。您可以使用 INSERT 陳述式來隔離錯誤，嘗試使用單一資料列。

用戶端會自動嘗試重新建立連線。