Skip to content

Commit

Permalink
Remove AppRegistry application
Browse files Browse the repository at this point in the history
Current implementation grouped resources of all environments under a single application.
I didn't find a way to filter and organize resources information per environment using that approach.
The reason I'd want to do such an organization is be able to view costs, metrics and so on per environment.
Removing this example until I find a better way to implement this.
  • Loading branch information
alexpulver committed Feb 15, 2025
1 parent 46377ee commit 6bd8e1c
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 151 deletions.
42 changes: 17 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
# User management backend
A CRUD API to manage users. Main components are the toolchain and the service. The application implements [Application Design Framework (ADF)](https://applicationdesignframework.com/) guidelines for organizing resources configuration and business logic code.

![diagram](https://github.com/alexpulver/usermanagement-backend/assets/4362270/774430b7-5315-44b0-9083-8d90d1a130a1)
![](architecture.png)
\* Diagram generated using https://github.com/pistazie/cdk-dia

## Create development environment
See [Getting Started With the AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html) for additional details and prerequisites.

## Clone the code
## Clone code
```bash
git clone https://github.com/alexpulver/usermanagement-backend
cd usermanagement-backend
```

## Fork the repository
## Fork repository
This is **optional** for deploying the service to sandbox environment, but **required** for deploying the toolchain.

```bash
git remote set-url origin <your fork URL>
```

## Configure local environment
## Configure development environment
```bash
python3.11 -m venv .venv
source .venv/bin/activate
Expand All @@ -31,8 +28,8 @@ source .venv/bin/activate
pip install pip-tools==6.4.0
pip install pip==21.3.1

toolchain/install-deps.sh
toolchain/run-tests.sh
toolchain/scripts/install-deps.sh
toolchain/scripts/run-tests.sh
```

## [Optional] Upgrade AWS CDK CLI version
Expand All @@ -43,9 +40,10 @@ The application uses Node Package Manager (npm) and `package.json` configuration
```bash
vi package.json # Update the "aws-cdk-lib" package version
```

```bash
toolchain/install-deps.sh
toolchain/run-tests.sh
toolchain/scripts/install-deps.sh
toolchain/scripts/run-tests.sh
```

## [Optional] Upgrade dependencies (ordered by constraints)
Expand All @@ -56,20 +54,15 @@ pip-compile --upgrade service/api/app/requirements.in
pip-compile --upgrade requirements.in
pip-compile --upgrade requirements-dev.in
```

```bash
toolchain/install-deps.sh
toolchain/run-tests.sh
toolchain/scripts/install-deps.sh
toolchain/scripts/run-tests.sh
```

## Deploy application stack
The application uses [AWS Service Catalog AppRegistry](https://docs.aws.amazon.com/servicecatalog/latest/arguide/intro-app-registry.html) to manage application metadata.

**Prerequisites**
- Update the account for `APPLICATION_PRODUCTION_ENVIRONMENT` constant in [constants.py](constants.py)
- Commit and push the changes: `git commit -a -m 'Environment configuration' && git push`

## [Optional] Cleanup unused packages
```bash
npx cdk deploy UserManagementBackend-Application-Production
pip-sync service/api/app/requirements.txt requirements.txt requirements-dev.txt
```

## Deploy service stack
Expand All @@ -91,15 +84,15 @@ UserManagementBackend-Service-Sandbox.APIEndpoint = https://bsc9goldsa.execute-a

**Prerequisites**
- Fork the repository, if you haven't done this already
- Create AWS CodeStar Connections [connection](https://docs.aws.amazon.com/dtconsole/latest/userguide/welcome-connections.html)
- Create AWS CodeConnections [connection](https://docs.aws.amazon.com/dtconsole/latest/userguide/welcome-connections.html)
for the deployment pipeline
- Authorize AWS CodeBuild access for the pull request build
- Start creating a new project manually
- Select GitHub as Source provider
- Choose **Connect using OAuth**
- Authorize access and cancel the project creation
- Update the `GITHUB_CONNECTION_ARN`, `GITHUB_OWNER`, `GITHUB_REPO`, `GITHUB_TRUNK_BRANCH`,
`TOOLCHAIN_PRODUCTION_ENVIRONMENT`, `SERVICE_SHARED_ENVIRONMENTS` constants in [constants.py](constants.py)
`TOOLCHAIN_PRODUCTION_ENVIRONMENT`, `SERVICE_PRODUCTION_ENVIRONMENT` constants in [constants.py](constants.py)
- Commit and push the changes: `git commit -a -m 'Source and environments configuration' && git push`

```bash
Expand All @@ -112,10 +105,9 @@ npx cdk deploy UserManagementBackend-Toolchain-Production
npx cdk destroy UserManagementBackend-Toolchain-Production
npx cdk destroy UserManagementBackend-Service-Production
npx cdk destroy UserManagementBackend-Service-Sandbox
npx cdk destroy UserManagementBackend-Application-Production
```

Delete the AWS CodeStar Connections connection if it is no longer needed. Follow the instructions
Delete the AWS CodeConnections connection if it is no longer needed. Follow the instructions
in [Delete a connection](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-delete.html).

## Testing
Expand Down
Binary file added architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 7 additions & 13 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class ServiceEnvironment(Environment):
privileged=True,
)

APPLICATION_STACK_BASE_NAME = f"{APP_NAME}-Application"
APPLICATION_PRODUCTION_ENVIRONMENT = Environment(
name="Production", account="807650736403", region="eu-west-1"
)
TOOLCHAIN_STACK_BASE_NAME = f"{APP_NAME}-Toolchain"
TOOLCHAIN_PRODUCTION_ENVIRONMENT = Environment(
name="Production", account="807650736403", region="eu-west-1"
Expand All @@ -49,12 +45,10 @@ class ServiceEnvironment(Environment):
compute_lambda_reserved_concurrency=1,
database_dynamodb_billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
)
SERVICE_SHARED_ENVIRONMENTS = [
ServiceEnvironment(
name="Production",
account="807650736403",
region="eu-west-1",
compute_lambda_reserved_concurrency=10,
database_dynamodb_billing_mode=dynamodb.BillingMode.PROVISIONED,
),
]
SERVICE_PRODUCTION_ENVIRONMENT = ServiceEnvironment(
name="Production",
account="807650736403",
region="eu-west-1",
compute_lambda_reserved_concurrency=10,
database_dynamodb_billing_mode=dynamodb.BillingMode.PROVISIONED,
)
16 changes: 0 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

import aws_cdk as cdk
import aws_cdk.aws_servicecatalogappregistry_alpha as appregistry_alpha

import constants
from service.service_stack import ServiceStack
Expand All @@ -11,20 +10,6 @@
def main() -> None:
app = cdk.App()

application = appregistry_alpha.TargetApplication.create_application_stack(
application_name=constants.APP_NAME,
application_description=constants.APP_DESCRIPTION,
# pylint: disable=line-too-long
stack_name=f"{constants.APPLICATION_STACK_BASE_NAME}-{constants.APPLICATION_PRODUCTION_ENVIRONMENT.name}",
env=cdk.Environment(
account=constants.APPLICATION_PRODUCTION_ENVIRONMENT.account,
region=constants.APPLICATION_PRODUCTION_ENVIRONMENT.region,
),
)
application_associator = appregistry_alpha.ApplicationAssociator(
app, "AppRegistryApplicationAssociator", applications=[application]
)

ServiceStack(
app,
f"{constants.SERVICE_STACK_BASE_NAME}-{constants.SERVICE_SANDBOX_ENVIRONMENT.name}",
Expand All @@ -41,7 +26,6 @@ def main() -> None:
ToolchainStack(
app,
f"{constants.TOOLCHAIN_STACK_BASE_NAME}-{constants.TOOLCHAIN_PRODUCTION_ENVIRONMENT.name}",
application_associator=application_associator,
env=cdk.Environment(
account=constants.TOOLCHAIN_PRODUCTION_ENVIRONMENT.account,
region=constants.TOOLCHAIN_PRODUCTION_ENVIRONMENT.region,
Expand Down
22 changes: 12 additions & 10 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ isort==6.0.0
# pylint
jinja2==3.1.5
# via safety
levenshtein==0.26.1
# via python-levenshtein
mando==0.7.1
# via radon
markdown-it-py==3.0.0
Expand Down Expand Up @@ -102,6 +104,8 @@ pygments==2.19.1
# via rich
pylint==3.3.4
# via -r requirements-dev.in
python-levenshtein==0.26.1
# via safety
pyyaml==6.0.2
# via
# bandit
Expand All @@ -110,26 +114,25 @@ radon==6.0.1
# via
# -r requirements-dev.in
# xenon
rapidfuzz==3.12.1
# via levenshtein
requests==2.32.3
# via
# safety
# xenon
rich==13.9.4
# via
# bandit
# safety
# typer
ruamel-yaml==0.18.10
# via safety-schemas
ruamel.yaml==0.18.10
# via safety
ruamel.yaml.clib==0.2.12
# via
# ruamel-yaml
# ruamel.yaml
safety==3.2.14
# safety
# safety-schemas
ruamel.yaml.clib==0.2.12
# via ruamel-yaml
safety==3.3.0
# via -r requirements-dev.in
safety_schemas==0.0.10
safety-schemas==0.0.10
# via safety
shellingham==1.5.4
# via typer
Expand Down Expand Up @@ -158,7 +161,6 @@ urllib3==2.3.0
# via
# -c service/api/app/requirements.txt
# requests
# safety
xenon==0.9.3
# via -r requirements-dev.in

Expand Down
1 change: 0 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
aws-cdk-lib
aws-cdk.aws-lambda-python-alpha
aws-cdk.aws-servicecatalogappregistry-alpha
constructs
7 changes: 0 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ aws-cdk-lib==2.178.2
# via
# -r requirements.in
# aws-cdk.aws-lambda-python-alpha
# aws-cdk.aws-servicecatalogappregistry-alpha
aws-cdk.asset-awscli-v1==2.2.223
# via aws-cdk-lib
aws-cdk.asset-kubectl-v20==2.1.4
Expand All @@ -21,8 +20,6 @@ aws-cdk.asset-node-proxy-agent-v6==2.1.0
# via aws-cdk-lib
aws-cdk.aws-lambda-python-alpha==2.178.2a0
# via -r requirements.in
aws-cdk.aws-servicecatalogappregistry-alpha==2.178.2a0
# via -r requirements.in
aws-cdk.cloud-assembly-schema==39.2.20
# via aws-cdk-lib
cattrs==24.1.2
Expand All @@ -32,7 +29,6 @@ constructs==10.4.2
# -r requirements.in
# aws-cdk-lib
# aws-cdk.aws-lambda-python-alpha
# aws-cdk.aws-servicecatalogappregistry-alpha
importlib-resources==6.5.2
# via jsii
jsii==1.106.0
Expand All @@ -42,7 +38,6 @@ jsii==1.106.0
# aws-cdk.asset-kubectl-v20
# aws-cdk.asset-node-proxy-agent-v6
# aws-cdk.aws-lambda-python-alpha
# aws-cdk.aws-servicecatalogappregistry-alpha
# aws-cdk.cloud-assembly-schema
# constructs
publication==0.0.3
Expand All @@ -52,7 +47,6 @@ publication==0.0.3
# aws-cdk.asset-kubectl-v20
# aws-cdk.asset-node-proxy-agent-v6
# aws-cdk.aws-lambda-python-alpha
# aws-cdk.aws-servicecatalogappregistry-alpha
# aws-cdk.cloud-assembly-schema
# constructs
# jsii
Expand All @@ -67,7 +61,6 @@ typeguard==2.13.3
# aws-cdk.asset-kubectl-v20
# aws-cdk.asset-node-proxy-agent-v6
# aws-cdk.aws-lambda-python-alpha
# aws-cdk.aws-servicecatalogappregistry-alpha
# aws-cdk.cloud-assembly-schema
# constructs
# jsii
Expand Down
8 changes: 4 additions & 4 deletions service/api/app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#
aws-lambda-powertools==3.6.0
# via -r service/api/app/requirements.in
boto3==1.36.19
boto3==1.36.21
# via -r service/api/app/requirements.in
boto3-stubs==1.36.19
boto3-stubs==1.36.21
# via -r service/api/app/requirements.in
botocore==1.36.19
botocore==1.36.21
# via
# boto3
# s3transfer
botocore-stubs==1.36.18
botocore-stubs==1.36.21
# via boto3-stubs
jmespath==1.0.1
# via
Expand Down
39 changes: 0 additions & 39 deletions service/metadata.py

This file was deleted.

2 changes: 0 additions & 2 deletions service/service_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from service.api.compute import Compute
from service.database import Database
from service.ingress import Ingress
from service.metadata import Metadata
from service.monitoring import Monitoring


Expand Down Expand Up @@ -35,7 +34,6 @@ def __init__(
dynamodb_table_name=database.dynamodb_table.table_name,
)
ingress = Ingress(self, "Ingress", lambda_function=compute.lambda_function)
Metadata(self, "Metadata", compute=compute, network=ingress)
Monitoring(self, "Monitoring", database=database, network=ingress)

database.dynamodb_table.grant_read_write_data(compute.lambda_function)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6bd8e1c

Please sign in to comment.