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.
Viewing the Load Balancer Address for Connecting to a GeminiDB DynamoDB-Compatible Instance
- Log in to the Huawei Cloud console.
- On the Instances page, click the target instance. On the displayed Basic Information page, view the load balancer address.
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 load balancer address queried in 2.
Java code example:
import com.amazonaws.SDKGlobalConfiguration;
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 V1Demo {
public static AWSCredentialsProvider myCredentials = new AWSStaticCredentialsProvider(new BasicAWSCredentials("your_ak", "your_sk"));
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.