Access an Amazon Neptune database from an Amazon EKS container
Created by Ramakrishnan Palaninathan (AWS)
Summary
This pattern establishes a connection between Amazon Neptune, which is a fully managed graph database, and Amazon Elastic Kubernetes Service (Amazon EKS), a container orchestration service, to access a Neptune database. Neptune DB clusters are confined within a virtual private cloud (VPC) on AWS. For this reason, accessing Neptune requires careful configuration of the VPC to enable connectivity.
Unlike Amazon Relational Database Service (Amazon RDS) for PostgreSQL, Neptune doesn't rely on typical database access credentials. Instead, it uses AWS Identity and Access Management (IAM) roles for authentication. Therefore, connecting to Neptune from Amazon EKS involves setting up an IAM role with the necessary permissions to access Neptune.
Furthermore, Neptune endpoints are accessible only within the VPC where the cluster resides. This means that you have to configure network settings to facilitate communication between Amazon EKS and Neptune. Depending on your specific requirements and networking preferences, there are various approaches to configuring the VPC to enable seamless connectivity between Neptune and Amazon EKS. Each method offers distinct advantages and considerations, which provide flexibility in designing your database architecture to suit your application's needs.
Prerequisites and limitations
Prerequisites
Install the latest version of kubectl (see instructions
). To check your version, run: kubectl version --short
Install the latest version of eksctl (see instructions
). To check your version, run: eksctl info
Install the latest version of the AWS Command Line Interface (AWS CLI) version 2 (see instructions). To check your version, run:
aws --version
Create a Neptune DB cluster (see instructions). Make sure to establish communications between the cluster's VPC and Amazon EKS through VPC peering, AWS Transit Gateway, or another method. Also make sure that the status of the cluster is “available” and that it has an inbound rule on port 8182 for the security group.
Configure an IAM OpenID Connect (OIDC) provider on an existing Amazon EKS cluster (see instructions).
Product versions
Architecture
The following diagram shows the connection between Kubernetes pods in an Amazon EKS cluster and Neptune to provide access to a Neptune database.

Automation and scale
You can use the Amazon EKS Horizontal Pod Autoscaler to scale this solution.
Tools
Services
Amazon Elastic Kubernetes Service (Amazon EKS) helps you run Kubernetes on AWS without needing to install or maintain your own Kubernetes control plane or nodes.
AWS Identity and Access Management (IAM) helps you securely manage access to your AWS resources by controlling who is authenticated and authorized to use them.
Amazon Neptune is a graph database service that helps you build and run applications that work with highly connected datasets.
Best practices
For best practices, see Identity and Access Management
Epics
Task | Description | Skills required |
---|---|---|
Verify the cluster context. | Before you interact with your Amazon EKS cluster by using Helm or other command-line tools, you must define environment variables that encapsulate your cluster's details. These variables are used in subsequent commands to ensure that they target the correct cluster and resources. First, confirm that you are operating within the correct cluster context. This ensures that any subsequent commands are sent to the intended Kubernetes cluster. To verify the current context, run the following command.
| AWS administrator, Cloud administrator |
Define the | Define the
| AWS administrator, Cloud administrator |
Validate output. | To validate that the variables have been set properly, run the following command.
Verify that the output of this command matches the input you specified in the previous step. | AWS administrator, Cloud administrator |
Task | Description | Skills required |
---|---|---|
Create a service account. | You use IAM roles for service accounts to map your Kubernetes service accounts to IAM roles, to enable fine-grained permissions management for your applications that run on Amazon EKS. You can use eksctl ImportantYou must have an OIDC endpoint associated with your cluster before you run these commands. Create a service account that you want to associate with an AWS managed policy named
where Upon completion, this command displays the following response:
| AWS administrator, Cloud administrator |
Verify that the account is set up properly. | Make sure that the
The output should look like this:
| AWS administrator, Cloud administrator |
Check connectivity. | Deploy a sample pod called
| AWS administrator, Cloud administrator |
Task | Description | Skills required |
---|---|---|
Enable IAM database authentication. | By default, IAM database authentication is disabled when you create a Neptune DB cluster. You can enable or disable IAM database authentication by using the AWS Management Console. Follow the steps in the AWS documentation to enable IAM database authentication in Neptune. | AWS administrator, Cloud administrator |
Verify connections. | In this step, you interact with the
| AWS administrator, Cloud administrator |
Troubleshooting
Issue | Solution |
---|---|
Can't access the Neptune database. | Review the IAM policy that's attached to the service account. Make sure that it allows the necessary actions (for example, |
Related resources
Grant Kubernetes workloads access to AWS using Kubernetes Service Accounts (Amazon EKS documentation)
IAM roles for service accounts (Amazon EKS documentation)
Creating a new Neptune DB cluster (Amazon Neptune documentation)