def test_snapshot_with_extended_task_role():
    template = get_template(
        deploy_config=
        'tests/fixtures/conf/fargate/extended_task_role/deploy.yml')
    snapshot_template = Config.dataload(
        'tests/fixtures/fargate_extended_task_role.template')
    assert snapshot_template == json.loads(template)
Exemplo n.º 2
0
def test_snapshot_with_no_default_vpcs():
    template = get_template(
        vpcs_config='tests/fixtures/conf/cluster/no_default_vpcs/vpcs.yml',
        deploy_config='tests/fixtures/conf/cluster/no_default_vpcs/cluster.yml'
    )
    snapshot_template = Config.dataload('tests/fixtures/cluster.template')
    assert snapshot_template == json.loads(template)
def test_snapshot_with_no_default_vpcs():
    template = get_template(
        global_config='tests/fixtures/conf/fargate/single_container/global.yml',
        vpcs_config='tests/fixtures/conf/fargate/no_default_vpcs/vpcs.yml',
        deploy_config='tests/fixtures/conf/fargate/no_default_vpcs/deploy.yml')
    snapshot_template = Config.dataload(
        'tests/fixtures/fargate_single_container.template')
    assert snapshot_template == json.loads(template)
def get_template(deploy_config=DEPLOY_CONFIG,
                 global_config=GLOBAL_CONFIG,
                 vpcs_config=VPCS_CONFIG):
    app = core.App()
    config = Config(global_config=global_config,
                    vpcs_config=vpcs_config,
                    deploy_config=deploy_config)
    FargateStack(scope=app,
                 id='fargate',
                 config=config,
                 stack_name='fargate-api')
    return json.dumps(app.synth().get_stack('fargate-api').template)
Exemplo n.º 5
0
    def __init__(self, scope: core.Construct, id: str, config: Config,
                 **kwargs):
        super().__init__(scope, id, **kwargs)

        ecs.CfnCluster(self, id='ECSCluster', cluster_name=core.Aws.STACK_NAME)
        SharedPrivateALB(
            self,
            id='SharedPrivateALB',
            application_port=config.application_port(),
            ingress_security_group_ids=config.ingress_security_group_ids(),
            ssl_certificate_arn=config.ssl_certificate_arn(),
            ssl_policy=config.ssl_policy(),
            subnet_ids=config.private_subnet_ids(),
            vpc_id=config.vpc_id())

        for key, value in config.tags().items():
            core.Tag.add(self, key, value)

        self.node.apply_aspect(UseOriginalConstructID())
Exemplo n.º 6
0
#!/usr/bin/env python3

import os
import argparse
from aws_cdk import core
from modules.stack.cluster_stack import ClusterStack
from modules.dataload.config import Config

parser = argparse.ArgumentParser()
parser.add_argument('-s', '--stack-name', required=True)
parser.add_argument('-d', '--deploy-config', required=True)
parser.add_argument('-o', '--overrides', nargs='*', default=[])
args = parser.parse_args()

app = core.App()
config = Config(deploy_config=args.deploy_config, overrides=args.overrides)
ClusterStack(scope=app,
             id='cluster',
             config=config,
             stack_name=args.stack_name,
             env={'region': os.environ['AWS_DEFAULT_REGION']})

app.synth()
def test_snapshot():
    snapshot_template = Config.dataload('tests/fixtures/fargate.template')
    assert snapshot_template == json.loads(get_template())
def test_snapshot_with_overrides():
    template = get_template(
        global_config='tests/fixtures/conf/fargate/with_overrides/global.yml')
    snapshot_template = Config.dataload(
        'tests/fixtures/fargate_with_overrides.template')
    assert snapshot_template == json.loads(template)
Exemplo n.º 9
0
    def __init__(self, scope: core.Construct, id: str, config: Config, **kwargs):
        super().__init__(scope, id, **kwargs)

        logs.CfnLogGroup(
            self,
            id=config.log_group_id(),
            retention_in_days=config.log_retention_days()
        )
        for role, policies in config.roles().items():
            ServiceRole(
                self,
                id=role,
                policies=policies,
                service='ecs-tasks.amazonaws.com',
                whitelisted_actions=config.whitelisted_actions()
            )
        TaskDefinition(
            self,
            id='TaskDefinition',
            containers=config.containers(),
            cpu=config.task_cpu(),
            memory=config.task_memory(),
            log_group_id=config.log_group_id(),
            execution_role_id=config.execution_role_id(),
            task_role_id=config.task_role_id(),
            overrides=config.task_overrides()
        )
        TargetGroup(
            self,
            id='TargetGroup',
            health_check_path=config.service_health_check_path(),
            port=config.service_port(),
            protocol=str.upper(config.service_health_check_protocol()),
            vpc_id=config.vpc_id(),
            overrides=config.target_group_overrides()
        )
        Service(
            self,
            id='Service',
            cluster_name=config.cluster_stack_name(),
            desired_count=config.service_desired_count(),
            service_name=config.service_name(),
            service_port=config.service_port(),
            security_group_import_name=config.shared_service_security_group_export_name(),
            subnet_ids=config.private_subnet_ids(),
            target_group_id='TargetGroup',
            task_def_id='TaskDefinition',
            overrides=config.service_overrides()
        )
        ListenerRule(
            self,
            id='ListenerRule',
            listener_import_name=config.shared_lb_listener_export_name(),
            paths=config.service_paths(),
            priority=config.service_priority(),
            target_group_id='TargetGroup'
        )
        RecordSet(
            self,
            id='RecordSet',
            hosted_zone_name=config.hosted_zone_name(),
            dns_name_import_name=config.shared_lb_dns_name_export_name(),
            hosted_zone_id_import_name=config.shared_lb_hosted_zone_id_export_name()
        )

        for key, value in config.tags().items():
            core.Tag.add(self, key, value)

        self.node.apply_aspect(UseOriginalConstructID())