def test_update_cluster_tags_builder(): default_task_json = { 'End': True, 'Retry': [{ 'ErrorEquals': ['Lambda.ServiceException', 'Lambda.AWSLambdaException', 'Lambda.SdkClientException'], 'IntervalSeconds': 2, 'MaxAttempts': 6, 'BackoffRate': 2 }], 'Type': 'Task', 'Resource': { 'Fn::GetAtt': ['UpdateClusterTags9DD0067C', 'Arn'] }, 'Parameters': { 'ExecutionInput.$': '$$.Execution.Input', 'Input.$': '$' } } stack = core.Stack(core.App(), 'test-stack') task = emr_tasks.UpdateClusterTagsBuilder.build( stack, 'test-task', ) print_and_assert(default_task_json, task)
def test_emr_secure_launch_function(self): stack = core.Stack(core.App(), 'test-stack') vpc = ec2.Vpc(stack, 'Vpc') success_topic = sns.Topic(stack, 'SuccessTopic') failure_topic = sns.Topic(stack, 'FailureTopic') profile = emr_profile.EMRProfile( stack, 'test-profile', profile_name='test-profile', vpc=vpc,) configuration = cluster_configuration.ClusterConfiguration( stack, 'test-configuration', configuration_name='test-configuration', secret_configurations={ 'SecretConfiguration': secretsmanager.Secret(stack, 'Secret') }) function = emr_launch_function.EMRLaunchFunction( stack, 'test-function', description='test description', launch_function_name='test-function', emr_profile=profile, cluster_configuration=configuration, cluster_name='test-cluster', success_topic=success_topic, failure_topic=failure_topic, allowed_cluster_config_overrides=configuration.override_interfaces['default'], wait_for_cluster_start=False ) self.print_and_assert(self.default_function, function)
def test_fail_if_cluster_running_builder(): default_task_json = { 'End': True, 'Retry': [{ 'ErrorEquals': ['Lambda.ServiceException', 'Lambda.AWSLambdaException', 'Lambda.SdkClientException'], 'IntervalSeconds': 2, 'MaxAttempts': 6, 'BackoffRate': 2 }], 'Type': 'Task', 'Resource': { 'Fn::GetAtt': ['FailIfClusterRunningC0A7FE52', 'Arn'] }, 'Parameters': { 'ExecutionInput.$': '$$.Execution.Input', 'DefaultFailIfClusterRunning': True, 'Input.$': '$' } } stack = core.Stack(core.App(), 'test-stack') task = emr_tasks.FailIfClusterRunningBuilder.build( stack, 'test-task', default_fail_if_cluster_running=True ) print_and_assert(default_task_json, task)
def test_emr_add_step_task(): default_task_json = { 'End': True, 'Parameters': { 'ClusterId': 'test-cluster-id', 'Step': { 'Key1': { 'Key2': 'Value2' } } }, 'Resource': { 'Fn::Join': [ '', [ 'arn:', { 'Ref': 'AWS::Partition' }, ':states:::elasticmapreduce:addStep.sync' ] ] }, 'Type': 'Task' } stack = core.Stack(core.App(), 'test-stack') task = sfn.Task(stack, 'test-task', task=emr_tasks.EmrAddStepTask('test-cluster-id', {'Key1': { 'Key2': 'Value2' }})) print_and_assert(default_task_json, task)
def test_emr_launch_function(): app = core.App() stack = core.Stack(app, 'test-stack') vpc = ec2.Vpc(stack, 'Vpc') success_topic = sns.Topic(stack, 'SuccessTopic') failure_topic = sns.Topic(stack, 'FailureTopic') profile = emr_profile.EMRProfile( stack, 'test-profile', profile_name='test-profile', vpc=vpc) configuration = cluster_configuration.ClusterConfiguration( stack, 'test-configuration', configuration_name='test-configuration') function = emr_launch_function.EMRLaunchFunction( stack, 'test-function', launch_function_name='test-function', emr_profile=profile, cluster_configuration=configuration, cluster_name='test-cluster', success_topic=success_topic, failure_topic=failure_topic, allowed_cluster_config_overrides=configuration.override_interfaces['default'], wait_for_cluster_start=False ) resolved_function = stack.resolve(function.to_json()) print(default_function) print(resolved_function) assert default_function == resolved_function
def test_terminate_cluster_builder(): default_task_json = { 'End': True, 'Parameters': { 'ClusterId': 'test-cluster-id' }, 'Type': 'Task', 'Resource': { 'Fn::Join': [ '', [ 'arn:', { 'Ref': 'AWS::Partition' }, ':states:::elasticmapreduce:terminateCluster.sync' ] ] } } stack = core.Stack(core.App(), 'test-stack') task = emr_tasks.TerminateClusterBuilder.build( stack, 'test-task', name='test-terminate-task', cluster_id='test-cluster-id', ) print_and_assert(default_task_json, task)
def test_determine_build_image_build_str(ecr_repo, build_image): """ Scenario: Target: Not set. Build: Specific config set, as str, should use this. Deploy: Specific config set, as str. Tests: Since the target is not set, it will determine that it is a build step. As specific config for the default build provider is set it should use these, not the deploy specific config. """ scope = core.Stack() target = None map_params = deepcopy(CODEBUILD_BASE_MAP_PARAMS) map_params['default_providers']['build'] = \ CODEBUILD_SPECIFIC_MAP_PARAMS_STR # Set deploy one to alternative, so we can test # that it is not using this in build steps map_params['default_providers']['deploy'] = \ CODEBUILD_SPECIFIC_MAP_PARAMS_ALT_STR result = CodeBuild.determine_build_image( scope=scope, target=target, map_params=map_params, ) assert result == getattr( _codebuild.LinuxBuildImage, SPECIFIC_CODEBUILD_IMAGE_STR, ) ecr_repo.from_repository_arn.assert_not_called() build_image.from_ecr_repository.assert_not_called()
def test_determine_build_image_deploy_defaults(ecr_repo, build_image): """ Scenario: Target: Set, no config. Build: Specific config set, as str. Build: No specifics, i.e. use defaults. Tests: Since the target is set, it will determine that it is a deploy step. As no specific config for the default deploy provider is set it should return the default config. """ scope = core.Stack() target = SIMPLE_TARGET map_params = deepcopy(CODEBUILD_BASE_MAP_PARAMS) # Set build one to alternative, so we can test # that it is not using this in deploy steps map_params['default_providers']['build'] = \ CODEBUILD_SPECIFIC_MAP_PARAMS_ALT_STR result = CodeBuild.determine_build_image( scope=scope, target=target, map_params=map_params, ) assert result == getattr( _codebuild.LinuxBuildImage, DEFAULT_CODEBUILD_IMAGE, ) ecr_repo.from_repository_arn.assert_not_called() build_image.from_ecr_repository.assert_not_called()
def test_add_step_builder(): default_task_json = { 'Resource': { 'Fn::Join': ['', ['arn:', { 'Ref': 'AWS::Partition' }, ':states:::elasticmapreduce:addStep.sync']] }, 'Parameters': { 'ClusterId': 'test-cluster-id', 'Step': { 'Name': 'test-step', 'ActionOnFailure': 'CONTINUE', 'HadoopJarStep': { 'Jar': 'Jar', 'MainClass': 'Main', 'Args': ['Arg1', 'Arg2'], 'Properties': [] } } }, 'End': True, 'Type': 'Task' } stack = core.Stack(core.App(), 'test-stack') task = emr_tasks.AddStepBuilder.build( stack, 'test-task', cluster_id='test-cluster-id', emr_step=emr_code.EMRStep('test-step', 'Jar', 'Main', ['Arg1', 'Arg2']), ) print_and_assert(default_task_json, task)
def test_start_execution_task(): default_task_json = { 'End': True, 'Parameters': { 'StateMachineArn': { 'Ref': 'teststatemachine7F4C511D' }, 'Input.$': '$$.Execution.Input' }, 'Type': 'Task', 'Resource': { 'Fn::Join': [ '', [ 'arn:', { 'Ref': 'AWS::Partition' }, ':states:::states:startExecution.sync' ] ] } } stack = core.Stack(core.App(), 'test-stack') state_machine = sfn.StateMachine(stack, 'test-state-machine', definition=sfn.Chain.start( sfn.Succeed(stack, 'Succeeded'))) task = sfn.Task(stack, 'test-task', task=emr_tasks.StartExecutionTask(state_machine, )) print_and_assert(default_task_json, task)
def test_package_using_subprocess(self) -> None: app = cdk.App(outdir=self.cdk_out_dir) stack = cdk.Stack(app, 'TestSubprocess') chalice = Chalice(stack, 'WebApi', source_dir=self.chalice_app_dir, stage_config=self.chalice_app_stage_config) template = self._synth_and_get_template(app, chalice) self._check_basic_asserts(chalice, template)
def test_package_using_docker_image_not_found(self) -> None: app = cdk.App(outdir=self.cdk_out_dir) stack = cdk.Stack(app, 'TestDockerImageNotFound') package_config = PackageConfig(use_container=True, image='cdk-chalice') with self.assertRaises(ChaliceError): Chalice(stack, 'WebApi', source_dir=self.chalice_app_dir, stage_config=self.chalice_app_stage_config, package_config=package_config)
def test_fail_chain(): default_fragment_json = { 'Type': 'Parallel', 'End': True, 'Branches': [{ 'StartAt': 'test-fragment: Failure Notification', 'States': { 'test-fragment: Failure Notification': { 'Next': 'test-fragment: Execution Failed', 'InputPath': '$', 'Parameters': { 'TopicArn': { 'Ref': 'testtopicB3D54793' }, 'Message': 'TestMessage', 'Subject': 'TestSubject' }, 'OutputPath': '$', 'Type': 'Task', 'Resource': { 'Fn::Join': [ '', [ 'arn:', { 'Ref': 'AWS::Partition' }, ':states:::sns:publish' ] ] }, 'ResultPath': '$.PublishResult' }, 'test-fragment: Execution Failed': { 'Type': 'Fail', 'Comment': 'TestComment', 'Error': 'TestError', 'Cause': 'TestCause' } } }] } stack = core.Stack(core.App(), 'test-stack') fragment = emr_chains.Fail(stack, 'test-fragment', message=sfn.TaskInput.from_text('TestMessage'), subject='TestSubject', topic=sns.Topic(stack, 'test-topic'), cause='TestCause', comment='TestComment', error='TestError') print_and_assert(default_fragment_json, fragment)
def test_package_using_docker(self) -> None: app = cdk.App(outdir=self.cdk_out_dir) stack = cdk.Stack(app, 'TestDocker') package_config = PackageConfig(use_container=True) chalice = Chalice(stack, 'WebApi', source_dir=self.chalice_app_dir, stage_config=self.chalice_app_stage_config, package_config=package_config) template = self._synth_and_get_template(app, chalice) self._check_basic_asserts(chalice, template)
def test_emr_lambdas(): app = core.App() stack = core.Stack(app, 'test-lambdas-stack') apis = Apis(stack, 'test-apis') assert apis.get_profile assert apis.get_profiles assert apis.get_configuration assert apis.get_configurations assert apis.get_function assert apis.get_functions
def test_emr_security_groups(): app = core.App() stack = core.Stack(app, 'test-stack') vpc = ec2.Vpc(stack, 'test-vpc') emr_security_groups = EMRSecurityGroups(stack, 'test-security-groups', vpc=vpc) assert emr_security_groups.service_group assert emr_security_groups.master_group assert emr_security_groups.workers_group
def __init__(self, scope: core.Construct, construct_id: str, deploy_flags: int, **kwargs): super().__init__(scope, construct_id, **kwargs) if deploy_flags == StackSwitches.NoStack: core.Stack(self, 'EmptyStack') return if deploy_flags & StackSwitches.WebServerExercisesStack == StackSwitches.WebServerExercisesStack: service = WebServerExercisesStack(self, 'WebServer', **kwargs) self.vpc_id = service.vpc_id self.public_subnet_id = service.public_subnet_id self.private_subnet_id = service.private_subnet_id if deploy_flags & StackSwitches.RDSExerciseStack == StackSwitches.RDSExerciseStack: RDSExerciseStack(self, 'RDS', **kwargs) if deploy_flags & StackSwitches.S3ExercisesStack == StackSwitches.S3ExercisesStack: S3ExercisesStack(self, 'S3Buckets', **kwargs) if deploy_flags & StackSwitches.DynamodbExerciseStack == StackSwitches.DynamodbExerciseStack: DynamodbExerciseStack(self, 'DynamoDB', **kwargs) if deploy_flags & StackSwitches.KMSKeyExerciseStack == StackSwitches.KMSKeyExerciseStack: kms_key = KMSKeyExerciseStack(self, 'KMSKey', **kwargs) self.key_id = kms_key.key_id if deploy_flags & StackSwitches.StaticSiteExerciseStack == StackSwitches.StaticSiteExerciseStack: static_site = StaticSiteExerciseStack(self, 'S3Site', **kwargs) self.bucket_url = static_site.url if deploy_flags & StackSwitches.AuthExercisesStack == StackSwitches.AuthExercisesStack: auth_stack = AuthExercisesStack(self, 'Auth', **kwargs) self.auth_vpc_id = auth_stack.vpc_id if deploy_flags & StackSwitches.MicroserviceExercisesStack == StackSwitches.MicroserviceExercisesStack: MicroserviceExercisesStack(self, 'Microservices', **kwargs) if deploy_flags & StackSwitches.LambdaExercisesStack == StackSwitches.LambdaExercisesStack: LambdaExercisesStack(self, 'Lambda', **kwargs) if deploy_flags & StackSwitches.StatelessAppExerciseStack == StackSwitches.StatelessAppExerciseStack: StatelessAppExerciseStack(self, 'StatelessApp', **kwargs) if deploy_flags & StackSwitches.MonitoringExercisesStack == StackSwitches.MonitoringExercisesStack: MonitoringExercisesStack(self, 'Monitoring', **kwargs) if deploy_flags & StackSwitches.OptimizationExercisesStack == StackSwitches.OptimizationExercisesStack: OptimizationExercisesStack(self, 'Optimization', **kwargs)
def test_run_job_flow_builder(): default_task_json = { 'End': True, 'Parameters': { 'FunctionName': { 'Ref': 'RunJobFlow9B18A53F' }, 'Payload': { 'ExecutionInput.$': '$$.Execution.Input', 'ClusterConfiguration.$': '$.ClusterConfiguration', 'TaskToken.$': '$$.Task.Token', 'CheckStatusLambda': { 'Fn::GetAtt': ['CheckClusterStatusA7C1019E', 'Arn'] }, 'RuleName': { 'Ref': 'testtaskEventRule9A04A93E' }, 'FireAndForget': False } }, 'Type': 'Task', 'Resource': { 'Fn::Join': [ '', [ 'arn:', { 'Ref': 'AWS::Partition' }, ':states:::lambda:invoke.waitForTaskToken' ] ] } } stack = core.Stack(core.App(), 'test-stack') task = emr_tasks.RunJobFlowBuilder.build( stack, 'test-task', roles=emr_profile.EMRRoles(stack, 'test-emr-roles', role_name_prefix='test-roles'), kerberos_attributes_secret=secretsmanager.Secret( stack, 'test-kerberos-secret'), secret_configurations={ 'Secret': secretsmanager.Secret(stack, 'test-secret-configurations-secret') }, ) print_and_assert(default_task_json, task)
def test_determine_build_image_deploy_ecr_no_tag_too(ecr_repo, build_image): """ Scenario: Target: Specific config set, as ECR dict, should use these, but has no specific tag set, so should use 'latest'. Build: Specific config set, as str. Deploy: Specific config set, as ECR dict. Tests: Since the target is set, it will determine that it is a deploy step. As specific config for the target is set it should use these with ECR, not the default build or deploy specific config. Plus setting the 'latest' default tag, as that is not specified. """ scope = core.Stack() target = deepcopy(CODEBUILD_SPECIFIC_MAP_PARAMS_ECR) target['properties']['image']['repository_arn'] = 'arn:other:one' del target['properties']['image']['tag'] map_params = deepcopy(CODEBUILD_BASE_MAP_PARAMS) map_params['default_providers']['deploy'] = deepcopy( CODEBUILD_SPECIFIC_MAP_PARAMS_ECR ) # Set build one to alternative, so we can test # that it is not using this in deploy steps map_params['default_providers']['build'] = \ CODEBUILD_SPECIFIC_MAP_PARAMS_ALT_STR from_repo_arn_return_value = {'Some': 'Value'} ecr_repo.from_repository_arn.return_value = from_repo_arn_return_value from_ecr_repo_return_value = {'Another': 'Object'} build_image.from_ecr_repository.return_value = from_ecr_repo_return_value result = CodeBuild.determine_build_image( scope=scope, target=target, map_params=map_params, ) assert result == from_ecr_repo_return_value ecr_repo.from_repository_arn.assert_called_once_with( scope, 'custom_repo', target['properties']['image']['repository_arn'], ) build_image.from_ecr_repository.assert_called_once_with( from_repo_arn_return_value, 'latest', )
def test_emr_security_groups(): app = core.App() stack = core.Stack(app, 'test-stack') artifacts_bucket = s3.Bucket(stack, 'test-artifacts-bucket') logs_bucket = s3.Bucket(stack, 'test-logs-bucket') emr_roles = EMRRoles(stack, 'test-emr-components', role_name_prefix='TestCluster', artifacts_bucket=artifacts_bucket, logs_bucket=logs_bucket) assert emr_roles.service_role assert emr_roles.instance_role assert emr_roles.autoscaling_role
def test_get_function(self): stack = core.Stack(core.App(), 'test-stack', env=core.Environment(account='123456789012', region='us-east-1')) vpc = ec2.Vpc.from_lookup(stack, 'test-vpc', vpc_id='vpc-12345678') success_topic = sns.Topic(stack, 'SuccessTopic') failure_topic = sns.Topic(stack, 'FailureTopic') profile = emr_profile.EMRProfile( stack, 'test-profile', profile_name='test-profile', vpc=vpc) configuration = cluster_configuration.ClusterConfiguration( stack, 'test-configuration', configuration_name='test-configuration') function = emr_launch_function.EMRLaunchFunction( stack, 'test-function', launch_function_name='test-function', emr_profile=profile, cluster_configuration=configuration, cluster_name='test-cluster', description='test description', success_topic=success_topic, failure_topic=failure_topic, allowed_cluster_config_overrides=configuration.override_interfaces['default'], wait_for_cluster_start=False ) ssm = boto3.client('ssm') ssm.put_parameter( Name=f'{emr_profile.SSM_PARAMETER_PREFIX}/{profile.namespace}/{profile.profile_name}', Value=json.dumps(profile.to_json())) ssm.put_parameter( Name=f'{cluster_configuration.SSM_PARAMETER_PREFIX}/' f'{configuration.namespace}/{configuration.configuration_name}', Value=json.dumps(configuration.to_json())) ssm.put_parameter( Name=f'{emr_launch_function.SSM_PARAMETER_PREFIX}/{function.namespace}/{function.launch_function_name}', Value=json.dumps(function.to_json())) restored_function = emr_launch_function.EMRLaunchFunction.from_stored_function( stack, 'test-restored-function', namespace=function.namespace, launch_function_name=function.launch_function_name, ) self.assertEquals(function.to_json(), restored_function.to_json())
def test_determine_build_image_deploy_ecr(ecr_repo, build_image): """ Scenario: Target: Set, no specific config. Build: Specific config set, as str. Deploy: Specific config set, as ECR dict, should use this. Tests: Since the target is set, it will determine that it is a deploy step. As specific config for the default deploy provider is set it should use these with ECR, not the build specific config. Plus setting the 'specific' tag, as that is specified. """ scope = core.Stack() target = SIMPLE_TARGET map_params = deepcopy(CODEBUILD_BASE_MAP_PARAMS) map_params['default_providers']['deploy'] = \ CODEBUILD_SPECIFIC_MAP_PARAMS_ECR # Set build one to alternative, so we can test # that it is not using this in deploy steps map_params['default_providers']['build'] = \ CODEBUILD_SPECIFIC_MAP_PARAMS_ALT_STR from_repo_arn_return_value = {'Some': 'Value'} ecr_repo.from_repository_arn.return_value = from_repo_arn_return_value from_ecr_repo_return_value = {'Another': 'Object'} build_image.from_ecr_repository.return_value = from_ecr_repo_return_value result = CodeBuild.determine_build_image( scope=scope, target=target, map_params=map_params, ) assert result == from_ecr_repo_return_value ecr_repo.from_repository_arn.assert_called_once_with( scope, 'custom_repo', SPECIFIC_CODEBUILD_IMAGE_ECR.get('repository_arn'), ) build_image.from_ecr_repository.assert_called_once_with( from_repo_arn_return_value, SPECIFIC_CODEBUILD_IMAGE_ECR.get('tag'), )
def test_fail_if_cluster_running_builder(): default_task_json = { 'End': True, 'Parameters': { 'ExecutionInput.$': '$$.Execution.Input', 'DefaultFailIfClusterRunning': True, 'ClusterConfiguration.$': '$.ClusterConfiguration.Cluster' }, 'OutputPath': '$', 'Type': 'Task', 'Resource': { 'Fn::GetAtt': ['FailIfClusterRunningC0A7FE52', 'Arn'] }, 'ResultPath': '$.ClusterConfiguration.Cluster' } stack = core.Stack(core.App(), 'test-stack') task = emr_tasks.FailIfClusterRunningBuilder.build( stack, 'test-task', default_fail_if_cluster_running=True) print_and_assert(default_task_json, task)
def __init__( self, scope: cdk.Construct, id_: str, data_project: str, workflow_projects: List[str], ica_base_url: str, slack_host_ssm_name: str, slack_webhook_ssm_name: str, **kwargs: Any, ): """ Represents the deployment of our stack(s) to a particular environment with a particular set of settings. Args: scope: id_: data_project: workflow_projects: ica_base_url: slack_host_ssm_name: slack_webhook_ssm_name: **kwargs: """ super().__init__(scope, id_, **kwargs) stateful = cdk.Stack(self, "stack") # this name becomes the prefix of our secrets so we slip in the word ICA to make it # obvious when someone sees them that they are associated with ICA Secrets( stateful, "IcaSecrets", data_project, workflow_projects, ica_base_url, slack_host_ssm_name, slack_webhook_ssm_name, )
def test_load_cluster_configuration_builder(): default_task_json = { 'End': True, 'Retry': [{ 'ErrorEquals': ['Lambda.ServiceException', 'Lambda.AWSLambdaException', 'Lambda.SdkClientException'], 'IntervalSeconds': 2, 'MaxAttempts': 6, 'BackoffRate': 2 }], 'Type': 'Task', 'Resource': { 'Fn::GetAtt': ['testtaskLoadClusterConfiguration518ECBAD', 'Arn'] }, 'Parameters': { 'ClusterName': 'test-cluster', 'ClusterTags': [{ 'Key': 'Key1', 'Value': 'Value1' }], 'ProfileNamespace': 'test', 'ProfileName': 'test-profile', 'ConfigurationNamespace': 'test', 'ConfigurationName': 'test-configuration' } } stack = core.Stack(core.App(), 'test-stack') task = emr_tasks.LoadClusterConfigurationBuilder.build( stack, 'test-task', cluster_name='test-cluster', cluster_tags=[core.Tag('Key1', 'Value1')], profile_namespace='test', profile_name='test-profile', configuration_namespace='test', configuration_name='test-configuration', ) print_and_assert(default_task_json, task)
def test_update_cluster_tags_builder(): default_task_json = { 'End': True, 'Parameters': { 'ExecutionInput.$': '$$.Execution.Input', 'ClusterConfiguration.$': '$.ClusterConfiguration.Cluster' }, 'OutputPath': '$', 'Type': 'Task', 'Resource': { 'Fn::GetAtt': ['UpdateClusterTags9DD0067C', 'Arn'] }, 'ResultPath': '$.ClusterConfiguration.Cluster' } stack = core.Stack(core.App(), 'test-stack') task = emr_tasks.UpdateClusterTagsBuilder.build( stack, 'test-task', ) print_and_assert(default_task_json, task)
def test_load_cluster_configuration_builder(): default_task_json = { 'End': True, 'OutputPath': '$', 'Parameters': { 'ClusterName': 'test-cluster', 'ClusterTags': [{ 'Key': 'Key1', 'Value': 'Value1' }], 'ConfigurationName': 'test-configuration', 'ConfigurationNamespace': 'test', 'ProfileName': 'test-profile', 'ProfileNamespace': 'test' }, 'Resource': { 'Fn::GetAtt': ['testtaskLoadClusterConfiguration518ECBAD', 'Arn'] }, 'ResultPath': '$.ClusterConfiguration', 'Type': 'Task' } stack = core.Stack(core.App(), 'test-stack') task = emr_tasks.LoadClusterConfigurationBuilder.build( stack, 'test-task', cluster_name='test-cluster', cluster_tags=[core.Tag('Key1', 'Value1')], profile_namespace='test', profile_name='test-profile', configuration_namespace='test', configuration_name='test-configuration', ) print_and_assert(default_task_json, task)
#!/usr/bin/env python3 from aws_cdk import aws_ecs, core app = core.App() stack = core.Stack(app) aws_ecs.Cluster( stack, cluster_name='mjlCluster', id='ecs', ) app.synth()
from aws_cdk import ( aws_ec2 as ec2, aws_ecs as ecs, aws_elasticloadbalancingv2 as elbv2, core, ) app = core.App() stack = core.Stack(app, "aws-ec2-integ-ecs") # Create a cluster vpc = ec2.Vpc(stack, "MyVpc", max_azs=2) cluster = ecs.Cluster(stack, 'EcsCluster', vpc=vpc) cluster.add_capacity("DefaultAutoScalingGroup", instance_type=ec2.InstanceType("t2.micro")) # Create Task Definition task_definition = ecs.Ec2TaskDefinition(stack, "TaskDef") container = task_definition.add_container( "web", image=ecs.ContainerImage.from_registry("nginx:latest"), memory_limit_mib=256) port_mapping = ecs.PortMapping(container_port=80, host_port=8080, protocol=ecs.Protocol.TCP) container.add_port_mappings(port_mapping) # Create Service service = ecs.Ec2Service(stack, "Service", cluster=cluster, task_definition=task_definition) # Create ALB lb = elbv2.ApplicationLoadBalancer(stack, "LB", vpc=vpc, internet_facing=True) listener = lb.add_listener("PublicListener", port=80, open=True)
from aws_cdk import aws_codebuild as codebuild from aws_cdk import aws_codepipeline as codepipeline from aws_cdk import aws_codepipeline_actions as codepipeline_actions from aws_cdk import aws_codestarnotifications as notifications from aws_cdk import aws_iam as iam from aws_cdk import aws_s3 as s3 from aws_cdk import core app = core.App() pipeline_params = app.node.try_get_context('release-pipeline') deployment_secret = pipeline_params['deployment-secret'] stack = core.Stack( app, 'EMRLaunchReleaseDeploymentPipeline', env=core.Environment( account=os.environ["CDK_DEFAULT_ACCOUNT"], region=os.environ["CDK_DEFAULT_REGION"])) artifacts_bucket = s3.Bucket(stack, 'ArtifactsBucket') deployment_bucket = s3.Bucket.from_bucket_name( stack, 'DeploymentBucket', core.Token.as_string(core.SecretValue.secrets_manager( secret_id=deployment_secret['secret-id'], json_field=deployment_secret['json-fields']['deployment-bucket']))) source_output = codepipeline.Artifact('SourceOutput') release_output = codepipeline.Artifact('ReleaseOutput') code_build_role = iam.Role( stack, 'EMRLaunchReleaseBuildRole', role_name='EMRLaunchReleaseBuildRole', assumed_by=iam.ServicePrincipal('codebuild.amazonaws.com'),