-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
dynamodb_kinesis_lambda_oci_cratedb.py
file
- Loading branch information
1 parent
1b7be33
commit 2f02475
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
from lorrystream.carabas.aws import DynamoDBKinesisPipe, LambdaFactory, LambdaPythonImage | ||
from lorrystream.util.common import setup_logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def main(): | ||
""" | ||
A recipe to deploy a data relay stack to Amazon AWS. | ||
Pipeline: | ||
- DynamoDB CDC -> Kinesis Stream -> Python Lambda via OCI -> CrateDB | ||
Ingredients: | ||
- DynamoDB CDC to Kinesis | ||
- Lambda function, shipped per OCI image | ||
- CrateDB Cloud | ||
Prerequisites: Register an OCI repository. | ||
""" | ||
|
||
# Build and publish OCI image that includes the AWS Lambda function. | ||
python_image = LambdaPythonImage( | ||
name="cratedb-kinesis-lambda", | ||
entrypoint_file=Path("../../cratedb_toolkit/io/processor/kinesis_lambda.py"), | ||
entrypoint_handler="kinesis_lambda.handler", | ||
) | ||
python_image.publish() | ||
|
||
# Define an AWS CloudFormation software stack. | ||
stack = DynamoDBKinesisPipe( | ||
project="testdrive-dynamodb", | ||
stage="dev", | ||
region="eu-west-1", | ||
description="DynamoDB CDC -> Kinesis Stream -> Python Lambda via OCI -> CrateDB", | ||
table_name="table-testdrive", | ||
stream_name="dynamodb-cdc", | ||
environment={ | ||
"CRATEDB_SQLALCHEMY_URL": "crate://admin:dZ..qB@example.eks1.eu-west-1.aws.cratedb.net:4200/?ssl=true",, | ||
"CRATEDB_TABLE": "transactions", | ||
}, | ||
) | ||
|
||
# Add components to the stack. | ||
stack.table().processor( | ||
LambdaFactory( | ||
name="DynamoDBCrateDBProcessor", | ||
oci_uri=python_image.uri, | ||
handler=python_image.entrypoint_handler, | ||
) | ||
).connect() | ||
|
||
# Deploy stack. | ||
stack.deploy() | ||
logger.info(f"Deployed stack: {stack}") | ||
|
||
# Refresh the OCI image. | ||
# TODO: Detect when changed. | ||
stack.deploy_processor_image() | ||
|
||
|
||
if __name__ == "__main__": | ||
setup_logging() | ||
main() |