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 instance and ECS must be in the same region, VPC, and subnet.
- The ECS must be allowed by the security group associated with the instance.
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 a Security Group Rule for a GeminiDB DynamoDB-Compatible Instance.
Prerequisites
- A GeminiDB DynamoDB-Compatible instance has been created.
- An ECS has been created. For details about how to create an ECS, see Purchasing an ECS in the Elastic Cloud Server documentation.
- JDK has been installed on the ECS.
Obtaining the Connection Address of a GeminiDB DynamoDB-Compatible Instance
- Log in to the Huawei Cloud console.
- On the Instances page, click the target instance name. On the displayed Basic Information page, view the load balancer address.
If no load balancer address is available, submit a service ticket on the console to contact the customer service.
Figure 1 Viewing the IP address
Java Connection Code
Replace the IP address in the following code example with the load balancer address queried in 2.
Java code example:
public class ClientExample {
public static AWSCredentialsProvider myCredentials = new AWSStaticCredentialsProvider(new BasicAWSCredentials("rwuser", "your_pwd"));
public static void main(String[] args) {
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://ip", "cn-north-1"))
.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