コード例 #1
0
    def __init__(self, scope: core.Construct, id: str, cluster: ecs.ICluster,
                 repo: ecr.IRepository, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # service skeleton
        streamproc_task_definition = ecs_patterns.ScheduledFargateTask(
            scope=self,
            id="SftpTaskDef",
            cluster=cluster,
            desired_task_count=1,
            schedule=applicationautoscaling.Schedule.rate(
                duration=core.Duration.minutes(5)),
            scheduled_fargate_task_image_options=ecs_patterns.
            ScheduledFargateTaskImageOptions(
                image=ecs.ContainerImage.from_ecr_repository(repository=repo,
                                                             tag='latest'),
                cpu=1024,
                memory_limit_mib=2048))
        streamproc_task_definition.task_definition.task_role.add_to_policy(
            statement=iam.PolicyStatement(
                resources=['*'],
                actions=[
                    'servicediscovery:DiscoverInstances',
                    'secretsmanager:Get*', 'ec2:Describe*'
                ]))
        ssm.StringParameter(scope=self,
                            id='SSMParamSftpImageName',
                            string_value=streamproc_task_definition.
                            task_definition.default_container.container_name,
                            parameter_name='image_sftp')
コード例 #2
0
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        self.scheduled_task_fargate = aws_ecs_patterns.ScheduledFargateTask(
            self,
            "ScheduledQueueTask",
            scheduled_fargate_task_image_options=aws_ecs_patterns.
            ScheduledFargateTaskImageOptions(
                image=aws_ecs.ContainerImage.from_asset(
                    directory='.',
                    file='Dockerfile.queue_service',
                    exclude=["cdk.out"]),
                command=["/queue_service.py", "send"],
                environment={
                    'QUEUE_NAME':
                    'queue-fargate-QueueServiceEcsProcessingQueue354FA9E5-1GJOWKT1W18XX'
                },
            ),
            schedule=aws_applicationautoscaling.Schedule.rate(
                core.Duration.seconds(60)))

        #DYNAMICALLY PULL THIS DOWN
        sqs_queue = aws_sqs.Queue.from_queue_arn(
            self, "Queue",
            "arn:aws:sqs:us-west-2:123:queue-fargate-QueueServiceEcsProcessingQueue354FA9E5-1GJOWKT1W18XX"
        )

        sqs_queue.grant_send_messages(
            self.scheduled_task_fargate.task_definition.task_role)
コード例 #3
0
    def __init__(self, scope: core.Construct, construct_id: str,
                 **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        #vpc
        batch_process_vpc = aws_ec2.Vpc(self,
                                        "BatchProcessVpc",
                                        max_azs=2,
                                        nat_gateways=1)

        #fargate cluster
        fargate_batch_process_cluster = aws_ecs.Cluster(self,
                                                        "BatchProcessCluster",
                                                        vpc=batch_process_vpc)

        #fargate with cloudwatch events rules
        batch_process_events = aws_ecs_patterns.ScheduledFargateTask(
            self,
            "BatchProcessEvent",
            cluster=fargate_batch_process_cluster,
            scheduled_fargate_task_image_options={
                "image":
                aws_ecs.ContainerImage.from_registry(
                    "manuja/demo-batch-process:latest"),
                "memory_limit_mib":
                512,
                "cpu":
                256,
                "environment": {
                    "name": "TRIGGER",
                    "value": "cloudwatch events"
                }
            },
            schedule=Schedule.expression("rate(2 minutes)"))
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Add your stack resources below):
        # Create VPC
        vpc = _ec2.Vpc(self, "batchProcessorVpc", max_azs=2, nat_gateways=1)

        # Create Fargate Cluster
        batch_processor_cluster = _ecs.Cluster(self,
                                               "batchProcessorCluster",
                                               vpc=vpc)

        # Deploy Batch Processing Container Task in Fargate with Cloudwatch Event Schedule
        batch_process_task = _ecs_patterns.ScheduledFargateTask(
            self,
            "batchProcessor",
            cluster=batch_processor_cluster,
            scheduled_fargate_task_image_options={
                "image":
                _ecs.ContainerImage.from_registry("mystique/batch-job-runner"),
                "memory_limit_mib":
                512,
                "cpu":
                256,
                "environment": {
                    "name": "TRIGGEr",
                    "value": "CloudWatch Events"
                }
            },
            schedule=Schedule.expression("rate(2 minutes)"))
コード例 #5
0
    def __configure_fundamentals(self) -> None:
        """
    Configure the daily check for fundamental data data.
    """
        fundamental_definition = AmeritradeTask(
            self,
            'FundamentalTask',
            context=self.context,
            entry_point=["/usr/bin/python3", "/app/get_fundamentals.py"],
            directory=path.join(src_root_dir, 'src/collectors'),
            repository_name='finsurf-pm-fundamentals',
            env_vars={'STREAM_NAME': self.quotes_stream.stream_name})

        self.fundamental_stream.grant_write(
            fundamental_definition.task_definition.task_role)

        #fundamental_definition.add_kinesis_subscription(stream=self.fundamental_stream

        self.fundamental_svc = ecs.FargateService(
            self,
            'FundamentalSvc',
            cluster=self.pm_compute_cluster,
            assign_public_ip=False,
            desired_count=0,
            security_group=self.security_group,
            service_name='finsurf-pm-fundamental',
            vpc_subnets=ec2.SubnetSelection(subnet_group_name='Collections'),
            task_definition=fundamental_definition.task_definition)

        sft = ecsp.ScheduledFargateTask(
            self,
            'FundamentalsTask',
            schedule=scale.Schedule.cron(hour="22", minute="0", week_day="6"),
            cluster=self.pm_compute_cluster,
            desired_task_count=1,
            scheduled_fargate_task_definition_options=ecsp.
            ScheduledFargateTaskDefinitionOptions(
                task_definition=fundamental_definition.task_definition),
            subnet_selection=ec2.SubnetSelection(
                subnet_group_name='Collections'),
            vpc=self.vpc)
コード例 #6
0
    def make_fargate_scheduled_task(
            self, scheduled_task_name: str, task_definition_description: str,
            task_ecr_repo: object, cloudwatch_loggroup_name: str,
            container_commands: list, container_secrets: dict,
            scheduled_task_description: str,
            scheduled_task_cron_expression: str):
        '''
            Creates a Fargate Task definition, then scheduled task and associates it
            with the ECS cluster, applied tags, etc.

            Parameters
            ----------
            scheduled_task_name : str
                The name of the contsruct being created. Used to form the names
                of the various resources
            task_definition_description : str
                Description used for tags
            cloudwatch_loggroup_name : str
                Name of log group used by the container
            container_commands : str
                List of commands supplied to the container
            container_secrets : str
                Secrets supplied to the container
            scheduled_task_description : str
                Description used for tags
            scheduled_task_cron_expression : str
                Task schedule's chron expresion
        '''

        task_definition_name = "%s-%s-task-definition" % (
            self.APPLICATION_PREFIX, scheduled_task_name)
        fargate_task = ecs.FargateTaskDefinition(
            self,
            task_definition_name,
            cpu=512,
            memory_limit_mib=1024,
            execution_role=self.ecs_task_exec_role,
            family=None,
            task_role=self.props['ecs_task_role'],
        )

        fargate_task.add_container(
            "%s-%s-container" % (self.APPLICATION_PREFIX, scheduled_task_name),
            image=ecs.ContainerImage.from_ecr_repository(
                task_ecr_repo, "latest"),
            logging=ecs.LogDriver.aws_logs(
                stream_prefix=self.APPLICATION_PREFIX,
                log_group=logs.LogGroup(
                    self,
                    "%s-%s-cloudwatch-loggroup" %
                    (self.APPLICATION_PREFIX, scheduled_task_name),
                    log_group_name="%s%s" %
                    (self.APPLICATION_PREFIX, cloudwatch_loggroup_name),
                    retention=logs.RetentionDays.ONE_MONTH,
                    removal_policy=core.RemovalPolicy.DESTROY)),
            command=container_commands,
            secrets=container_secrets)
        util.tag_resource(fargate_task, task_definition_name,
                          task_definition_description)

        scheduled_task_name = "%s-%s-scheduled-task" % (
            self.APPLICATION_PREFIX, scheduled_task_name)
        ecs_sched_task = ecs_patterns.ScheduledFargateTask(
            self,
            scheduled_task_name,
            scheduled_fargate_task_definition_options=ecs_patterns.
            ScheduledFargateTaskDefinitionOptions(
                task_definition=fargate_task),
            schedule=asg.Schedule.expression(scheduled_task_cron_expression),
            cluster=self.props['ecs_fargate_task_cluster'],
            vpc=self.props['ecs_fargate_task_cluster'],
            subnet_selection=ec2.SubnetSelection(
                subnet_type=ec2.SubnetType(ec2.SubnetType.PUBLIC)))

        util.tag_resource(ecs_sched_task, scheduled_task_name,
                          scheduled_task_description)