Connecting to a GeminiDB DynamoDB-Compatible Instance Using Python
This section describes how to connect to a GeminiDB DynamoDB-Compatible instance using Python.
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.
- Python has been installed on an 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.
Python code example:
#!/usr/bin/python
import boto3
url = 'http://ip'
dynamodb = boto3.resource('dynamodb',
endpoint_url=url,
aws_access_key_id='ak',
aws_secret_access_key='sk',
region_name="region-a")
GeminiDB DynamoDB-Compatible API is completely compatible with DynamoDB. For details about common operations, see official DynamoDB documents.