AWS CDK AWS Neptune (Alpha)

2.250.0a0 · active · verified Thu Apr 16

The `aws-cdk-aws-neptune-alpha` library is the AWS Cloud Development Kit (CDK) Construct Library for AWS Neptune. It provides higher-level constructs (L2 and L3) for provisioning Amazon Neptune database clusters and instances using Python. As an 'alpha' module, its APIs are experimental and subject to non-backward compatible changes or removal in future versions, not adhering to semantic versioning. It is actively developed and released frequently as part of the broader AWS CDK project, with the current version being 2.250.0a0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart deploys a basic AWS Neptune Database Cluster within a new VPC. It defines a `Vpc`, then instantiates `neptune.DatabaseCluster` with a specified instance type and engine version, and finally adds a security group rule to allow connections. The cluster's endpoint is exported as a CloudFormation output.

import aws_cdk as cdk
from aws_cdk import (Stack,
                     aws_ec2 as ec2,
                     aws_neptune_alpha as neptune)

class NeptuneStack(Stack):
    def __init__(self, scope: cdk.App, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Create a VPC for the Neptune cluster
        vpc = ec2.Vpc(self, "Vpc",
                      max_azs=2,  # Use 2 Availability Zones
                      nat_gateways=1)

        # Create a Neptune Database Cluster
        # Note: instanceType requires an 'alpha' prefix for some versions/runtimes
        cluster = neptune.DatabaseCluster(self, "NeptuneDatabase",
                                          vpc=vpc,
                                          instance_type=neptune.InstanceType.R5_LARGE,
                                          engine_version=neptune.EngineVersion.V1_2_0_0)

        # Add a default security group rule to allow connections
        cluster.connections.allow_default_port_from_any_ipv4("Allow connections from anywhere")

        # Output the cluster endpoint
        cdk.CfnOutput(self, "NeptuneClusterEndpoint",
                      value=cluster.cluster_endpoint.socket_address,
                      description="The endpoint address of the Neptune Cluster")

app = cdk.App()
NeptuneStack(app, "NeptuneAlphaQuickstartStack")
app.synth()

view raw JSON →