Example #1
0
def main():
    # ------------------------------
    # Validate Config Values
    # ------------------------------

    if 'region' in config.deadline_client_linux_ami_map:
        raise ValueError('Deadline Client Linux AMI map is required but was not specified.')

    # ------------------------------
    # Application
    # ------------------------------
    app = App()

    if 'CDK_DEPLOY_ACCOUNT' not in os.environ and 'CDK_DEFAULT_ACCOUNT' not in os.environ:
        raise ValueError('You must define either CDK_DEPLOY_ACCOUNT or CDK_DEFAULT_ACCOUNT in the environment.')
    if 'CDK_DEPLOY_REGION' not in os.environ and 'CDK_DEFAULT_REGION' not in os.environ:
        raise ValueError('You must define either CDK_DEPLOY_REGION or CDK_DEFAULT_REGION in the environment.')
    env = Environment(
        account=os.environ.get('CDK_DEPLOY_ACCOUNT', os.environ.get('CDK_DEFAULT_ACCOUNT')),
        region=os.environ.get('CDK_DEPLOY_REGION', os.environ.get('CDK_DEFAULT_REGION'))
    )

    sep_props = sep_stack.SEPStackProps(
        docker_recipes_stage_path=os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'stage'),
        worker_machine_image=MachineImage.generic_linux(config.deadline_client_linux_ami_map),
        create_resource_tracker_role=config.create_resource_tracker_role,
    )
    service = sep_stack.SEPStack(app, 'SEPStack', props=sep_props, env=env)

    app.synth()
def cdk_prep_team_handler(stack_class: Type["Stack"]) -> None:
    _logger.debug("sys.argv: %s", sys.argv)
    if len(sys.argv) != 5:
        raise ValueError(f"Unexpected number of values in sys.argv ({len(sys.argv)}) - {sys.argv}.")

    stack_name: str = sys.argv[1]
    # team_name: str = sys.argv[3]
    parameters: Dict[str, Any] = _deserialize_parameters(parameters=sys.argv[4])
    context: "Context" = ContextSerDe.load_context_from_ssm(env_name=sys.argv[2], type=Context)

    # Can not find /orbit/env_name/teams ssm param.
    # team_context = context.get_team_by_name(name=team_name)
    # if team_context is None:
    #     raise ValueError(f"Team {team_name} not found in the context.")

    outdir = os.path.join(
        ".orbit.out",
        context.name,
        "cdk",
        stack_name,
    )
    shutil.rmtree(outdir, ignore_errors=True)
    os.makedirs(outdir, exist_ok=True)

    # Can't be imported globally because we only have CDK installed on CodeBuild
    from aws_cdk.core import App

    app = App(outdir=outdir)
    stack_class(app, stack_name, context, parameters)  # type: ignore
    app.synth(force=True)
Example #3
0
def main() -> None:
    _logger.debug("sys.argv: %s", sys.argv)
    if len(sys.argv) == 3:
        context: "Context" = ContextSerDe.load_context_from_ssm(
            env_name=sys.argv[1], type=Context)
        team_name: str = sys.argv[2]
    else:
        raise ValueError("Unexpected number of values in sys.argv.")

    changeset: Optional["Changeset"] = load_changeset_from_ssm(
        env_name=context.name)
    _logger.debug("Changeset loaded.")

    team_policies: Optional[List[str]] = None
    image: Optional[str] = None

    if changeset and changeset.teams_changeset and team_name in changeset.teams_changeset.added_teams_names:
        manifest: Optional["Manifest"] = ManifestSerDe.load_manifest_from_ssm(
            env_name=sys.argv[1], type=Manifest)
        if manifest is None:
            raise ValueError("manifest is None!")
        team_manifest: Optional["TeamManifest"] = manifest.get_team_by_name(
            name=team_name)
        if team_manifest:
            team_policies = team_manifest.policies
            image = team_manifest.image
        else:
            raise ValueError(f"{team_name} not found in manifest!")
    else:
        team_context: Optional["TeamContext"] = context.get_team_by_name(
            name=team_name)
        if team_context:
            team_policies = team_context.policies
            image = team_context.image
        else:
            raise ValueError(f"Team {team_name} not found in the context.")

    if team_policies is None:
        raise ValueError("team_policies is None!")

    stack_name: str = f"orbit-{context.name}-{team_name}"
    outdir = os.path.join(".orbit.out", context.name, "cdk", stack_name)
    os.makedirs(outdir, exist_ok=True)
    shutil.rmtree(outdir)
    app = App(outdir=outdir)
    Team(scope=app,
         id=stack_name,
         context=context,
         team_name=team_name,
         team_policies=team_policies,
         image=image)
    app.synth(force=True)
Example #4
0
File: app.py Project: linz/geostore
def main() -> None:
    app = App()

    env_name = environment_name()
    Application(app, f"{env_name}-geostore")

    # tag all resources in stack
    Tag.add(app, "CostCentre", "100005")
    Tag.add(app, APPLICATION_NAME_TAG_NAME, APPLICATION_NAME)
    Tag.add(app, "Owner", "Bill M. Nelson")
    Tag.add(app, "EnvironmentType", env_name)
    Tag.add(app, "SupportType", "Dev")
    Tag.add(app, "HoursOfOperation", "24x7")

    app.synth()
Example #5
0
def synthesis_solutions(session_mocker):
    """This currently uses the legacy stack synthesizer for speed."""
    session_mocker.patch("aws_cdk.aws_lambda.Function.__init__", mock_lambda_init)
    session_mocker.patch("aws_cdk.aws_lambda.LayerVersion.__init__", mock_layer_init)

    asset_directory = "assets"

    app = App(
        runtime_info=False,
        stack_traces=False,
        tree_metadata=False,
        analytics_reporting=False,
        context={
            "BUCKET_NAME": "test",
            "SOLUTION_NAME": "Improving Forecast Accuracy With Machine Learning",
            "QUICKSIGHT_SOURCE": "none",
            "NOTEBOOKS": "none",
            "VERSION": "1.2.0",
            "SOLUTIONS_ASSETS_REGIONAL": asset_directory,
            "SOLUTIONS_ASSETS_GLOBAL": asset_directory,
        },
    )
    synthesizer = SolutionStackSubstitions(qualifier="hnb659fds")
    stack = ForecastStack(app, "test", synthesizer=synthesizer)
    root = stack.node.root
    return root.synth(force=True)
Example #6
0
    def build_imagebuilder_template(image_config: ImageBuilderConfig,
                                    image_id: str, bucket: S3Bucket):
        """Build template for the given imagebuilder and return as output in Yaml format."""
        from aws_cdk.core import App  # pylint: disable=C0415

        from pcluster.templates.imagebuilder_stack import ImageBuilderCdkStack  # pylint: disable=C0415

        with tempfile.TemporaryDirectory() as tempdir:
            output_file = "imagebuilder"
            app = App(outdir=str(tempdir))
            ImageBuilderCdkStack(app, output_file, image_config, image_id,
                                 bucket)
            app.synth()
            generated_template = load_yaml_dict(
                os.path.join(tempdir, f"{output_file}.template.json"))

        return generated_template
Example #7
0
    def _synth_and_get_template(self, app: cdk.App, chalice: Chalice) -> dict:
        cloud_assembly = app.synth()

        chalice_stack_name = cdk.Stack.of(chalice).stack_name
        template = cloud_assembly.get_stack_by_name(
            chalice_stack_name).template

        return template
Example #8
0
def test_FUNC_constructor_WITH_various_parameters_EXPECT_layer_created():
    """
    Test whether the layer can be created.

    :return: No return.
    """
    layer = Layer(Stack(App(), 'Test'), 'Test')
    assert layer is not None
def main() -> None:
    _logger.debug("sys.argv: %s", sys.argv)
    if len(sys.argv) == 2:
        context: "FoundationContext" = ContextSerDe.load_context_from_ssm(
            env_name=sys.argv[1], type=FoundationContext)
    else:
        raise ValueError("Unexpected number of values in sys.argv.")

    outdir = os.path.join(".orbit.out", context.name, "cdk",
                          cast(str, context.stack_name))
    os.makedirs(outdir, exist_ok=True)
    shutil.rmtree(outdir)

    app = App(outdir=outdir)
    FoundationStack(scope=app,
                    id=cast(str, context.stack_name),
                    context=context)
    app.synth(force=True)
Example #10
0
def main() -> None:
    _logger.debug("sys.argv: %s", sys.argv)
    if len(sys.argv) == 2:
        context: "Context" = ContextSerDe.load_context_from_ssm(env_name=sys.argv[1], type=Context)
    else:
        raise ValueError(f"Unexpected number of values in sys.argv ({len(sys.argv)}), {sys.argv}")

    outdir = os.path.join(".orbit.out", context.name, "cdk", context.env_stack_name)
    os.makedirs(outdir, exist_ok=True)
    shutil.rmtree(outdir)

    app = App(outdir=outdir)
    Env(
        scope=app,
        id=context.env_stack_name,
        context=context,
    )
    app.synth(force=True)
Example #11
0
    def build_cluster_template(cluster_config: BaseClusterConfig,
                               bucket: S3Bucket,
                               stack_name: str,
                               log_group_name: str = None):
        """Build template for the given cluster and return as output in Yaml format."""
        from aws_cdk.core import App  # pylint: disable=C0415

        from pcluster.templates.cluster_stack import ClusterCdkStack  # pylint: disable=C0415

        with tempfile.TemporaryDirectory() as tempdir:
            output_file = str(stack_name)
            app = App(outdir=str(tempdir))
            ClusterCdkStack(app, output_file, stack_name, cluster_config,
                            bucket, log_group_name)
            app.synth()
            generated_template = load_yaml_dict(
                os.path.join(tempdir, f"{output_file}.template.json"))

        return generated_template
Example #12
0
def main() -> None:
    _logger.debug("sys.argv: %s", sys.argv)
    context: "FoundationContext" = ContextSerDe.load_context_from_ssm(
        env_name=sys.argv[1], type=FoundationContext)
    ssl_cert_arn: str
    if len(sys.argv) == 3:
        ssl_cert_arn = sys.argv[2]
    elif len(sys.argv) == 2:
        ssl_cert_arn = ""
    else:
        raise ValueError("Unexpected number of values in sys.argv.")

    outdir = os.path.join(".orbit.out", context.name, "cdk",
                          cast(str, context.stack_name))
    os.makedirs(outdir, exist_ok=True)
    shutil.rmtree(outdir)

    app = App(outdir=outdir, )

    @jsii.implements(core.IAspect)
    class AddDeployPathIAM:
        """ Implementing CDK Aspects to add optional IAM Role prefix to IAM roles """
        def visit(self, node: core.IConstruct) -> None:
            """ Function to implement a path pattern """
            if isinstance(node, iam.CfnRole):
                node.path = f"/{context.role_prefix}/" if context.role_prefix else "/"

    foundation_stack = FoundationStack(
        scope=app,
        id=cast(str, context.stack_name),
        context=context,
        ssl_cert_arn=ssl_cert_arn,
        env=core.Environment(account=os.environ["CDK_DEFAULT_ACCOUNT"],
                             region=os.environ["CDK_DEFAULT_REGION"]),
    )

    Aspects.of(scope=cast(core.IConstruct, foundation_stack)).add(
        cast(core.IAspect, AddDeployPathIAM()))
    app.synth(force=True)
Example #13
0
def test_ALL_FUNC_WITH_default_params_EXPECT_singleton_initialized():
    """
    Test whether the layer singleton works.

    :return: No return.
    """
    with pytest.raises(Exception):
        LayerSingleton(Stack(App(), 'Test'), 'Test')

    with pytest.raises(Exception):
        LayerSingleton.get_instance()

    assert LayerSingleton.is_initialized() is False

    LayerSingleton.initialize(Stack(App(), 'Test'), 'Test')

    with pytest.raises(Exception):
        LayerSingleton.initialize(Stack(App(), 'Test'), 'Test')

    LayerSingleton.safe_initialize(Stack(App(), 'Test'), 'Test')

    assert isinstance(LayerSingleton.get_instance().layer, Layer)
def main() -> None:
    _logger.debug("sys.argv: %s", sys.argv)
    if len(sys.argv) == 2:
        context: "Context" = ContextSerDe.load_context_from_ssm(
            env_name=sys.argv[1], type=Context)
    else:
        raise ValueError(
            f"Unexpected number of values in sys.argv ({len(sys.argv)}), {sys.argv}"
        )

    outdir = os.path.join(".orbit.out", context.name, "cdk",
                          context.env_stack_name)
    os.makedirs(outdir, exist_ok=True)
    shutil.rmtree(outdir)

    app = App(outdir=outdir)

    @jsii.implements(core.IAspect)
    class AddDeployPathIAM:
        """ Implementing CDK Aspects to add optional IAM Role prefix to IAM roles """
        def visit(self, obj: core.IConstruct) -> None:
            """ Function to implement a path pattern """
            if isinstance(obj, NonPathRole):
                cfn_role = obj.node.find_child("Resource")
                path = "/"
                cfn_role.add_property_override("Path", path)
            elif isinstance(obj, iam.Role):
                cfn_role = obj.node.find_child("Resource")
                path = f"/{context.role_prefix}/" if context.role_prefix else "/"
                cfn_role.add_property_override("Path", path)

    env_stack = Env(
        scope=app,
        id=context.env_stack_name,
        context=context,
    )
    Aspects.of(scope=cast(IConstruct, env_stack)).add(
        cast(IAspect, AddDeployPathIAM()))
    app.synth(force=True)
Example #15
0
def main():
    # ------------------------------
    # Application
    # ------------------------------
    app = App()

    if 'CDK_DEPLOY_ACCOUNT' not in os.environ and 'CDK_DEFAULT_ACCOUNT' not in os.environ:
        raise ValueError('You must define either CDK_DEPLOY_ACCOUNT or CDK_DEFAULT_ACCOUNT in the environment.')
    if 'CDK_DEPLOY_REGION' not in os.environ and 'CDK_DEFAULT_REGION' not in os.environ:
        raise ValueError('You must define either CDK_DEPLOY_REGION or CDK_DEFAULT_REGION in the environment.')
    env = Environment(
        account=os.environ.get('CDK_DEPLOY_ACCOUNT', os.environ.get('CDK_DEFAULT_ACCOUNT')),
        region=os.environ.get('CDK_DEPLOY_REGION', os.environ.get('CDK_DEFAULT_REGION'))
    )
    # ------------------------------
    # Service Tier
    # ------------------------------
    sep_props = sep_stack.SEPStackProps(
        docker_recipes_stage_path=os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'stage'),
    )
    service = sep_stack.SEPStack(app, 'SEPStack', props=sep_props, env=env)

    app.synth()
Example #16
0
def main():
    app = App()

    if 'CDK_DEPLOY_ACCOUNT' not in os.environ and 'CDK_DEFAULT_ACCOUNT' not in os.environ:
        raise ValueError(
            'You must define either CDK_DEPLOY_ACCOUNT or CDK_DEFAULT_ACCOUNT in the environment.'
        )
    if 'CDK_DEPLOY_REGION' not in os.environ and 'CDK_DEFAULT_REGION' not in os.environ:
        raise ValueError(
            'You must define either CDK_DEPLOY_REGION or CDK_DEFAULT_REGION in the environment.'
        )
    env = Environment(
        account=os.environ.get('CDK_DEPLOY_ACCOUNT',
                               os.environ.get('CDK_DEFAULT_ACCOUNT')),
        region=os.environ.get('CDK_DEPLOY_REGION',
                              os.environ.get('CDK_DEFAULT_REGION')))

    farm_props = base_farm_stack.BaseFarmStackProps(
        deadline_version=config.deadline_version,
        accept_aws_thinkbox_eula=config.accept_aws_thinkbox_eula)
    farm_stack = base_farm_stack.BaseFarmStack(app,
                                               'BaseFarmStack',
                                               props=farm_props,
                                               env=env)

    compute_stack_props = compute_stack.ComputeStackProps(
        deadline_version=config.deadline_version,
        image_recipe_version=config.image_recipe_version,
        render_queue=farm_stack.render_queue,
        vpc=farm_stack.vpc)
    compute_stack.ComputeStack(app,
                               'ComputeStack',
                               props=compute_stack_props,
                               env=env)

    app.synth()
def test_FUNC_hash_WITH_valid_parameters_EXPECT_hash_created():
    """
    Test that hashing is consistent and works as expected.

    :return: No return.
    """
    stack = Stack(App(), 'TestStack')

    integration = LambdaIntegration(
        scope=stack,
        integration_name='TestIntegration',
        api=CfnApi(stack, 'TestApi'),
        lambda_function=Function(
            stack,
            'TestLambdaFunction',
            code=Code.from_inline('def handler(*args, **kwargs): return 123'),
            handler='index.handler',
            runtime=Runtime.PYTHON_3_6))

    assert integration.hash == 'ab93cecc508e529c3791ba48a1275deec88cdd6b43a7e1d443906df48fa300e4'
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # The code that defines your stack goes here
        app = App()
        cdk_stack = Stack(app, 'network')

        # Add a tag to all constructs in the stack
        Tag.add(cdk_stack, "Created By", "umut.yalcinkaya")

        # VPC
        vpc = ec2.Vpc(self,
                      "VPC",
                      nat_gateways=0,
                      subnet_configuration=[
                          ec2.SubnetConfiguration(
                              name="public", subnet_type=ec2.SubnetType.PUBLIC)
                      ])
        # Iterate the private subnets
        # selection = vpc.select_subnets(
        #     subnet_type=ec2.SubnetType.PRIVATE
        # )

        # for subnet in selection.subnets:
        #     pass

        # AMI
        amzn_linux = ec2.MachineImage.latest_amazon_linux(
            generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
            edition=ec2.AmazonLinuxEdition.STANDARD,
            virtualization=ec2.AmazonLinuxVirt.HVM,
            storage=ec2.AmazonLinuxStorage.GENERAL_PURPOSE)

        # Instance Role and SSM Managed Policy
        role = iam.Role(self,
                        "InstanceSSM",
                        assumed_by=iam.ServicePrincipal("ec2.amazonaws.com"))

        role.add_managed_policy(
            iam.ManagedPolicy.from_aws_managed_policy_name(
                "service-role/AmazonEC2RoleforSSM"))

        # Instance
        instance = ec2.Instance(self,
                                "Instance",
                                instance_type=ec2.InstanceType("t3a.large"),
                                machine_image=amzn_linux,
                                vpc=vpc,
                                role=role,
                                key_name="umut-poc")

        instance.instance.add_property_override(
            "BlockDeviceMappings", [{
                "DeviceName": "/dev/sdb",
                "Ebs": {
                    "VolumeSize": "30",
                    "VolumeType": "gp2",
                    "DeleteOnTermination": "true"
                }
            }])

        # Script in S3 as Asset
        asset = Asset(self,
                      "Asset",
                      path=os.path.join(dirname, "configure.sh"))
        local_path = instance.user_data.add_s3_download_command(
            bucket=asset.bucket, bucket_key=asset.s3_object_key)

        # Userdata executes script from S3
        instance.user_data.add_execute_file_command(file_path=local_path)
        asset.grant_read(instance.role)
        # output information after deploy
        output = core.CfnOutput(self,
                                "BastionHost_information",
                                value=instance.instance_public_ip,
                                description="BastionHost's Public IP")
Example #19
0
def main() -> None:
    app = App()

    environment = Environment(
        account=environ["CDK_DEFAULT_ACCOUNT"], region=environ["CDK_DEFAULT_REGION"]
    )

    storage = StorageStack(
        app,
        "storage",
        deploy_env=ENV,
        env=environment,
        stack_name=f"{ENV}-geospatial-data-lake-storage",
    )

    StagingStack(
        app,
        "staging",
        deploy_env=ENV,
        env=environment,
        stack_name=f"{ENV}-geospatial-data-lake-staging",
    )

    lambda_layers = LambdaLayersStack(
        app,
        "lambda-layers",
        deploy_env=ENV,
        env=environment,
        stack_name=f"{ENV}-geospatial-data-lake-lambda-layers",
    )

    processing = ProcessingStack(
        app,
        "processing",
        botocore_lambda_layer=lambda_layers.botocore,
        datasets_table=storage.datasets_table,
        deploy_env=ENV,
        storage_bucket=storage.storage_bucket,
        storage_bucket_parameter=storage.storage_bucket_parameter,
        validation_results_table=storage.validation_results_table,
        env=environment,
        stack_name=f"{ENV}-geospatial-data-lake-processing",
    )

    APIStack(
        app,
        "api",
        botocore_lambda_layer=lambda_layers.botocore,
        datasets_table=storage.datasets_table,
        deploy_env=ENV,
        state_machine=processing.state_machine,
        state_machine_parameter=processing.state_machine_parameter,
        storage_bucket=storage.storage_bucket,
        storage_bucket_parameter=storage.storage_bucket_parameter,
        validation_results_table=storage.validation_results_table,
        env=environment,
        stack_name=f"{ENV}-geospatial-data-lake-api",
    )

    if app.node.try_get_context("enableLDSAccess"):
        LDSStack(
            app,
            "lds",
            deploy_env=ENV,
            storage_bucket=storage.storage_bucket,
            env=environment,
            stack_name=f"{ENV}-geospatial-data-lake-lds",
        )

    # tag all resources in stack
    Tag.add(app, "CostCentre", "100005")
    Tag.add(app, APPLICATION_NAME_TAG_NAME, APPLICATION_NAME)
    Tag.add(app, "Owner", "Bill M. Nelson")
    Tag.add(app, "EnvironmentType", ENV)
    Tag.add(app, "SupportType", "Dev")
    Tag.add(app, "HoursOfOperation", "24x7")

    app.synth()
Example #20
0
def main():
    # ------------------------------
    # Validate Config Values
    # ------------------------------

    if not config.ubl_certificate_secret_arn and config.ubl_licenses:
        raise ValueError(
            'UBL certificates secret ARN is required when using UBL but was not specified.'
        )

    if not config.ubl_licenses:
        print('No UBL licenses specified. UBL Licensing will not be set up.')

    if not config.key_pair_name:
        print(
            'EC2 key pair name not specified. You will not have SSH access to the render farm.'
        )

    if 'region' in config.deadline_client_linux_ami_map:
        raise ValueError(
            'Deadline Client Linux AMI map is required but was not specified.')

    # ------------------------------
    # Application
    # ------------------------------
    app = App()

    if 'CDK_DEPLOY_ACCOUNT' not in os.environ and 'CDK_DEFAULT_ACCOUNT' not in os.environ:
        raise ValueError(
            'You must define either CDK_DEPLOY_ACCOUNT or CDK_DEFAULT_ACCOUNT in the environment.'
        )
    if 'CDK_DEPLOY_REGION' not in os.environ and 'CDK_DEFAULT_REGION' not in os.environ:
        raise ValueError(
            'You must define either CDK_DEPLOY_REGION or CDK_DEFAULT_REGION in the environment.'
        )
    env = Environment(
        account=os.environ.get('CDK_DEPLOY_ACCOUNT',
                               os.environ.get('CDK_DEFAULT_ACCOUNT')),
        region=os.environ.get('CDK_DEPLOY_REGION',
                              os.environ.get('CDK_DEFAULT_REGION')))

    # ------------------------------
    # Network Tier
    # ------------------------------
    network = network_tier.NetworkTier(app, 'NetworkTier', env=env)

    # ------------------------------
    # Security Tier
    # ------------------------------
    security = security_tier.SecurityTier(app, 'SecurityTier', env=env)

    # ------------------------------
    # Storage Tier
    # ------------------------------
    if config.deploy_mongo_db:
        storage_props = storage_tier.StorageTierMongoDBProps(
            vpc=network.vpc,
            database_instance_type=InstanceType.of(InstanceClass.MEMORY5,
                                                   InstanceSize.LARGE),
            root_ca=security.root_ca,
            dns_zone=network.dns_zone,
            accept_sspl_license=config.accept_sspl_license,
            key_pair_name=config.key_pair_name)
        storage = storage_tier.StorageTierMongoDB(app,
                                                  'StorageTier',
                                                  props=storage_props,
                                                  env=env)
    else:
        storage_props = storage_tier.StorageTierDocDBProps(
            vpc=network.vpc,
            database_instance_type=InstanceType.of(InstanceClass.MEMORY5,
                                                   InstanceSize.LARGE),
        )
        storage = storage_tier.StorageTierDocDB(app,
                                                'StorageTier',
                                                props=storage_props,
                                                env=env)

    # ------------------------------
    # Service Tier
    # ------------------------------
    service_props = service_tier.ServiceTierProps(
        database=storage.database,
        file_system=storage.file_system,
        vpc=network.vpc,
        docker_recipes_stage_path=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), os.pardir, 'stage'),
        ubl_certs_secret_arn=config.ubl_certificate_secret_arn,
        ubl_licenses=config.ubl_licenses,
        root_ca=security.root_ca,
        dns_zone=network.dns_zone)
    service = service_tier.ServiceTier(app,
                                       'ServiceTier',
                                       props=service_props,
                                       env=env)

    # ------------------------------
    # Compute Tier
    # ------------------------------
    deadline_client_image = MachineImage.generic_linux(
        config.deadline_client_linux_ami_map)
    compute_props = compute_tier.ComputeTierProps(
        vpc=network.vpc,
        render_queue=service.render_queue,
        worker_machine_image=deadline_client_image,
        key_pair_name=config.key_pair_name,
        usage_based_licensing=service.ubl_licensing,
        licenses=config.ubl_licenses)
    _compute = compute_tier.ComputeTier(app,
                                        'ComputeTier',
                                        props=compute_props,
                                        env=env)

    app.synth()
Example #21
0
from aws_cdk.core import App

from conf import AWS_CONF
from ui_stack import UiStack

app_deploy = App()

stacks = [
    {
        "name": "ui",
        "class": UiStack,
        "type": "extended"
    },
]
for stack in stacks:
    if stack.get("type") == "extended":
        base_name = AWS_CONF["extended_base_stack_name"]
        base_desc = AWS_CONF["extended_base_stack_desc"]
    else:
        base_name = AWS_CONF["base_stack_name"]
        base_desc = AWS_CONF["base_stack_desc"]

    cf_stack_name = f"{base_name}-{stack['name']}"
    cf_stack_desc = f"{stack['name']} stack | {base_desc}"
    stack["class"](
        app_deploy,
        cf_stack_name,
        description=cf_stack_desc,
        env=dict(AWS_CONF["env"]),
    )
Example #22
0
def main() -> None:
    _logger.debug("sys.argv: %s", sys.argv)
    if len(sys.argv) == 3:
        context: "Context" = ContextSerDe.load_context_from_ssm(
            env_name=sys.argv[1], type=Context)
        team_name: str = sys.argv[2]
    else:
        raise ValueError("Unexpected number of values in sys.argv.")

    changeset: Optional["Changeset"] = load_changeset_from_ssm(
        env_name=context.name)
    _logger.debug("Changeset loaded.")

    team_policies: Optional[List[str]] = None
    image: Optional[str] = None

    if changeset and changeset.teams_changeset and team_name in changeset.teams_changeset.added_teams_names:
        manifest: Optional["Manifest"] = ManifestSerDe.load_manifest_from_ssm(
            env_name=sys.argv[1], type=Manifest)
        if manifest is None:
            raise ValueError("manifest is None!")
        team_manifest: Optional["TeamManifest"] = manifest.get_team_by_name(
            name=team_name)
        if team_manifest:
            team_policies = team_manifest.policies
            image = team_manifest.image
        else:
            raise ValueError(f"{team_name} not found in manifest!")
    else:
        team_context: Optional["TeamContext"] = context.get_team_by_name(
            name=team_name)
        if team_context:
            team_policies = team_context.policies
            image = team_context.image
        else:
            raise ValueError(f"Team {team_name} not found in the context.")

    if team_policies is None:
        raise ValueError("team_policies is None!")

    stack_name: str = f"orbit-{context.name}-{team_name}"
    outdir = os.path.join(".orbit.out", context.name, "cdk", stack_name)
    os.makedirs(outdir, exist_ok=True)
    shutil.rmtree(outdir)
    app = App(outdir=outdir)

    @jsii.implements(core.IAspect)
    class AddDeployPathIAM:
        """ Implementing CDK Aspects to add optional IAM Role prefix to IAM roles """
        def visit(self, node: IConstruct) -> None:
            """ Function to implement a path pattern """

            if isinstance(node, iam.CfnRole):
                node.path = f"/{context.role_prefix}/" if context.role_prefix else "/"

    team_stack = Team(scope=app,
                      id=stack_name,
                      context=context,
                      team_name=team_name,
                      team_policies=team_policies,
                      image=image)
    Aspects.of(scope=cast(IConstruct, team_stack)).add(
        cast(IAspect, AddDeployPathIAM()))
    app.synth(force=True)
Example #23
0
def main():
    # ------------------------------
    # Validate Config Values
    # ------------------------------
    if not config.config.key_pair_name:
        print(
            'EC2 key pair name not specified. You will not have SSH access to the render farm.'
        )

    # ------------------------------
    # Application
    # ------------------------------
    app = App()

    if 'CDK_DEPLOY_ACCOUNT' not in os.environ and 'CDK_DEFAULT_ACCOUNT' not in os.environ:
        raise ValueError(
            'You must define either CDK_DEPLOY_ACCOUNT or CDK_DEFAULT_ACCOUNT in the environment.'
        )
    if 'CDK_DEPLOY_REGION' not in os.environ and 'CDK_DEFAULT_REGION' not in os.environ:
        raise ValueError(
            'You must define either CDK_DEPLOY_REGION or CDK_DEFAULT_REGION in the environment.'
        )
    env = Environment(
        account=os.environ.get('CDK_DEPLOY_ACCOUNT',
                               os.environ.get('CDK_DEFAULT_ACCOUNT')),
        region=os.environ.get('CDK_DEPLOY_REGION',
                              os.environ.get('CDK_DEFAULT_REGION')))

    # ------------------------------
    # Network Tier
    # ------------------------------
    network = network_tier.NetworkTier(app, 'NetworkTier', env=env)

    # ------------------------------
    # Security Tier
    # ------------------------------
    security = security_tier.SecurityTier(app, 'SecurityTier', env=env)

    # ------------------------------
    # Service Tier
    # ------------------------------
    service_props = service_tier.ServiceTierProps(
        vpc=network.vpc,
        availability_zones=config.config.availability_zones_standard,
        root_ca=security.root_ca,
        dns_zone=network.dns_zone,
        deadline_version=config.config.deadline_version,
        accept_aws_thinkbox_eula=config.config.accept_aws_thinkbox_eula)
    service = service_tier.ServiceTier(app,
                                       'ServiceTier',
                                       props=service_props,
                                       env=env)

    # ------------------------------
    # Compute Tier
    # ------------------------------
    deadline_client_image = MachineImage.generic_linux(
        config.config.deadline_client_linux_ami_map)
    compute_props = compute_tier.ComputeTierProps(
        vpc=network.vpc,
        availability_zones=config.config.availability_zones_local,
        render_queue=service.render_queue,
        worker_machine_image=deadline_client_image,
        key_pair_name=config.config.key_pair_name,
    )
    _compute = compute_tier.ComputeTier(app,
                                        'ComputeTier',
                                        props=compute_props,
                                        env=env)

    app.synth()
Example #24
0
#!/usr/bin/env python3
from aws_cdk.core import App, Stack, CfnParameter
from stack.base_stack import BaseStack
from stack.core_stack import CoreStack

app = App()

main_stack = Stack(app, 'Main')

email_param = CfnParameter(
    main_stack, 'email',
    description='email for sns subscription').value_as_string
app_stack = CoreStack(main_stack, 'AppStack', email=email_param)
base_stack = BaseStack(main_stack, 'BaseStack', app_stack.functions.my_lambda,
                       app_stack.functions.custom_config_rds,
                       app_stack.step_fn.state_machine)

#CdkworkshopStack(app, "projetox", env={'region': 'sa-east-1', 'account': os.environ['CDK_DEFAULT_ACCOUNT']})

app.synth()
Example #25
0
import pytest

from aws_cdk.core import App, Stack
from aws_cdk.assertions import Capture, Match, Template
from app import LambdaCronStack

app = App()
stack = LambdaCronStack(app, "LambdaCronExample")
template = Template.from_stack(stack)


class TestLambda:
    def test_specified_resources_created(self):
        template.resource_count_is('AWS::Lambda::Function', 1)
        template.resource_count_is('AWS::Events::Rule', 1)

    def test_lambda_function_has_correct_properties(self):
        dependency_capture = Capture()
        template.has_resource(
            'AWS::Lambda::Function', {
                'Properties': {
                    'Code': {
                        'ZipFile':
                        "def main(event, context):\n    print(\"I'm running!\")\n",
                    },
                    'Handler': 'index.main',
                    'Runtime': 'python3.7',
                    'Timeout': 300,
                },
                'DependsOn': [dependency_capture]
            })