Advertisement
Guest User

Untitled

a guest
Jul 25th, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. ---
  2. AWSTemplateFormatVersion: '2010-09-09'
  3. Description: EC2 cluster with GPUs and scheduled task
  4.  
  5. Parameters:
  6. StackName:
  7. Description: "StackName"
  8. Type: "String"
  9. DockerURI:
  10. Description: "Docker uri"
  11. Type: "String"
  12.  
  13. Resources:
  14. ECSLogGroup:
  15. Type: AWS::Logs::LogGroup
  16. Properties:
  17. LogGroupName: !Sub ${StackName}-ecslogs
  18. RetentionInDays: 3
  19.  
  20. ECSCluster:
  21. Type: AWS::ECS::Cluster
  22.  
  23. EC2InstanceRole:
  24. Type: AWS::IAM::Role
  25. Properties:
  26. AssumeRolePolicyDocument:
  27. Version: '2012-10-17'
  28. Statement:
  29. - Effect: Allow
  30. Principal:
  31. Service: [ec2.amazonaws.com]
  32. Action: ['sts:AssumeRole']
  33. ManagedPolicyArns:
  34. - arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
  35.  
  36. EC2InstanceProfile:
  37. Type: AWS::IAM::InstanceProfile
  38. Properties:
  39. Roles:
  40. - !Ref EC2InstanceRole
  41.  
  42. EC2LaunchTemplate:
  43. Type: AWS::EC2::LaunchTemplate
  44. Properties:
  45. LaunchTemplateName: EC2LaunchTemplate
  46. LaunchTemplateData:
  47. ImageId: ami-0263b519400e979e7 # AMI with NVIDIA GPU drivers and ECS support
  48. InstanceType: "t2.micro" # currently small migro e.g., g4dn.xlarge
  49. IamInstanceProfile:
  50. Name: !Ref EC2InstanceProfile
  51.  
  52. EC2SecurityGroup:
  53. Type: AWS::EC2::SecurityGroup
  54. Properties:
  55. GroupDescription: EC2 Security Group
  56. SecurityGroupIngress:
  57. - IpProtocol: tcp
  58. FromPort: 80
  59. ToPort: 80
  60. CidrIp: 0.0.0.0/0
  61.  
  62.  
  63. # LogGroup:
  64. # Type: AWS::Logs::LogGroup
  65. # Properties:
  66. # LogGroupName: !Sub ${StackName}-service-flink
  67. # RetentionInDays: 3
  68.  
  69. # doesnot work
  70. # AppLogGroup:
  71. # Type: "AWS::Logs::LogGroup"
  72. # Properties:
  73. # LogGroupName: !Sub "/aws/lambda/${StackName}"
  74.  
  75. # try NO!!
  76. # AppLogGroup:
  77. # Type: "AWS::Logs::LogGroup"
  78. # Properties:
  79. # LogGroupName: /aws/lambda/xyzdaily
  80.  
  81. TaskDefinition:
  82. Type: AWS::ECS::TaskDefinition
  83. Properties:
  84. Family: ScheduledTask
  85. Cpu: 1024
  86. Memory: 512
  87. RequiresCompatibilities:
  88. - EC2
  89. ContainerDefinitions:
  90. - Name: ScheduledContainer
  91. Image: "<ACCNUM>.dkr.ecr.us-east-2.amazonaws.com/simpledocker:latest" # Replace with the Docker image containing your Python script
  92. Cpu: 1024
  93. Memory: 512 # 2048
  94. Essential: true
  95. Command: [ 'echo "hello" '] # Replace with the actual script name
  96. # Environment:
  97. # - Name: S3_BUCKET
  98. # Value: <YOUR_S3_BUCKET>
  99. # - Name: CSV_FILE
  100. # Value: <YOUR_CSV_FILE_NAME>
  101. # LLGO1WY:
  102. # Type: 'AWS::Logs::LogGroup'
  103. # DeletionPolicy: 3 # <--- This is not property and must be here
  104. # Properties:
  105. # awslogs-region: !Ref 'AWS::Region'
  106. # LogGroupName: xzyzlog-group
  107. # RetentionInDays: 3
  108. LogConfiguration:
  109. LogDriver: awslogs
  110. Options:
  111. awslogs-group: !Ref 'ECSLogGroup'
  112. awslogs-region: !Ref AWS::Region
  113. awslogs-stream-prefix: !Sub ${StackName}-logs
  114.  
  115. ECSService:
  116. Type: AWS::ECS::Service
  117. Properties:
  118. Cluster: !Ref ECSCluster
  119. TaskDefinition: !Ref TaskDefinition
  120. DesiredCount: 1
  121. LaunchType: EC2
  122.  
  123. # ScheduledEventRule:
  124. # Type: AWS::Events::Rule
  125. # Properties:
  126. # Description: Daily trigger for ECS Task
  127. # ScheduleExpression: cron(0 0 * * ? *) # Trigger daily at midnight UTC
  128. # State: ENABLED
  129. # Targets:
  130. # - Arn: !GetAtt LambdaFunction.Arn
  131. # Id: TargetFunction
  132.  
  133. # PermissionForEventsToInvokeLambda:
  134. # Type: AWS::Lambda::Permission
  135. # Properties:
  136. # FunctionName: !Ref LambdaFunction
  137. # Action: lambda:InvokeFunction
  138. # Principal: events.amazonaws.com
  139. # SourceArn: !Ref ScheduledEventRule
  140.  
  141. Outputs:
  142. ClusterName:
  143. Value: !Ref ECSCluster
  144.  
  145. TaskDefinitionArn:
  146. Value: !Ref TaskDefinition
  147.  
  148. AutoScalingGroupName:
  149. Value: !Ref ECSService
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement