1
0
mirror of https://github.com/ebosas/microservices.git synced 2025-06-24 22:26:56 +02:00

Combine Fargate and EC2 services

This commit is contained in:
ebosas
2021-11-13 16:39:06 +02:00
parent da53ff6e38
commit ac968e072e
2 changed files with 107 additions and 107 deletions

View File

@ -4,23 +4,19 @@ Parameters:
EnvironmentName: EnvironmentName:
Type: String Type: String
Default: production Default: production
Description: "A friendly environment name that will be used for namespacing all cluster resources. Example: staging, qa, or production" Description: A friendly environment name that will be used for namespacing all cluster resources, like staging, qa, or production
InstanceType: InstanceType:
Type: String Type: String
Default: t2.micro Default: t2.micro
Description: Class of EC2 instance used to host containers. Choose t2 for testing, m5 for general purpose, c5 for CPU intensive services, and r5 for memory intensive services Description: Class of EC2 instance used to host containers
AllowedValues: [ t2.micro, t2.small, t2.medium, t2.large, t2.xlarge, t2.2xlarge, AllowedValues: [ t2.micro, t2.small, t2.medium, t2.large, t2.xlarge, t2.2xlarge ]
m5.large, m5.xlarge, m5.2xlarge, m5.4xlarge, m5.12xlarge, m5.24xlarge,
c5.large, c5.xlarge, c5.2xlarge, c5.4xlarge, c5.9xlarge, c5.18xlarge,
r5.large, r5.xlarge, r5.2xlarge, r5.4xlarge, r5.12xlarge, r5.24xlarge ]
ConstraintDescription: Please choose a valid instance type.
DesiredCapacity: DesiredCapacity:
Type: Number Type: Number
Default: '1' Default: 1
Description: Number of EC2 instances to launch in your ECS cluster. Description: Number of EC2 instances to launch in your ECS cluster.
MaxSize: MaxSize:
Type: Number Type: Number
Default: '3' Default: 3
Description: Maximum number of EC2 instances that can be launched in your ECS cluster. Description: Maximum number of EC2 instances that can be launched in your ECS cluster.
ECSAMI: ECSAMI:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id> Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
@ -123,7 +119,7 @@ Resources:
# Role for the EC2 hosts. This allows the ECS agent on the EC2 hosts # Role for the EC2 hosts. This allows the ECS agent on the EC2 hosts
# to communciate with the ECS control plane, as well as download the docker # to communciate with the ECS control plane, as well as download the docker
# images from ECR to run on your host. # images from ECR to run on your host (AmazonEC2ContainerServiceforEC2Role)
EC2Role: EC2Role:
Type: AWS::IAM::Role Type: AWS::IAM::Role
Properties: Properties:
@ -140,58 +136,61 @@ Resources:
Statement: Statement:
- Effect: Allow - Effect: Allow
Action: Action:
- 'ecs:CreateCluster' - ec2:DescribeTags
- 'ecs:DeregisterContainerInstance' - ecs:CreateCluster
- 'ecs:DiscoverPollEndpoint' - ecs:DeregisterContainerInstance
- 'ecs:Poll' - ecs:DiscoverPollEndpoint
- 'ecs:RegisterContainerInstance' - ecs:Poll
- 'ecs:StartTelemetrySession' - ecs:RegisterContainerInstance
- 'ecs:Submit*' - ecs:StartTelemetrySession
- 'logs:CreateLogStream' - ecs:UpdateContainerInstancesState
- 'logs:PutLogEvents' - ecs:Submit*
- 'ecr:GetAuthorizationToken' - ecr:GetAuthorizationToken
- 'ecr:BatchGetImage' - ecr:BatchCheckLayerAvailability
- 'ecr:GetDownloadUrlForLayer' - ecr:GetDownloadUrlForLayer
- ecr:BatchGetImage
- logs:CreateLogStream
- logs:PutLogEvents
Resource: '*' Resource: '*'
# This is an IAM role which authorizes ECS to manage resources on your # # This is an IAM role which authorizes ECS to manage resources on your
# account on your behalf, such as updating your load balancer with the # # account on your behalf, such as updating your load balancer with the
# details of where your containers are, so that traffic can reach your # # details of where your containers are, so that traffic can reach your
# containers. # # containers.
ECSRole: # ECSRole:
Type: AWS::IAM::Role # Type: AWS::IAM::Role
Properties: # Properties:
AssumeRolePolicyDocument: # AssumeRolePolicyDocument:
Statement: # Statement:
- Effect: Allow # - Effect: Allow
Principal: # Principal:
Service: [ecs.amazonaws.com] # Service: [ecs.amazonaws.com]
Action: ['sts:AssumeRole'] # Action: ['sts:AssumeRole']
Path: / # Path: /
Policies: # Policies:
- PolicyName: ecs-service # - PolicyName: ecs-service
PolicyDocument: # PolicyDocument:
Statement: # Statement:
- Effect: Allow # - Effect: Allow
Action: # Action:
# Rules which allow ECS to attach network interfaces to instances # # Rules which allow ECS to attach network interfaces to instances
# on your behalf in order for awsvpc networking mode to work right # # on your behalf in order for awsvpc networking mode to work right
- 'ec2:AttachNetworkInterface' # - 'ec2:AttachNetworkInterface'
- 'ec2:CreateNetworkInterface' # - 'ec2:CreateNetworkInterface'
- 'ec2:CreateNetworkInterfacePermission' # - 'ec2:CreateNetworkInterfacePermission'
- 'ec2:DeleteNetworkInterface' # - 'ec2:DeleteNetworkInterface'
- 'ec2:DeleteNetworkInterfacePermission' # - 'ec2:DeleteNetworkInterfacePermission'
- 'ec2:Describe*' # - 'ec2:Describe*'
- 'ec2:DetachNetworkInterface' # - 'ec2:DetachNetworkInterface'
# Rules which allow ECS to update load balancers on your behalf # # Rules which allow ECS to update load balancers on your behalf
# with the information sabout how to send traffic to your containers # # with the information sabout how to send traffic to your containers
- 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer' # - 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer'
- 'elasticloadbalancing:DeregisterTargets' # - 'elasticloadbalancing:DeregisterTargets'
- 'elasticloadbalancing:Describe*' # - 'elasticloadbalancing:Describe*'
- 'elasticloadbalancing:RegisterInstancesWithLoadBalancer' # - 'elasticloadbalancing:RegisterInstancesWithLoadBalancer'
- 'elasticloadbalancing:RegisterTargets' # - 'elasticloadbalancing:RegisterTargets'
Resource: '*' # Resource: '*'
# These are the values output by the CloudFormation template. Be careful # These are the values output by the CloudFormation template. Be careful
# about changing any of them, because of them are exported with specific # about changing any of them, because of them are exported with specific
@ -207,8 +206,8 @@ Outputs:
Value: !GetAtt 'AutoscalingRole.Arn' Value: !GetAtt 'AutoscalingRole.Arn'
Export: Export:
Name: !Sub ${EnvironmentName}:AutoscalingRole Name: !Sub ${EnvironmentName}:AutoscalingRole
ECSRole: # ECSRole:
Description: The ARN of the ECS role # Description: The ARN of the ECS role
Value: !GetAtt 'ECSRole.Arn' # Value: !GetAtt 'ECSRole.Arn'
Export: # Export:
Name: !Sub ${EnvironmentName}:ECSRole # Name: !Sub ${EnvironmentName}:ECSRole

View File

@ -35,46 +35,47 @@ Resources:
- 'ecs:UpdateService' - 'ecs:UpdateService'
Resource: '*' Resource: '*'
# This is an IAM role which authorizes ECS to manage resources on your # # This is an IAM role which authorizes ECS to manage resources on your
# account on your behalf, such as updating your load balancer with the # # account on your behalf, such as updating your load balancer with the
# details of where your containers are, so that traffic can reach your # # details of where your containers are, so that traffic can reach your
# containers. # # containers.
ECSRole: # ECSRole:
Type: AWS::IAM::Role # Type: AWS::IAM::Role
Properties: # Properties:
AssumeRolePolicyDocument: # AssumeRolePolicyDocument:
Statement: # Statement:
- Effect: Allow # - Effect: Allow
Principal: # Principal:
Service: [ecs.amazonaws.com] # Service: [ecs.amazonaws.com]
Action: ['sts:AssumeRole'] # Action: ['sts:AssumeRole']
Path: / # Path: /
Policies: # Policies:
- PolicyName: ecs-service # - PolicyName: ecs-service
PolicyDocument: # PolicyDocument:
Statement: # Statement:
- Effect: Allow # - Effect: Allow
Action: # Action:
# Rules which allow ECS to attach network interfaces to instances # # Rules which allow ECS to attach network interfaces to instances
# on your behalf in order for awsvpc networking mode to work right # # on your behalf in order for awsvpc networking mode to work right
- 'ec2:AttachNetworkInterface' # - 'ec2:AttachNetworkInterface'
- 'ec2:CreateNetworkInterface' # - 'ec2:CreateNetworkInterface'
- 'ec2:CreateNetworkInterfacePermission' # - 'ec2:CreateNetworkInterfacePermission'
- 'ec2:DeleteNetworkInterface' # - 'ec2:DeleteNetworkInterface'
- 'ec2:DeleteNetworkInterfacePermission' # - 'ec2:DeleteNetworkInterfacePermission'
- 'ec2:Describe*' # - 'ec2:Describe*'
- 'ec2:DetachNetworkInterface' # - 'ec2:DetachNetworkInterface'
# Rules which allow ECS to update load balancers on your behalf # # Rules which allow ECS to update load balancers on your behalf
# with the information sabout how to send traffic to your containers # # with the information sabout how to send traffic to your containers
- 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer' # - 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer'
- 'elasticloadbalancing:DeregisterTargets' # - 'elasticloadbalancing:DeregisterTargets'
- 'elasticloadbalancing:Describe*' # - 'elasticloadbalancing:Describe*'
- 'elasticloadbalancing:RegisterInstancesWithLoadBalancer' # - 'elasticloadbalancing:RegisterInstancesWithLoadBalancer'
- 'elasticloadbalancing:RegisterTargets' # - 'elasticloadbalancing:RegisterTargets'
Resource: '*' # Resource: '*'
# This is a role which is used by the ECS tasks themselves. # This is a role which is used by the ECS tasks themselves
# (AmazonECSTaskExecutionRolePolicy)
ECSTaskExecutionRole: ECSTaskExecutionRole:
Type: AWS::IAM::Role Type: AWS::IAM::Role
Properties: Properties:
@ -116,11 +117,11 @@ Outputs:
Value: !GetAtt 'AutoscalingRole.Arn' Value: !GetAtt 'AutoscalingRole.Arn'
Export: Export:
Name: !Sub ${EnvironmentName}:AutoscalingRole Name: !Sub ${EnvironmentName}:AutoscalingRole
ECSRole: # ECSRole:
Description: The ARN of the ECS role # Description: The ARN of the ECS role
Value: !GetAtt 'ECSRole.Arn' # Value: !GetAtt 'ECSRole.Arn'
Export: # Export:
Name: !Sub ${EnvironmentName}:ECSRole # Name: !Sub ${EnvironmentName}:ECSRole
ECSTaskExecutionRole: ECSTaskExecutionRole:
Description: The ARN of the ECS role Description: The ARN of the ECS role
Value: !GetAtt 'ECSTaskExecutionRole.Arn' Value: !GetAtt 'ECSTaskExecutionRole.Arn'