App-FargateStack

 view release on metacpan or  search on metacpan

lib/App/FargateStack.pm  view on Meta::CPAN

sub cmd_service_status {
########################################################################
  my ( $self, @args ) = @_;

  my $service_name = $self->check_service_name( @args, $self->get_args );

  my ( $cluster, $tasks ) = $self->common_args(qw(cluster tasks));

  my $cluster_name = $cluster->{name};

  $self->verify_service($service_name);

  require Text::Wrap;
  Text::Wrap->import('wrap');

  {
    ## no critic
    no warnings 'once';
    $Text::Wrap::columns = 100;
  }

lib/App/FargateStack.pm  view on Meta::CPAN


  my ( $task_name, $err ) = $self->get_default_service_name();

  die "usage: %s remove-service task-name\n", $ENV{SCRIPT_NAME}
    if !$task_name || $err;

  my ( $config, $cluster, $dryrun ) = $self->common_args(qw(config cluster dryrun));

  my $cluster_name = $cluster->{name};

  $self->verify_service($task_name);

  $self->check_task( $task_name, 'warn' );

  $self->log_warn( 'remove-service: task [%s] will be deleted...%s', $task_name, $dryrun );

  return $SUCCESS
    if $dryrun;

  my $ecs = $self->fetch_ecs;

  my $result = $ecs->delete_service( $cluster->{name}, $task_name );
  $ecs->check_result( message => 'ERROR: could not stop service %s', $task_name );

  return $SUCCESS;
}

########################################################################
sub verify_service {
########################################################################
  my ( $self, $service_name ) = @_;

  my ( $cluster, $config ) = $self->common_args(qw(cluster config));

  my $cluster_name //= $cluster->{name};

  my $ecs = $self->fetch_ecs;

  my $services = $ecs->list_services( $cluster_name, 'serviceArns' );

lib/App/FargateStack.pm  view on Meta::CPAN

sub cmd_update_service {
########################################################################
  my ( $self, @args ) = @_;

  my $service_name = $self->check_service_name( @args, $self->get_args );

  my ($cluster) = $self->common_args(qw(cluster));

  my $cluster_name = $cluster->{name};

  $self->verify_service($service_name);

  my $ecs = $self->fetch_ecs;

  my $task_definition_arn = $self->get_latest_task_definition($service_name);

  my @elems = qw(status running_count desired_count pending_count task_definition);

  my $result = $ecs->update_service(
    cluster_name    => $cluster_name,
    service_name    => $service_name,

lib/App/FargateStack.pm  view on Meta::CPAN


########################################################################
sub update_task_count {
########################################################################
  my ( $self, $task_name, $desired_count ) = @_;

  my ( $config, $cluster ) = $self->common_args(qw(config cluster));

  my $cluster_name = $cluster->{name};

  $self->verify_service($task_name);

  my $ecs = $self->get_ecs;

  my $result = $ecs->update_service(
    cluster_name  => $cluster_name,
    desired_count => $desired_count,
    service_name  => $task_name,
  );

  log_die( $self, "ERROR: could not update service: [%s]\n%s", $task_name, $ecs->get_error )

lib/App/FargateStack/Autoscaling.pm  view on Meta::CPAN

  my ( $task_name, @args ) = $self->_get_autoscaling_task_name($tasks);

  croak
    "usage: add-scheduled-action [task] name start-time end-time days min-capacity max-capacity (ex: 00:18 00:02 MON-FRI 2/1 2/2)\n"
    if @args != 6;

  my $schedule_name = shift @args;

  my $scheduled = $tasks->{$task_name}->{autoscaling}->{scheduled} // {};

  # plan will verify these values
  $scheduled->{$schedule_name} = {
    start_time   => $args[0],
    end_time     => $args[1],
    days         => $args[2],
    min_capacity => $args[3],
    max_capacity => $args[4],
  };

  my $autoscaling_config = App::FargateStack::AutoscalingConfig->new(
    config    => $tasks->{$task_name}->{autoscaling},
    task_name => $task_name
  );

  $self->update_config;

  print {*STDOUT} sprintf "Scheduled action: [%s] added to your configuration. Run plan to verify the configuration.\n",
    $schedule_name;

  return $SUCCESS;
}

########################################################################
sub cmd_add_scaling_policy {
########################################################################
  my ($self) = @_;

lib/App/FargateStack/Autoscaling.pm  view on Meta::CPAN

    config             => $tasks->{$task_name}->{autoscaling},
    task_name          => $task_name,
    metric             => sprintf( '%s:%s', @args[ 0, 1 ] ),
    min_capacity       => $args[2],
    max_capacity       => $args[3],
    scale_out_cooldown => $args[4],
    scale_in_cooldown  => $args[5],
    policy_name        => $self->create_default( 'autoscaling-policy-name', $task_name ),
  );

  print {*STDOUT} sprintf "Scaling policy: [%s] added to your configuration. Run plan to verify the configuration.\n",
    $autoscaling_config->get_policy_name;

  $self->update_config;

  return $SUCCESS;
}

1;

lib/App/FargateStack/Builder/HTTPService.pm  view on Meta::CPAN

  }

  if ( !$security_groups ) {
    $security_groups = $config->{security_groups} = {};
    $config->{security_groups} = $security_groups;
  }

  my $elb = $self->fetch_elbv2();
  my $ec2 = $self->fetch_ec2;

  # if we have defined one in the config, verify
  if ( my $alb_arn = $alb->{arn} ) {

    my $alb_info = $elb->describe_load_balancer( $alb_arn, 'LoadBalancers[0]' );
    $elb->check_result( message => 'ERROR: could not describe load balancer: [%s]', $alb_arn );

    $self->set_alb($alb_info);

    my ( $alb_name, $alb_security_groups ) = @{$alb_info}{qw(LoadBalancerName SecurityGroups)};

    $self->log_trace( sub { return Dumper( [ alb => $alb_info ] ); } );

lib/App/FargateStack/Checker.pm  view on Meta::CPAN

  }

  my @services = qw(ecs-tasks.amazonaws.com events.amazonaws.com);

  my %decisions_by_service;

  foreach my $svc (@services) {
    my $result = eval { _simulate_passrole_once( $iam, $policy_source_arn, $role_arns, $svc ) };
    if ( $EVAL_ERROR || !$result ) {
      # If org blocks simulation, warn rather than fail
      return row_warn( 'iam:PassRole', 'Simulation not permitted; verify PassRole manually' );
    }

    # result is an arrayref of EvalDecision strings: allowed | explicitDeny | implicitDeny
    my @dec = @{ $result || [] };
    $decisions_by_service{$svc} = \@dec;
  }

  # Aggregate decisions: any explicitDeny -> FAIL
  # otherwise any implicitDeny -> WARN
  # otherwise all allowed -> PASS

lib/App/FargateStack/Checker.pm  view on Meta::CPAN

=head1 NAME

app-FargateStack-env.pl - Preflight checker for ECS Fargate environments

=head1 USAGE

  app-FargateStack-env.pl [options]

=head1 DESCRIPTION

Runs read-only checks against the target AWS account and region to verify
that common ECS Fargate deployment scenarios are feasible. Produces an
ASCII table with PASS/WARN/FAIL rows and a capabilities summary for:

  - HTTP services
  - HTTPS service
  - Scheduled tasks
  - One-shot tasks
  - Daemon services

No resources are created or modified. Intended as a fast “can I deploy here?”

share/ChangeLog  view on Meta::CPAN

	* lib/App/ECS.pm.in
	(list_task)
	- allow hash ref of args to support desired-status
	(update-service): + query
	* lib/App/FargateStack.pm.in
	(cmd_service_status)
	- refactoring
	- maybecolor
	- display task status too
	(cmd_display_task_status): new
	(cmd_remove_service): verify_service just takes task-name
	(update_task_count): likewise
	(verify_service): just accept task-name
	(get_task_image_digests): new
	(get_latest_task_definition): new
	(cmd_update_service): new
	(cmd_start_stop_service): renamed from cmd_update_service
	(cmd_list_tasks)
	- refactoring
	- color
	- stopped reason
	(fetch_option_defaults)
	- set config name

share/ChangeLog  view on Meta::CPAN

	- return boolean
	- whitespace
	(get_task_status)
	- refactoring
	(get_default_service_name)
	- refactoring
	(cmd_create_service)
	- refactoring
	- allow count
	(cmd_remove_service): die don't croak
	(verify_service): likewise
	(cmd_update_service): likewise
	(cmd_register_task_definition)
	- likewise
	- check_result
	(get_latest_image): fetch_ecr
	(cmd_stop_task): croak don't die
	(cmd_list_tasks): likewise
	(cmd_delete_schedule): likewise
	(cmd_delete_task): likewise
	(cmd_delete_daemon): likewise

share/ChangeLog  view on Meta::CPAN

	- refactoring
	- support --subnet-id arg
	- check that we running latest image
	(check_latest_image): new
	(get_default_service_name): new
	(cmd_create_service)
	- refactoring
	- check if running latest image
	(cmd_delete_service)
	- refactoring
	- verify service
	(verify_service): new
	(update_task_count): renamed from _update_task_count()
	(cmd_register)
	- refactoring
	- $task_definition, not $task_definition_arn
	(get_latest_image): new
	(cmd_stop_task): refactoring
	(cmd_redeploy): new
	(main)
	- + --force option to run task on old image, --subnet-id
	* lib/App/FargateStack/Builder/Service.pm.in



( run in 0.668 second using v1.01-cache-2.11-cpan-e1769b4cff6 )