def _create_autoscaling_group()

in ec2-provider/ec2_provider/todo_app_stack.py [0:0]


    def _create_autoscaling_group(self, ddb_table: dynamodb.Table) -> autoscaling.AutoScalingGroup:
        """Creates an Autoscaling group for the Todo application"""
        role = iam.Role(
            self,
            'todo-instance-role',
            assumed_by=iam.ServicePrincipal("ec2.amazonaws.com"),
        )
        role.add_to_policy(
            iam.PolicyStatement(
                resources=[ddb_table.table_arn],
                actions=[
                    "dynamodb:GetItem",
                    "dynamodb:PutItem",
                    "dynamodb:Scan",
                ]
            )
        )

        return autoscaling.AutoScalingGroup(
            self,
            "todo-asg",
            vpc=self._vpc,
            instance_type=ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
            machine_image=self._get_image(),
            user_data=self._get_user_data(),
            security_group=self._create_sg(),
            role=role,
            vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PRIVATE),
            desired_capacity=2,
        )