diff --git a/awscdk/.env_example b/awscdk/.env_example new file mode 100644 index 00000000..0d61aab6 --- /dev/null +++ b/awscdk/.env_example @@ -0,0 +1,4 @@ +default_region=us-east-1 +default_account= +aws_access_key_id= +aws_secret_access_key= \ No newline at end of file diff --git a/awscdk/.gitignore b/awscdk/.gitignore new file mode 100644 index 00000000..cf092ef1 --- /dev/null +++ b/awscdk/.gitignore @@ -0,0 +1,20 @@ +dist/ +*.pyo +*.pyc +creds/* +imports/* +*.egg-info/ +!imports/__init__.py +.venv +.env +*/test.py +cdk.out +*.ini* +*.pem +.DS_Store + +# Ignore debug +*.bak + +# Ignore files used to drive AI implementation +AI \ No newline at end of file diff --git a/awscdk/README_docker_compose.md b/awscdk/README_docker_compose.md new file mode 100644 index 00000000..3e3b5690 --- /dev/null +++ b/awscdk/README_docker_compose.md @@ -0,0 +1,51 @@ +# Bento cdk project: Bento AWS + +## Prerequisites + +This project was built based on the python implementation detailed at: +- https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html + +The project can be built using the included docker-compose file to install prerequisites or they can be installed locally. + + +### Using docker-compose + +Once the repo has been cloned a dev container can be started from the cdk/awscdk folder using the following command: + +```bash +docker-compose run aws-cdk sh +docker compose run aws-cdk sh +``` + +This will start a container with all required applications installed and map the awscdk/bento folder as its workspace. + + +## Initialize the bento cdk project + +In order to build the bento cdk files you will need to get the required python modules (this command should be run in the bento folder): + +```bash +pip3 install --ignore-installed --break-system-packages -r requirements.txt +``` + + +## Configure the config.ini file + +The CDK script get configuration settings from a config.ini file, in order to properly run this project you will need to create this file with the proper values populated. This file can be created by copying the included config.ini.template file and adding in values for any missing information. + + +## Build Cloudformation scripts for the bento cdk project + +After modules are installed you can run cdk commands on your stack: + +```bash +cdk synth +cdk bootstrap +cdk deploy +cdk diff +cdk destroy +``` + +To skip approval step: --require-approval never + +* Note: an appropriate tier must be specified in bento.properties in order to build the bento scripts - if valid tiers are created or removed for this project getArgs.py must be updated to reflect these changes \ No newline at end of file diff --git a/awscdk/docker-compose.yml b/awscdk/docker-compose.yml new file mode 100644 index 00000000..48882308 --- /dev/null +++ b/awscdk/docker-compose.yml @@ -0,0 +1,15 @@ +#version: '3.4' +services: + aws-cdk: + container_name: aws-cdk + build: + context: . + dockerfile: ./dockerfiles/cdk_python + environment: + - AWS_ACCESS_KEY_ID=${aws_access_key_id} + - AWS_SECRET_ACCESS_KEY=${aws_secret_access_key} + - AWS_SESSION_TOKEN=${aws_session_token} + - AWS_DEFAULT_REGION=${default_region} + - AWS_DEFAULT_ACCOUNT=${default_account} + volumes: + - ./:/app \ No newline at end of file diff --git a/awscdk/dockerfiles/cdk_python b/awscdk/dockerfiles/cdk_python new file mode 100644 index 00000000..ecc9d017 --- /dev/null +++ b/awscdk/dockerfiles/cdk_python @@ -0,0 +1,14 @@ +FROM node:20.17.0-alpine3.20 +#FROM node:20.15.1-alpine3.20 + +# Update to the latest npm +RUN npm install npm@latest -g +#RUN npm install -g npm@10.7.0 + +# add python and pip +RUN apk add --no-cache python3 py3-pip + +# install aws-cdk and set its log level to debug +RUN npm install -g aws-cdk@2.155.0 + +WORKDIR /app \ No newline at end of file diff --git a/awscdk/phoenix/.gitignore b/awscdk/phoenix/.gitignore new file mode 100644 index 00000000..619b350d --- /dev/null +++ b/awscdk/phoenix/.gitignore @@ -0,0 +1,11 @@ +*.swp +package-lock.json +__pycache__ +.pytest_cache +.venv +.env +*.egg-info + +# CDK asset staging directory +.cdk.staging +cdk.out diff --git a/awscdk/phoenix/README.md b/awscdk/phoenix/README.md new file mode 100644 index 00000000..c53f0b50 --- /dev/null +++ b/awscdk/phoenix/README.md @@ -0,0 +1,58 @@ + +# Welcome to your CDK Python project! + +This is a blank project for CDK development with Python. + +The `cdk.json` file tells the CDK Toolkit how to execute your app. + +This project is set up like a standard Python project. The initialization +process also creates a virtualenv within this project, stored under the `.venv` +directory. To create the virtualenv it assumes that there is a `python3` +(or `python` for Windows) executable in your path with access to the `venv` +package. If for any reason the automatic creation of the virtualenv fails, +you can create the virtualenv manually. + +To manually create a virtualenv on MacOS and Linux: + +``` +$ python3 -m venv .venv +``` + +After the init process completes and the virtualenv is created, you can use the following +step to activate your virtualenv. + +``` +$ source .venv/bin/activate +``` + +If you are a Windows platform, you would activate the virtualenv like this: + +``` +% .venv\Scripts\activate.bat +``` + +Once the virtualenv is activated, you can install the required dependencies. + +``` +$ pip install -r requirements.txt +``` + +At this point you can now synthesize the CloudFormation template for this code. + +``` +$ cdk synth +``` + +To add additional dependencies, for example other CDK libraries, just add +them to your `setup.py` file and rerun the `pip install -r requirements.txt` +command. + +## Useful commands + + * `cdk ls` list all stacks in the app + * `cdk synth` emits the synthesized CloudFormation template + * `cdk deploy` deploy this stack to your default AWS account/region + * `cdk diff` compare deployed stack with current state + * `cdk docs` open CDK documentation + +Enjoy! diff --git a/awscdk/phoenix/README_docker_compose.md b/awscdk/phoenix/README_docker_compose.md new file mode 100644 index 00000000..3e3b5690 --- /dev/null +++ b/awscdk/phoenix/README_docker_compose.md @@ -0,0 +1,51 @@ +# Bento cdk project: Bento AWS + +## Prerequisites + +This project was built based on the python implementation detailed at: +- https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html + +The project can be built using the included docker-compose file to install prerequisites or they can be installed locally. + + +### Using docker-compose + +Once the repo has been cloned a dev container can be started from the cdk/awscdk folder using the following command: + +```bash +docker-compose run aws-cdk sh +docker compose run aws-cdk sh +``` + +This will start a container with all required applications installed and map the awscdk/bento folder as its workspace. + + +## Initialize the bento cdk project + +In order to build the bento cdk files you will need to get the required python modules (this command should be run in the bento folder): + +```bash +pip3 install --ignore-installed --break-system-packages -r requirements.txt +``` + + +## Configure the config.ini file + +The CDK script get configuration settings from a config.ini file, in order to properly run this project you will need to create this file with the proper values populated. This file can be created by copying the included config.ini.template file and adding in values for any missing information. + + +## Build Cloudformation scripts for the bento cdk project + +After modules are installed you can run cdk commands on your stack: + +```bash +cdk synth +cdk bootstrap +cdk deploy +cdk diff +cdk destroy +``` + +To skip approval step: --require-approval never + +* Note: an appropriate tier must be specified in bento.properties in order to build the bento scripts - if valid tiers are created or removed for this project getArgs.py must be updated to reflect these changes \ No newline at end of file diff --git a/awscdk/phoenix/app.py b/awscdk/phoenix/app.py new file mode 100644 index 00000000..66b37778 --- /dev/null +++ b/awscdk/phoenix/app.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +import os, sys +import logging +import aws_cdk as cdk + +from configparser import ConfigParser, ExtendedInterpolation +from aws_cdk import aws_iam as iam + +from app.stack import Stack +from app.aspects import MyAspect + +# Read config +config = ConfigParser(interpolation=ExtendedInterpolation()) +config.read("config.ini") + +if __name__=="__main__": + logging.basicConfig(format='%(asctime)s [%(levelname)5s] %(message)s', + datefmt='%Y-%m-%dT%H:%M:%S', + level=logging.NOTSET) + + if config.has_option('iam', 'role_prefix'): + synthesizer = cdk.DefaultStackSynthesizer( + # ARN of the role assumed by the CLI and Pipeline to deploy here + deploy_role_arn="arn:${AWS::Partition}:iam::${AWS::AccountId}:role/" + config['iam']['role_prefix'] + "-cdk-${Qualifier}-deploy-role-${AWS::Region}", + + # ARN of the role used for file asset publishing (assumed from the CLI role) + file_asset_publishing_role_arn="arn:${AWS::Partition}:iam::${AWS::AccountId}:role/" + config['iam']['role_prefix'] + "-cdk-${Qualifier}-file-publishing-role-${AWS::Region}", + + # ARN of the role used for Docker asset publishing (assumed from the CLI role) + image_asset_publishing_role_arn="arn:${AWS::Partition}:iam::${AWS::AccountId}:role/" + config['iam']['role_prefix'] + "-cdk-${Qualifier}-image-publishing-role-${AWS::Region}", + + # ARN of the role passed to CloudFormation to execute the deployments + cloud_formation_execution_role="arn:${AWS::Partition}:iam::${AWS::AccountId}:role/" + config['iam']['role_prefix'] + "-cdk-${Qualifier}-cfn-exec-role-${AWS::Region}", + + # ARN of the role used to look up context information in an environment + lookup_role_arn="arn:${AWS::Partition}:iam::${AWS::AccountId}:role/" + config['iam']['role_prefix'] + "-cdk-${Qualifier}-lookup-role-${AWS::Region}", + ) + else: + synthesizer = cdk.DefaultStackSynthesizer() + + app = cdk.App() + + stack_name="{}-{}".format(config['main']['resource_prefix'], config['main']['tier']) + stack = Stack( + app, + stack_name, + synthesizer=synthesizer, + env=cdk.Environment( + account=config['main']['account_id'], + region=config['main']['region'] + ), + ) + + # Rename all roles to add role prefix + cdk.Aspects.of(stack).add(MyAspect()) + + # set permission boundary on all roles + if config.has_option('iam', 'permission_boundary'): + boundary = iam.ManagedPolicy.from_managed_policy_arn(stack, "Boundary", config['iam']['permission_boundary']) + iam.PermissionsBoundary.of(stack).apply(boundary) + + config_tags = dict(s.split(':') for s in config['main']['tags'].split(",")) + env_tags = {'Environment': config['main']['tier']} + tags = config_tags | env_tags + + + for tag,value in tags.items(): + cdk.Tags.of(stack).add(tag, value) + + app.synth() diff --git a/awscdk/phoenix/app/__init__.py b/awscdk/phoenix/app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/awscdk/phoenix/app/aspects.py b/awscdk/phoenix/app/aspects.py new file mode 100644 index 00000000..808bd679 --- /dev/null +++ b/awscdk/phoenix/app/aspects.py @@ -0,0 +1,20 @@ +import aws_cdk as cdk +import jsii +from constructs import Construct, IConstruct +from configparser import ConfigParser, ExtendedInterpolation +from aws_cdk import aws_iam as iam + +# Read config +config = ConfigParser(interpolation=ExtendedInterpolation()) +config.read("config.ini") + +@jsii.implements(cdk.IAspect) +class MyAspect: + def visit(self, node): + + if isinstance(node, iam.CfnRole): + if config.has_option('iam', 'role_prefix'): + resolvedLogicalId = cdk.Stack.of(node).resolve(node.logical_id) + roleName = config['iam']['role_prefix'] + '-' + resolvedLogicalId + roleName = roleName[:64] # Ensure the role name is within the 64 character limit + node.role_name = roleName diff --git a/awscdk/phoenix/app/stack.py b/awscdk/phoenix/app/stack.py new file mode 100644 index 00000000..8f17a816 --- /dev/null +++ b/awscdk/phoenix/app/stack.py @@ -0,0 +1,211 @@ +from configparser import ConfigParser, ExtendedInterpolation +from constructs import Construct +from aws_cdk import Stack, Duration, RemovalPolicy +from aws_cdk import aws_ec2 as ec2 +from aws_cdk import aws_ecs as ecs +from aws_cdk import aws_kms as kms +# from aws_cdk import aws_iam as iam +from aws_cdk import aws_rds as rds +from aws_cdk import aws_elasticloadbalancingv2 as elbv2 +from aws_cdk import aws_certificatemanager as cfm +from aws_cdk import aws_s3 as s3 +from aws_cdk import aws_secretsmanager as secretsmanager +from aws_cdk import SecretValue + +# from services import memgraph + +# Read config +config = ConfigParser(interpolation=ExtendedInterpolation()) +config.read("config.ini") + +class Stack(Stack): + def __init__(self, scope: Construct, id: str, **kwargs) -> None: + super().__init__(scope, id, **kwargs) + + self.namingPrefix = "{}-{}".format(config['main']['resource_prefix'], config['main']['tier']) + + # Import VPC + self.VPC = ec2.Vpc.from_lookup( + self, + "VPC", + vpc_id=config["main"]["vpc_id"] + ) + + # Phoenix Service + service = "phoenix" + + ### Secrets + self.secret = secretsmanager.Secret( + self, + "Secret", + secret_name=f"{config['main']['program']}/{config['main']['project']}/{config['main']['tier']}", + secret_object_value={ + "phoenix_secret": SecretValue.unsafe_plain_text(config[service]['phoenix_secret']), + "phoenix_admin_password": SecretValue.unsafe_plain_text(config[service]['phoenix_admin_password']), + "username": SecretValue.unsafe_plain_text(config['db']['db_user']), + "password": SecretValue.unsafe_plain_text(config['db']['db_pass']), + "dbname": SecretValue.unsafe_plain_text(config['db']['db_name']), + } + ) + + # RDS + self.postgres = rds.DatabaseInstance(self, "Postgres", + engine=rds.DatabaseInstanceEngine.postgres( + version=rds.PostgresEngineVersion.VER_16 + ), + vpc=self.VPC, + vpc_subnets=ec2.SubnetSelection( + subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS + ), + instance_type=ec2.InstanceType.of( + ec2.InstanceClass.BURSTABLE3, + ec2.InstanceSize.MICRO, + ), + # credentials=rds.Credentials.from_generated_secret("postgres"), + credentials=rds.Credentials.from_secret(self.secret), + database_name=config["db"]["db_name"], + allocated_storage=20, + max_allocated_storage=100, + multi_az=False, + publicly_accessible=False, + storage_encrypted=True, + backup_retention=Duration.days(7), + deletion_protection=False, + removal_policy=RemovalPolicy.DESTROY, + delete_automated_backups=True, + ) + + # ECS Cluster + self.kmsKey = kms.Key(self, "ECSExecKey") + + self.ECSCluster = ecs.Cluster( + self, + "ecs", + vpc=self.VPC, + execute_command_configuration=ecs.ExecuteCommandConfiguration( + kms_key=self.kmsKey + ), + ) + + # Set container configs + if config.has_option(service, 'entry_point'): + entry_point = ["/bin/sh", "-c", config[service]['entry_point']] + else: + entry_point = None + + secrets={ + "PHOENIX_SECRET":ecs.Secret.from_secrets_manager(self.secret, 'phoenix_secret'), + "PHOENIX_DEFAULT_ADMIN_INITIAL_PASSWORD":ecs.Secret.from_secrets_manager(self.secret, 'phoenix_admin_password'), + "PHOENIX_POSTGRES_USER":ecs.Secret.from_secrets_manager(self.secret, 'username'), + "PHOENIX_POSTGRES_PASSWORD":ecs.Secret.from_secrets_manager(self.secret, 'password'), + "PHOENIX_POSTGRES_DB":ecs.Secret.from_secrets_manager(self.secret, 'dbname') + } + + environment={ + "PHOENIX_POSTGRES_HOST": self.postgres.db_instance_endpoint_address, + "PHOENIX_TELEMETRY_ENABLED": "false", + "PHOENIX_ENABLE_AUTH": "true", + # "PHOENIX_POSTGRES_SCHEMA": "postgresql", + "PHOENIX_POSTGRES_PORT": "5432" + } + + taskDefinition = ecs.FargateTaskDefinition(self, + "{}-{}-taskDef".format(self.namingPrefix, service), + cpu=config.getint(service, 'cpu'), + memory_limit_mib=config.getint(service, 'memory') + ) + + phoenixContainer = taskDefinition.add_container( + service, + image=ecs.ContainerImage.from_registry(config[service]['image']), + cpu=config.getint(service, 'cpu'), + memory_limit_mib=config.getint(service, 'memory'), + port_mappings=[ecs.PortMapping(container_port=config.getint(service, 'port'), name=service)], + # user="root", + entry_point=entry_point, + secrets=secrets, + environment=environment, + logging=ecs.LogDrivers.aws_logs( + stream_prefix="{}-{}".format(self.namingPrefix, service) + ) + ) + + ecsService = ecs.FargateService(self, + "{}-{}-service".format(self.namingPrefix, service), + cluster=self.ECSCluster, + task_definition=taskDefinition, + enable_execute_command=True, + min_healthy_percent=0, + max_healthy_percent=100, + circuit_breaker=ecs.DeploymentCircuitBreaker( + enable=True, + rollback=True + ) + ) + + ### ALB + if config.getboolean('alb', 'internet_facing'): + subnets=ec2.SubnetSelection( + subnets=self.VPC.select_subnets(one_per_az=True,subnet_type=ec2.SubnetType.PUBLIC).subnets + ) + else: + subnets=ec2.SubnetSelection( + subnets=self.VPC.select_subnets(one_per_az=True,subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS).subnets + ) + + # ALB + self.ALB = elbv2.ApplicationLoadBalancer(self, + "alb", + vpc=self.VPC, + internet_facing=config.getboolean('alb', 'internet_facing'), + vpc_subnets=subnets + ) + + self.ALB.log_access_logs( + prefix=f"{config['main']['program']}/{config['main']['tier']}/{config['main']['project']}/alb-access-logs", + bucket=s3.Bucket.from_bucket_arn(self, + f"{self.namingPrefix}-ALB-CentralLogBucket", + bucket_arn=config['alb']['log_bucket_arn'] + ) + ) + + self.ALB.add_redirect( + source_protocol=elbv2.ApplicationProtocol.HTTP, + source_port=80, + target_protocol=elbv2.ApplicationProtocol.HTTPS, + target_port=443 + ) + + alb_cert = cfm.Certificate.from_certificate_arn(self, "alb-cert", + certificate_arn=config['alb']['certificate_arn'] + ) + + self.listener = self.ALB.add_listener("PublicListener", + certificates=[alb_cert], + port=443 + ) + + ecsService.connections.allow_to_default_port(self.postgres) + + ecsTarget = self.listener.add_targets("ECS-{}-Target".format(service), + port=int(config[service]['port']), + protocol=elbv2.ApplicationProtocol.HTTP, + health_check = elbv2.HealthCheck( + path=config[service]['health_check_path'], + timeout=Duration.seconds(config.getint(service, 'health_check_timeout')), + interval=Duration.seconds(config.getint(service, 'health_check_interval')),), + targets=[ecsService],) + + elbv2.ApplicationListenerRule(self, id="alb-{}-rule".format(service), + conditions=[ + elbv2.ListenerCondition.path_patterns(config[service]['path'].split(',')) + ], + priority=int(config[service]['priority_rule_number']), + listener=self.listener, + target_groups=[ecsTarget] + ) + + self.listener.add_action("ECS-Content-Not-Found", + action=elbv2.ListenerAction.fixed_response(200, + message_body="The requested resource is not available") + ) \ No newline at end of file diff --git a/awscdk/phoenix/cdk.json b/awscdk/phoenix/cdk.json new file mode 100644 index 00000000..63a5d1c2 --- /dev/null +++ b/awscdk/phoenix/cdk.json @@ -0,0 +1,70 @@ +{ + "app": "python3 app.py", + "watch": { + "include": [ + "**" + ], + "exclude": [ + "README.md", + "cdk*.json", + "requirements*.txt", + "source.bat", + "**/__init__.py", + "**/__pycache__", + "tests" + ] + }, + "context": { + "@aws-cdk/aws-lambda:recognizeLayerVersion": true, + "@aws-cdk/core:checkSecretUsage": true, + "@aws-cdk/core:target-partitions": [ + "aws", + "aws-cn" + ], + "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, + "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, + "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, + "@aws-cdk/aws-iam:minimizePolicies": true, + "@aws-cdk/core:validateSnapshotRemovalPolicy": true, + "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, + "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, + "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, + "@aws-cdk/aws-apigateway:disableCloudWatchRole": true, + "@aws-cdk/core:enablePartitionLiterals": true, + "@aws-cdk/aws-events:eventsTargetQueueSameAccount": true, + "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true, + "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true, + "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true, + "@aws-cdk/aws-route53-patters:useCertificate": true, + "@aws-cdk/customresources:installLatestAwsSdkDefault": false, + "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true, + "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true, + "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true, + "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true, + "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true, + "@aws-cdk/aws-redshift:columnId": true, + "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true, + "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true, + "@aws-cdk/aws-apigateway:requestValidatorUniqueId": true, + "@aws-cdk/aws-kms:aliasNameRef": true, + "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true, + "@aws-cdk/core:includePrefixInUniqueNameGeneration": true, + "@aws-cdk/aws-efs:denyAnonymousAccess": true, + "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true, + "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true, + "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true, + "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true, + "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true, + "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true, + "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true, + "@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true, + "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true, + "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true, + "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true, + "@aws-cdk/aws-eks:nodegroupNameAttribute": true, + "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true, + "@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true, + "@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false, + "@aws-cdk/aws-stepfunctions-tasks:ecsReduceRunTaskPermissions": true + } +} diff --git a/awscdk/phoenix/getArgs.py b/awscdk/phoenix/getArgs.py new file mode 100644 index 00000000..0b377ce2 --- /dev/null +++ b/awscdk/phoenix/getArgs.py @@ -0,0 +1,16 @@ +import sys, getopt + +class getArgs: + def set_tier(argv): + + try: + opts, args = getopt.getopt(argv,"ht:",["tier="]) + except getopt.GetoptError: + print('app.py -t ') + sys.exit(2) + for opt, arg in opts: + if opt == '-h': + print('To use these scripts please identify the tier: app.py -t ') + sys.exit(1) + elif opt in ("-t", "--tier"): + return arg \ No newline at end of file diff --git a/awscdk/phoenix/parseYML.py b/awscdk/phoenix/parseYML.py new file mode 100644 index 00000000..b0f6c037 --- /dev/null +++ b/awscdk/phoenix/parseYML.py @@ -0,0 +1,10 @@ +import yaml +import os + +parsed_file = yaml.safe_load(open('deployments.yaml')) + +for svc in parsed_file['services']: + envVarName = 'IMAGE_' + svc.upper() + print("{}={}".format(envVarName, parsed_file['services'][svc]['image'])) + + # os.environ[envVarName] = parsed_file['services'][svc]['image'] diff --git a/awscdk/phoenix/requirements-dev.txt b/awscdk/phoenix/requirements-dev.txt new file mode 100644 index 00000000..92709451 --- /dev/null +++ b/awscdk/phoenix/requirements-dev.txt @@ -0,0 +1 @@ +pytest==6.2.5 diff --git a/awscdk/phoenix/requirements.txt b/awscdk/phoenix/requirements.txt new file mode 100644 index 00000000..30cc6141 --- /dev/null +++ b/awscdk/phoenix/requirements.txt @@ -0,0 +1,10 @@ +-e . +aws-cdk-lib==2.150.0 +constructs>=10.0.0,<11.0.0 +configparser +boto3 +jsii + +pyyaml + +cdk-ec2-key-pair \ No newline at end of file diff --git a/awscdk/phoenix/setup.py b/awscdk/phoenix/setup.py new file mode 100644 index 00000000..12d08e1d --- /dev/null +++ b/awscdk/phoenix/setup.py @@ -0,0 +1,45 @@ +import setuptools + + +with open("README.md") as fp: + long_description = fp.read() + + +setuptools.setup( + name="app", + version="0.0.1", + + description="An empty CDK Python app", + long_description=long_description, + long_description_content_type="text/markdown", + + author="author", + + package_dir={"": "app"}, + packages=setuptools.find_packages(where="app"), + + install_requires=[ + "aws-cdk-lib==2.150.0", + ], + + python_requires=">=3.6", + + classifiers=[ + "Development Status :: 4 - Beta", + + "Intended Audience :: Developers", + + "License :: OSI Approved :: Apache Software License", + + "Programming Language :: JavaScript", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + + "Topic :: Software Development :: Code Generators", + "Topic :: Utilities", + + "Typing :: Typed", + ], +) diff --git a/awscdk/phoenix/source.bat b/awscdk/phoenix/source.bat new file mode 100644 index 00000000..9e1a8344 --- /dev/null +++ b/awscdk/phoenix/source.bat @@ -0,0 +1,13 @@ +@echo off + +rem The sole purpose of this script is to make the command +rem +rem source .venv/bin/activate +rem +rem (which activates a Python virtualenv on Linux or Mac OS X) work on Windows. +rem On Windows, this command just runs this batch file (the argument is ignored). +rem +rem Now we don't need to document a Windows command for activating a virtualenv. + +echo Executing .venv\Scripts\activate.bat for you +.venv\Scripts\activate.bat diff --git a/awscdk/phoenix/tests/__init__.py b/awscdk/phoenix/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/awscdk/phoenix/tests/unit/__init__.py b/awscdk/phoenix/tests/unit/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/awscdk/phoenix/tests/unit/test_app_stack.py b/awscdk/phoenix/tests/unit/test_app_stack.py new file mode 100644 index 00000000..575b2a02 --- /dev/null +++ b/awscdk/phoenix/tests/unit/test_app_stack.py @@ -0,0 +1,15 @@ +import aws_cdk as core +import aws_cdk.assertions as assertions + +from app.app_stack import AppStack + +# example tests. To run these tests, uncomment this file along with the example +# resource in app/app_stack.py +def test_sqs_queue_created(): + app = core.App() + stack = AppStack(app, "app") + template = assertions.Template.from_stack(stack) + +# template.has_resource_properties("AWS::SQS::Queue", { +# "VisibilityTimeout": 300 +# })