Connecting to a GeminiDB DynamoDB-Compatible Instance Using Java
This section describes how to connect to a GeminiDB DynamoDB-Compatible instance using Java.
Usage Notes
- The target instance and ECS must be in the same VPC and subnet.
- The instance security group must allow access from the ECS.
Scenario 1: If the instance is associated with the default security group, you do not need to set security group rules.
Scenario 2: If the instance is not associated with the default security group, check whether the security group rules allow access from the ECS.
- If yes, the ECS can connect to the instance.
- If no, add an inbound rule to the security group.
For details, see Setting Security Group Rules for a GeminiDB DynamoDB-Compatible Instance.
Prerequisites
- A GeminiDB DynamoDB-Compatible instance has been created.
- For details about how to create an ECS, see Purchasing an ECS in Getting Started with Elastic Cloud Server.
- JDK has been installed on the ECS.
Obtaining the IP Address of a GeminiDB DynamoDB-Compatible Instance
- Log in to the Huawei Cloud console.
- In the service list, choose Databases > GeminiDB.
- On the Instances page, click the instance name. On the displayed Basic Information page, view IP addresses of the load balancer and each node.
If no load balancer address is available, choose Service Tickets > Create Service Ticket in the upper right corner of the console and contact the customer service.
Figure 1 Viewing the IP address
Replace the IP address in the following code example with the IP address queried in 3.
Java code example:
package com.huawei.dbs.test; import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.TableCollection; public class ListTableCase { public static AWSCredentialsProvider myCredentials = new AWSStaticCredentialsProvider( new BasicAWSCredentials("your_ak", "your_sk")); public static String ip = "***.***.***.***"; public static void main(String[] args) { AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard() .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://" + ip , "region-01")) .withCredentials(myCredentials) .build(); DynamoDB dynamoDB = new DynamoDB(client); TableCollection res = dynamoDB.listTables(); System.out.println(res); } }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot