Weitere AWS SDK-Beispiele sind im Repo AWS Doc SDK Examples
Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.
Mit CreateDBSubnetGroup
einem SDK verwenden AWS
Die folgenden Code-Beispiele zeigen, wie CreateDBSubnetGroup
verwendet wird.
- Java
-
- SDK für Java 2.x
-
Anmerkung
Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-
einrichten und ausführen. /** * Creates a new DB subnet group asynchronously. * * @param groupName the name of the subnet group to create * @return a CompletableFuture that, when completed, returns the Amazon Resource Name (ARN) of the created subnet group * @throws CompletionException if the operation fails, with a cause that may be a ServiceQuotaExceededException if the request would exceed the maximum quota */ public CompletableFuture<String> createSubnetGroupAsync(String groupName) { // Get the Amazon Virtual Private Cloud (VPC) where the Neptune cluster and resources will be created String vpcId = getDefaultVpcId(); logger.info("VPC is : " + vpcId); List<String> subnetList = getSubnetIds(vpcId); for (String subnetId : subnetList) { System.out.println("Subnet group:" +subnetId); } CreateDbSubnetGroupRequest request = CreateDbSubnetGroupRequest.builder() .dbSubnetGroupName(groupName) .dbSubnetGroupDescription("Subnet group for Neptune cluster") .subnetIds(subnetList) .build(); return getAsyncClient().createDBSubnetGroup(request) .whenComplete((response, exception) -> { if (exception != null) { Throwable cause = exception.getCause(); if (cause instanceof ServiceQuotaExceededException) { throw new CompletionException("The operation was denied because the request would exceed the maximum quota.", cause); } throw new CompletionException("Failed to create subnet group: " + exception.getMessage(), exception); } }) .thenApply(response -> { String name = response.dbSubnetGroup().dbSubnetGroupName(); String arn = response.dbSubnetGroup().dbSubnetGroupArn(); logger.info("Subnet group created: " + name); return arn; }); }
-
Einzelheiten zur API finden Sie unter DBSubnetGruppe erstellen in der AWS SDK for Java 2.x API-Referenz.
-
- Python
-
- SDK für Python (Boto3)
-
Anmerkung
Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-
einrichten und ausführen. def create_subnet_group(neptune_client, group_name: str): """ Creates a Neptune DB subnet group and returns its name and ARN. Args: neptune_client (boto3.client): The Neptune client object. group_name (str): The desired name of the subnet group. Returns: tuple(str, str): (subnet_group_name, subnet_group_arn) Raises: RuntimeError: For quota errors or other AWS-related failures. """ vpc_id = get_default_vpc_id() subnet_ids = get_subnet_ids(vpc_id) request = { 'DBSubnetGroupName': group_name, 'DBSubnetGroupDescription': 'My Neptune subnet group', 'SubnetIds': subnet_ids, 'Tags': [{'Key': 'Environment', 'Value': 'Dev'}] } try: response = neptune_client.create_db_subnet_group(**request) sg = response.get("DBSubnetGroup", {}) name = sg.get("DBSubnetGroupName") arn = sg.get("DBSubnetGroupArn") if not name or not arn: raise RuntimeError("Response missing subnet group name or ARN.") print(f"Subnet group created: {name}") print(f"ARN: {arn}") return name, arn except ClientError as e: code = e.response["Error"]["Code"] msg = e.response["Error"]["Message"] if code == "ServiceQuotaExceededException": print("Subnet group quota exceeded.") raise RuntimeError("Subnet group quota exceeded.") from e else: print(f"AWS error [{code}]: {msg}") raise RuntimeError(f"AWS error [{code}]: {msg}") from e except Exception as e: print(f"Unexpected error creating subnet group '{group_name}': {e}") raise RuntimeError(f"Unexpected error creating subnet group '{group_name}': {e}") from e
-
API-Einzelheiten finden Sie unter Create DBSubnet Group in AWS SDK for Python (Boto3) API-Referenz.
-