Amazon Neptune Analytics¶
Amazon Neptune Analytics is a memory-optimized graph database engine for analytics. With Neptune Analytics, you can get insights and find trends by processing large amounts of graph data in seconds.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Create necessary resources using AWS Console or AWS CLI.
Install API libraries via pip.
pip install 'apache-airflow[amazon]'Detailed information is available Installation of Airflow®
Generic Parameters¶
- aws_conn_id
Reference to Amazon Web Services Connection ID. If this parameter is set to
Nonethen the default boto3 behaviour is used without a connection lookup. Otherwise use the credentials stored in the Connection. Default:aws_default- region_name
AWS Region Name. If this parameter is set to
Noneor omitted then region_name from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default:None- verify
Whether or not to verify SSL certificates.
False- Do not validate SSL certificates.path/to/cert/bundle.pem - A filename of the CA cert bundle to use. You can specify this argument if you want to use a different CA cert bundle than the one used by botocore.
If this parameter is set to
Noneor is omitted then verify from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default:None- botocore_config
The provided dictionary is used to construct a botocore.config.Config. This configuration can be used to configure Avoid Throttling exceptions, timeouts, etc.
Example, for more detail about parameters please have a look botocore.config.Config¶{ "signature_version": "unsigned", "s3": { "us_east_1_regional_endpoint": True, }, "retries": { "mode": "standard", "max_attempts": 10, }, "connect_timeout": 300, "read_timeout": 300, "tcp_keepalive": True, }
If this parameter is set to
Noneor omitted then config_kwargs from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default:NoneNote
Specifying an empty dictionary,
{}, will overwrite the connection configuration for botocore.config.Config
Operators¶
Create a new Neptune Graph¶
To create a new Neptune Analytics Graph, you can use
NeptuneCreateGraphOperator.
This operator can be run in deferrable mode by passing deferrable=True as a parameter. This requires
the aiobotocore module to be installed.
create_graph = NeptuneCreateGraphOperator(
task_id="create_graph",
graph_name=graph_name,
vector_search_config={"dimension": 128},
provisioned_memory=32,
public_connectivity=True,
replica_count=0,
deletion_protection=False,
wait_for_completion=True,
deferrable=False,
waiter_delay=30,
waiter_max_attempts=60,
)
Delete a Neptune Graph¶
To delete an existing Neptune Analytics Graph, you can use
NeptuneDeleteGraphOperator.
This operator can be run in deferrable mode by passing deferrable=True as a parameter. This requires
the aiobotocore module to be installed.
delete_graph = NeptuneDeleteGraphOperator(
task_id="delete_graph",
graph_id="{{ ti.xcom_pull(task_ids='create_graph')['graph_id'] }}",
skip_snapshot=True,
wait_for_completion=True,
deferrable=False,
waiter_delay=30,
waiter_max_attempts=60,
)
Create a Neptune Graph private endpoint¶
To create a VPC Endpoint for connecting to an existing Neptune Graph, you can use
NeptuneCreatePrivateGraphEndpointOperator.
This operator can be run in deferrable mode by passing deferrable=True as a parameter. This requires
the aiobotocore module to be installed.
create_endpoint = NeptuneCreatePrivateGraphEndpointOperator(
task_id="create_endpoint",
graph_identifier="{{ ti.xcom_pull(task_ids='create_graph')['graph_id']}}",
wait_for_completion=True,
)
Delete a Neptune Graph private endpoint¶
To delete a VPC Endpoint attached to an existing Neptune Graph, you can use
NeptuneDeletePrivateGraphEndpointOperator.
This operator can be run in deferrable mode by passing deferrable=True as a parameter. This requires
the aiobotocore module to be installed.
delete_endpoint = NeptuneDeletePrivateGraphEndpointOperator(
task_id="delete_endpoint",
graph_identifier="{{ ti.xcom_pull(task_ids='create_graph')['graph_id'] }}",
vpc_id="{{ ti.xcom_pull(task_ids='create_endpoint')['vpc_id'] }}",
wait_for_completion=True,
deferrable=False,
waiter_delay=30,
waiter_max_attempts=60,
)
Create a Neptune Graph with a data import task¶
To create a Neptune Analytics Graph and immediately import data, you can use
NeptuneCreateGraphWithImportOperator.
This operator can be run in deferrable mode by passing deferrable=True as a parameter. This requires
the aiobotocore module to be installed.
create_graph_with_import = NeptuneCreateGraphWithImportOperator(
task_id="create_graph_with_import",
graph_name=import_graph_name,
vector_search_config={"dimension": 128},
source=f"s3://{bucket_name}/data/",
role_arn=create_role,
format="CSV",
fail_on_error=True,
public_connectivity=True,
replica_count=0,
deletion_protection=False,
min_provisioned_memory=32,
max_provisioned_memory=32,
wait_for_completion=True,
deferrable=False,
waiter_delay=30,
waiter_max_attempts=60,
)
Import data into an existing Neptune Graph¶
To import data into an existing Neptune Analytics Graph, you can use
NeptuneStartImportTaskOperator.
This operator can be run in deferrable mode by passing deferrable=True as a parameter. This requires
the aiobotocore module to be installed.
start_import = NeptuneStartImportTaskOperator(
task_id="start_import",
graph_identifier="{{ ti.xcom_pull(task_ids='create_graph')['graph_id'] }}",
role_arn=create_role,
source=f"s3://{bucket_name}/data/",
format="CSV",
fail_on_error=True,
wait_for_completion=False,
deferrable=False,
waiter_delay=30,
waiter_max_attempts=60,
)
Cancel a running import task¶
To cancel an existing import task, you can use
NeptuneCancelImportTaskOperator.
This operator can be run in deferrable mode by passing deferrable=True as a parameter. This requires
the aiobotocore module to be installed.
cancel_import = NeptuneCancelImportTaskOperator(
task_id="cancel_import",
import_task_id="{{ ti.xcom_pull(task_ids='start_import')['import_task_id']}}",
wait_for_completion=True,
aws_conn_id="aws_default",
)