Skip to content

jjeanjacques10/springboot-ecs-fargate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot + ECS + Fargate



Report Bug · Request Feature

Jean Jacques Barros Repository size GitHub last commit License GitHub Pull Requests Stargazers

Integration between Spring Boot and AWS Elastic Container Service (Fargate)

Config Docker

Build Image

docker build -t digimonapi:latest "."

Run Container using image created

docker run -d -p 80:80 -t digimonapi:latest

Cloudformation

Use file template.yml to create that resources:

  • Cluster
  • TaskDefinition
  • Service
  • Security Group
  • Load Balancer
  • CloudWatch
Service:
  Type: "AWS::ECS::Service"
  Properties:
    ServiceName: !Sub service-${FeatureName}-${MicroServiceName}
    <...>
    CapacityProviderStrategy:
      - CapacityProvider: FARGATE_SPOT
        Weight: 5
      - CapacityProvider: FARGATE
        Weight: 1
    <...>

AutoScaling

Config AutoScaling to scale up and down the service. Use template.yml to create that resources:

ScalableTarget:
  Type: AWS::ApplicationAutoScaling::ScalableTarget
  DependsOn: Service
  Properties:
    MinCapacity: 2
    MaxCapacity: 6
    ResourceId: !Join
      - "/"
      - - service
        - !Ref EcsClusterName
        - !GetAtt Service.Name
    RoleARN: !GetAtt AutoScalingRole.Arn
    ScalableDimension: ecs:service:DesiredCount
    ServiceNamespace: ecs

ScalingPolicy:
  Type: AWS::ApplicationAutoScaling::ScalingPolicy
  Properties:
    PolicyName: !Sub "${FeatureName}-auto-scaling-policy"
    PolicyType: TargetTrackingScaling
    ScalingTargetId: !Ref ScalableTarget
    TargetTrackingScalingPolicyConfiguration:
      PredefinedMetricSpecification:
        PredefinedMetricType: ECSServiceAverageCPUUtilization
      TargetValue: 30.0

It's configured to scale up and down the service when the CPU usage is greater than 30%.

Scheduled Scaling

Config Scheduled Scaling to scale up and down the service. Use template.yml to create that resources:

ScalableTarget:
  <...>
  ScheduledActions:
    - ScalableTargetAction:
        MinCapacity: 0
        MaxCapacity: 0
      Schedule: 'cron(0 0 22 ? * MON-FRI)'
      ScheduledActionName: scale-down
    - ScalableTargetAction:
        MinCapacity: 2
        MaxCapacity: 6
      Schedule: 'cron(0 0 11 ? * MON-FRI)'
      ScheduledActionName: scale-up

Articles

These are my articles about ECS Fargate using Spot instance and AutoScaling with ECS.

CodeBuild Notes

  • Add ECR permissions to codeBuild.
  • Error - "You have reached your pull rate limit"

Developed by Jean Jacques Barros