From ded441b2e181cd8216619581ef70178d7bb418ca Mon Sep 17 00:00:00 2001 From: Simon Planzer Date: Sat, 26 Sep 2020 21:02:54 +1200 Subject: [PATCH] feat(infra): intialise CDK project closes #4 --- README.md | 62 ++++++++++++++++++++++++++-- infra/app.py | 22 ++++++++++ infra/cdk.json | 8 ++++ infra/data_stores/__init__.py | 0 infra/data_stores/data_lake_stack.py | 8 ++++ requirements-infra.txt | 3 ++ 6 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 infra/app.py create mode 100644 infra/cdk.json create mode 100644 infra/data_stores/__init__.py create mode 100644 infra/data_stores/data_lake_stack.py create mode 100644 requirements-infra.txt diff --git a/README.md b/README.md index f388cd6a8..46835c41b 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,9 @@ Central storage, management and access for important geospatial datasets Developed by [Land Information New Zealand](https://github.com/linz) -## Installation -* Create and activate a virtual environment. +# Dependencies Installation +## Python Virtual Environment (for Python CLI and AWS CDK) +* Create and activate a Python virtual environment ```bash $ python3 -m venv .venv @@ -17,6 +18,41 @@ $ source .venv/bin/activate ```bash $ pip install --upgrade pip +``` + + +## AWS CDK Environment (AWS Infrastructure) +* Install NVM (use latest version) + +```bash +$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v/install.sh | bash +``` + +* Enable NVM + +```bash +$ export NVM_DIR="$HOME/.nvm" +$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +$ [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +``` + +* Install latest LTS Node version + +```bash +$ nvm install --lts +``` + +* Install latest AWS CDK version + +```bash +$ npm install -g aws-cdk +``` + + +## Python CLI Installation +* Install Python dependencies + +```bash $ pip install -r requirements.txt ``` @@ -27,8 +63,28 @@ $ python ./setup.py install ``` +## AWS Infrastructure Deployment (CDK Stack) +* Install Python CDK dependencies + +```bash +$ pip install -r requirements-infra.txt +``` + +* Get AWS credentials (see: https://www.npmjs.com/package/aws-azure-login) + +```bash +$ aws-azure-login -p +``` + +* Deploy CDK stack + +```bash +$ cdk deploy --profile +``` + + ## Development -* Install development dependencies +* Install Python development dependencies ```bash $ pip install -r requirements-dev.txt diff --git a/infra/app.py b/infra/app.py new file mode 100644 index 000000000..45a1e8710 --- /dev/null +++ b/infra/app.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +from aws_cdk import core +from data_stores.data_lake_stack import DataLakeStack + +app = core.App() + +DataLakeStack( + app, + "data-lake-nonprod", + stack_name="geospatial-data-lake-nonprod", + env={"region": "ap-southeast-2", "account": "632223577832"}, +) + +DataLakeStack( + app, + "data-lake-prod", + stack_name="geospatial-data-lake-prod", + env={"region": "ap-southeast-2", "account": "715898075157"}, +) + +app.synth() diff --git a/infra/cdk.json b/infra/cdk.json new file mode 100644 index 000000000..cd2273a59 --- /dev/null +++ b/infra/cdk.json @@ -0,0 +1,8 @@ +{ + "app": "python3 app.py", + "context": { + "@aws-cdk/core:enableStackNameDuplicates": "true", + "aws-cdk:enableDiffNoFail": "true", + "@aws-cdk/core:stackRelativeExports": "true" + } +} diff --git a/infra/data_stores/__init__.py b/infra/data_stores/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/infra/data_stores/data_lake_stack.py b/infra/data_stores/data_lake_stack.py new file mode 100644 index 000000000..4fa781e3e --- /dev/null +++ b/infra/data_stores/data_lake_stack.py @@ -0,0 +1,8 @@ +from aws_cdk import core + + +class DataLakeStack(core.Stack): + def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: + super().__init__(scope, id, **kwargs) + + # The code that defines your stack goes here diff --git a/requirements-infra.txt b/requirements-infra.txt new file mode 100644 index 000000000..1b0ab8afd --- /dev/null +++ b/requirements-infra.txt @@ -0,0 +1,3 @@ +aws-cdk.aws-s3 +aws-cdk.aws-iam +awscli