def test_nested_state_machine_chain():
    default_fragment_json = {
        'Type':
        'Parallel',
        'End':
        True,
        'Branches': [{
            'StartAt': 'test-fragment: test-nested-state-machine',
            'States': {
                'test-fragment: test-nested-state-machine': {
                    'Next':
                    'test-fragment: test-nested-state-machine - Parse JSON Output',
                    'Catch': [{
                        'ErrorEquals': ['States.ALL'],
                        'ResultPath': '$.Error',
                        'Next': 'test-fail'
                    }],
                    'Parameters': {
                        'StateMachineArn': {
                            'Ref': 'teststatemachine7F4C511D'
                        },
                        'Input': {
                            'Key1': 'Value1'
                        }
                    },
                    'Type':
                    'Task',
                    'Resource': {
                        'Fn::Join': [
                            '',
                            [
                                'arn:', {
                                    'Ref': 'AWS::Partition'
                                }, ':states:::states:startExecution.sync'
                            ]
                        ]
                    }
                },
                'test-fragment: test-nested-state-machine - Parse JSON Output':
                {
                    'End':
                    True,
                    'Catch': [{
                        'ErrorEquals': ['States.ALL'],
                        'ResultPath': '$.Error',
                        'Next': 'test-fail'
                    }],
                    'Parameters': {
                        'JsonString.$': '$.Output'
                    },
                    'Type':
                    'Task',
                    'Resource': {
                        'Fn::GetAtt': ['ParseJsonString859DB4F0', 'Arn']
                    },
                    'ResultPath':
                    '$'
                },
                'test-fail': {
                    'Type': 'Fail'
                }
            }
        }]
    }

    stack = core.Stack(core.App(), 'test-stack')

    state_machine = sfn.StateMachine(stack,
                                     'test-state-machine',
                                     definition=sfn.Chain.start(
                                         sfn.Succeed(stack, 'Succeeded')))

    fragment = emr_chains.NestedStateMachine(stack,
                                             'test-fragment',
                                             name='test-nested-state-machine',
                                             state_machine=state_machine,
                                             input={'Key1': 'Value1'},
                                             fail_chain=sfn.Fail(
                                                 stack, 'test-fail'))

    print_and_assert(default_fragment_json, fragment)
Example #2
0
def app_fixture():
    return core.App()
Example #3
0
def get_template():
    app = core.App()
    MyFirstCdkProjectStack(app, "my-first-cdk-project")
    return json.dumps(app.synth().get_stack("my-first-cdk-project").template)
Example #4
0
def template():
    app = core.App()
    NetworkStack(app, "NetworkStackTest")
    return json.dumps(app.synth().get_stack("NetworkStackTest").template)
Example #5
0
def main():
    app = core.App()
    BatchEnvironment(app, "your-project", "prod")
    app.synth()
Example #6
0
def main():
    app = core.App()
    BatchNestedEnvironment(app, "batch-nested-environment")
    app.synth()
def get_template():
    app = core.App()
    ApplicationmetricsStack(app, "applicationmetrics")
    return json.dumps(app.synth().get_stack("applicationmetrics").template)
def test_pipeline_creation_outputs_as_expected_when_source_is_s3_and_build_is_codebuild(
):
    region_name = "eu-central-1"
    account_id = "123456789012"

    stack_input = {
        "input": {
            "params": {},
            "default_providers": {},
            "regions": {}
        },
        "ssm_params": {
            "fake-region": {}
        },
    }

    stack_input["input"]["name"] = "test-stack"

    stack_input["input"]["default_providers"]["source"] = {
        "provider": "s3",
        "properties": {
            "account_id": "123456789012"
        },
    }
    stack_input["input"]["default_providers"]["build"] = {
        "provider": "codebuild",
        "properties": {
            "account_id": "123456789012"
        },
    }

    stack_input["ssm_params"][region_name] = {
        "modules": "fake-bucket-name",
        "kms":
        f"arn:aws:kms:{region_name}:{account_id}:key/my-unique-kms-key-id",
    }
    app = core.App()
    PipelineStack(app, stack_input)

    cloud_assembly = app.synth()
    resources = {
        k[0:-8]: v
        for k, v in cloud_assembly.stacks[0].template['Resources'].items()
    }
    code_pipeline = resources['codepipeline']
    assert code_pipeline['Type'] == "AWS::CodePipeline::Pipeline"
    assert len(code_pipeline["Properties"]["Stages"]) == 2

    source_stage = code_pipeline['Properties']["Stages"][0]
    assert len(source_stage['Actions']) == 1

    source_stage_action = source_stage['Actions'][0]
    assert source_stage_action['ActionTypeId']['Category'] == "Source"
    assert source_stage_action['ActionTypeId']['Owner'] == "AWS"
    assert source_stage_action['ActionTypeId']['Provider'] == "S3"

    build_stage = code_pipeline['Properties']["Stages"][1]
    build_stage_action = build_stage['Actions'][0]
    assert build_stage_action['ActionTypeId']['Category'] == "Build"
    assert build_stage_action['ActionTypeId']['Owner'] == "AWS"
    assert build_stage_action['ActionTypeId']['Provider'] == "CodeBuild"

    assert len(build_stage['Actions']) == 1
def get_template():
    app = core.App()
    Sep20CloudguruchallengeStack(app, "sep20cloudguruchallenge")
    return json.dumps(
        app.synth().get_stack("sep20cloudguruchallenge").template)
def test_pipeline_creation_outputs_with_codeartifact_trigger_with_package_name(
):
    region_name = "eu-central-1"
    acount_id = "123456789012"

    stack_input = {
        "input": {
            "params": {},
            "default_providers": {},
            "regions": {},
            "triggers": {
                "triggered_by": {
                    "code_artifact": {
                        "repository": "my_test_repo",
                        "package": "my_test_package"
                    }
                }
            }
        },
        "ssm_params": {
            "fake-region": {}
        },
    }

    stack_input["input"]["name"] = "test-stack"

    stack_input["input"]["default_providers"]["source"] = {
        "provider": "codecommit",
        "properties": {
            "account_id": "123456789012"
        },
    }
    stack_input["input"]["default_providers"]["build"] = {
        "provider": "codebuild",
        "properties": {
            "account_id": "123456789012"
        },
    }

    stack_input["ssm_params"][region_name] = {
        "modules": "fake-bucket-name",
        "kms":
        f"arn:aws:kms:{region_name}:{acount_id}:key/my-unique-kms-key-id",
    }
    app = core.App()
    PipelineStack(app, stack_input)

    cloud_assembly = app.synth()
    resources = {
        k[0:-8]: v
        for k, v in cloud_assembly.stacks[0].template['Resources'].items()
    }
    trigger = resources[
        'codepipelinecodeartifactpipelinetriggermytestrepomytestpackage']
    assert trigger["Type"] == "AWS::Events::Rule"
    assert trigger["Properties"]["EventPattern"]["detail-type"] == [
        "CodeArtifact Package Version State Change"
    ]
    assert trigger["Properties"]["EventPattern"]["source"] == [
        "aws.codeartifact"
    ]
    assert trigger["Properties"]["EventPattern"]["detail"] == {
        "repositoryName": "my_test_repo",
        "packageName": "my_test_package"
    }
def test_pipeline_creation_outputs_as_expected_when_notification_endpoint_is_chatbot(
):
    region_name = "eu-central-1"
    acount_id = "123456789012"

    stack_input = {
        "input": {
            "params": {
                "notification_endpoint": {
                    "target": "fake-config",
                    "type": "chat_bot"
                }
            },
            "default_providers": {},
            "regions": {},
        },
        "ssm_params": {
            "fake-region": {}
        },
    }

    stack_input["input"]["name"] = "test-stack"

    stack_input["input"]["default_providers"]["source"] = {
        "provider": "codecommit",
        "properties": {
            "account_id": "123456789012"
        },
    }
    stack_input["input"]["default_providers"]["build"] = {
        "provider": "codebuild",
        "properties": {
            "account_id": "123456789012"
        },
    }

    stack_input["ssm_params"][region_name] = {
        "modules": "fake-bucket-name",
        "kms":
        f"arn:aws:kms:{region_name}:{acount_id}:key/my-unique-kms-key-id",
    }
    app = core.App()
    PipelineStack(app, stack_input)

    cloud_assembly = app.synth()
    resources = {
        k[0:-8]: v
        for k, v in cloud_assembly.stacks[0].template['Resources'].items()
    }
    pipeline_notification = resources['pipelinenoti']['Properties']

    target = pipeline_notification["Targets"][0]

    assert resources["pipelinenoti"][
        "Type"] == "AWS::CodeStarNotifications::NotificationRule"
    assert target[
        "TargetAddress"] == "arn:aws:chatbot::111111111111:chat-configuration/slack-channel/fake-config"
    assert target["TargetType"] == "AWSChatbotSlack"
    assert pipeline_notification["EventTypeIds"] == [
        "codepipeline-pipeline-stage-execution-succeeded",
        "codepipeline-pipeline-stage-execution-failed",
        "codepipeline-pipeline-pipeline-execution-started",
        "codepipeline-pipeline-pipeline-execution-failed",
        "codepipeline-pipeline-pipeline-execution-succeeded",
        "codepipeline-pipeline-manual-approval-needed",
        "codepipeline-pipeline-manual-approval-succeeded"
    ]
    assert pipeline_notification["DetailType"] == "FULL"
def test_pipeline_generation_works_when_no_type_specified(mock):
    stack_input = {"input": {"params": {}}}
    stack_input["input"]["name"] = "test-stack"
    app = core.App()
    PipelineStack(app, stack_input)
    mock.assert_called()
def get_template():
    app = core.App()
    CicdPipelinePracticeStack(app, "cicd-pipeline-practice")
    return json.dumps(app.synth().get_stack("cicd-pipeline-practice").template)
def get_template():
    app = core.App()
    SlsApiStack(app, "sls-api")
    return json.dumps(app.synth().get_stack("sls-api").template)
def test_add_step_with_argument_overrides():
    default_fragment_json = {
        'Type':
        'Parallel',
        'End':
        True,
        'Branches': [{
            'StartAt': 'test-fragment: test-step - Override Args',
            'States': {
                'test-fragment: test-step - Override Args': {
                    'Next':
                    'test-fragment: test-step',
                    'Catch': [{
                        'ErrorEquals': ['States.ALL'],
                        'ResultPath': '$.Error',
                        'Next': 'test-fail'
                    }],
                    'Parameters': {
                        'ExecutionInput.$': '$$.Execution.Input',
                        'StepName': 'test-step',
                        'Args': ['Arg1', 'Arg2']
                    },
                    'Type':
                    'Task',
                    'Resource': {
                        'Fn::GetAtt': ['OverrideStepArgsE9376C9F', 'Arn']
                    },
                    'ResultPath':
                    '$.test-fragmentResultArgs'
                },
                'test-fragment: test-step': {
                    'End':
                    True,
                    'Catch': [{
                        'ErrorEquals': ['States.ALL'],
                        'ResultPath': '$.Error',
                        'Next': 'test-fail'
                    }],
                    'Parameters': {
                        'ClusterId': 'test-cluster-id',
                        'Step': {
                            'Name': 'test-step',
                            'ActionOnFailure': 'CONTINUE',
                            'HadoopJarStep': {
                                'Jar': 'Jar',
                                'MainClass': 'Main',
                                'Args.$': '$.test-fragmentResultArgs',
                                'Properties': []
                            }
                        }
                    },
                    'Type':
                    'Task',
                    'Resource': {
                        'Fn::Join': [
                            '',
                            [
                                'arn:', {
                                    'Ref': 'AWS::Partition'
                                }, ':states:::elasticmapreduce:addStep.sync'
                            ]
                        ]
                    }
                },
                'test-fail': {
                    'Type': 'Fail'
                }
            }
        }]
    }

    stack = core.Stack(core.App(), 'test-stack')

    fragment = emr_chains.AddStepWithArgumentOverrides(
        stack,
        'test-fragment',
        emr_step=emr_code.EMRStep('test-step', 'Jar', 'Main',
                                  ['Arg1', 'Arg2']),
        cluster_id='test-cluster-id',
        fail_chain=sfn.Fail(stack, 'test-fail'))

    print_and_assert(default_fragment_json, fragment)
def get_template():
    app = core.App()
    BadgeUploaderStack(app, "badge-uploader")
    return json.dumps(app.synth().get_stack("badge-uploader").template)
Example #17
0
def main():
    app = core.App()
    LambdaStepfunctionsStack(app, "LambdaStepfunctions", "prod")
    app.synth()
Example #18
0
def get_template():
    app = core.App()

    # Maybe some day in a future course learn to write tests for this
def get_template():
    app = core.App()
    CdkWorkshopStack(app, "cdk-workshop")
    return json.dumps(app.synth().get_stack("cdk-workshop").template)
Example #20
0
def get_template():
    app = core.App()
    SampleStack(app, "sample")
    return json.dumps(app.synth().get_stack("sample").template)
Example #21
0
 def setUp(self):
     self.app = core.App()
     self.stack = core.Stack(self.app, "teststack")
Example #22
0
def template_fixture():
    app = core.App()
    AirflowStack(app, deploy_env="test")
    return app.synth().get_stack("test-airflow-stack").template
def get_template():
    app = core.App()
    HelloS3V2Stack(app, "hello-s3-v2")
    return json.dumps(app.synth().get_stack("hello-s3-v2").template)
Example #24
0
def test_empty_repo_names(github):
    with pytest.raises(ValueError, match='Need to specify repository names.'):
        context = set_context(github)
        context['repo_names'] = ""
        app = core.App(context=context)
        RepositoryStatusMonitorStack(app, 'RepositoryStatusMonitor')