pilasguru

Cloudformation - ECS wellcome-docker

Sep 21st, 2026
3,353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.59 KB | Software | 0 0
  1. AWSTemplateFormatVersion: "2010-09-09"
  2.  
  3. Description: >
  4.  Aplicacion Docker welcome-to-docker ejecutandose en ECS Fargate.
  5.  
  6. Parameters:
  7.   VpcId:
  8.     Type: AWS::EC2::VPC::Id
  9.     Description: VPC donde se ejecutara la aplicacion
  10.  
  11.   PublicSubnetId:
  12.     Type: AWS::EC2::Subnet::Id
  13.     Description: Subred publica con salida a Internet
  14.  
  15. Resources:
  16.   ECSCluster:
  17.     Type: AWS::ECS::Cluster
  18.     Properties:
  19.       ClusterName: welcome-cluster
  20.  
  21.   TaskExecutionRole:
  22.     Type: AWS::IAM::Role
  23.     Properties:
  24.       RoleName: !Sub "${AWS::StackName}-execution-role"
  25.       AssumeRolePolicyDocument:
  26.         Version: "2012-10-17"
  27.         Statement:
  28.           - Effect: Allow
  29.             Principal:
  30.               Service:
  31.                - ecs-tasks.amazonaws.com
  32.             Action:
  33.              - sts:AssumeRole
  34.       ManagedPolicyArns:
  35.        - !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
  36.  
  37.   WebSecurityGroup:
  38.     Type: AWS::EC2::SecurityGroup
  39.     Properties:
  40.       GroupDescription: Permite acceder a la aplicacion web
  41.       VpcId: !Ref VpcId
  42.       SecurityGroupIngress:
  43.         - Description: HTTP publico para la demo
  44.           IpProtocol: tcp
  45.           FromPort: 80
  46.           ToPort: 80
  47.           CidrIp: 0.0.0.0/0
  48.       SecurityGroupEgress:
  49.         - IpProtocol: -1
  50.           CidrIp: 0.0.0.0/0
  51.  
  52.   WelcomeTaskDefinition:
  53.     Type: AWS::ECS::TaskDefinition
  54.     Properties:
  55.       Family: welcome-task
  56.       RequiresCompatibilities:
  57.        - FARGATE
  58.       NetworkMode: awsvpc
  59.       Cpu: "256"
  60.       Memory: "512"
  61.       ExecutionRoleArn: !GetAtt TaskExecutionRole.Arn
  62.       ContainerDefinitions:
  63.         - Name: welcome
  64.           Image: docker/welcome-to-docker:latest
  65.           Essential: true
  66.           PortMappings:
  67.             - ContainerPort: 80
  68.               HostPort: 80
  69.               Protocol: tcp
  70.  
  71.   WelcomeService:
  72.     Type: AWS::ECS::Service
  73.     Properties:
  74.       ServiceName: welcome-service
  75.       Cluster: !Ref ECSCluster
  76.       LaunchType: FARGATE
  77.       DesiredCount: 1
  78.       TaskDefinition: !Ref WelcomeTaskDefinition
  79.       NetworkConfiguration:
  80.         AwsvpcConfiguration:
  81.           AssignPublicIp: ENABLED
  82.           Subnets:
  83.            - !Ref PublicSubnetId
  84.           SecurityGroups:
  85.            - !Ref WebSecurityGroup
  86.  
  87. Outputs:
  88.   ClusterName:
  89.     Description: Nombre del cluster ECS
  90.     Value: !Ref ECSCluster
  91.  
  92.   ServiceName:
  93.     Description: Nombre del servicio ECS
  94.     Value: !GetAtt WelcomeService.Name
  95.  
  96.   SecurityGroupId:
  97.     Description: Security Group utilizado
  98.     Value: !Ref WebSecurityGroup
Advertisement