Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- AWSTemplateFormatVersion: '2010-09-09'
- Description: EC2 cluster with GPUs and scheduled task
- Parameters:
- StackName:
- Description: "StackName"
- Type: "String"
- DockerURI:
- Description: "Docker uri"
- Type: "String"
- Resources:
- ECSLogGroup:
- Type: AWS::Logs::LogGroup
- Properties:
- LogGroupName: !Sub ${StackName}-ecslogs
- RetentionInDays: 3
- ECSCluster:
- Type: AWS::ECS::Cluster
- EC2InstanceRole:
- Type: AWS::IAM::Role
- Properties:
- AssumeRolePolicyDocument:
- Version: '2012-10-17'
- Statement:
- - Effect: Allow
- Principal:
- Service: [ec2.amazonaws.com]
- Action: ['sts:AssumeRole']
- ManagedPolicyArns:
- - arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
- EC2InstanceProfile:
- Type: AWS::IAM::InstanceProfile
- Properties:
- Roles:
- - !Ref EC2InstanceRole
- EC2LaunchTemplate:
- Type: AWS::EC2::LaunchTemplate
- Properties:
- LaunchTemplateName: EC2LaunchTemplate
- LaunchTemplateData:
- ImageId: ami-0263b519400e979e7 # AMI with NVIDIA GPU drivers and ECS support
- InstanceType: "t2.micro" # currently small migro e.g., g4dn.xlarge
- IamInstanceProfile:
- Name: !Ref EC2InstanceProfile
- EC2SecurityGroup:
- Type: AWS::EC2::SecurityGroup
- Properties:
- GroupDescription: EC2 Security Group
- SecurityGroupIngress:
- - IpProtocol: tcp
- FromPort: 80
- ToPort: 80
- CidrIp: 0.0.0.0/0
- # LogGroup:
- # Type: AWS::Logs::LogGroup
- # Properties:
- # LogGroupName: !Sub ${StackName}-service-flink
- # RetentionInDays: 3
- # doesnot work
- # AppLogGroup:
- # Type: "AWS::Logs::LogGroup"
- # Properties:
- # LogGroupName: !Sub "/aws/lambda/${StackName}"
- # try NO!!
- # AppLogGroup:
- # Type: "AWS::Logs::LogGroup"
- # Properties:
- # LogGroupName: /aws/lambda/xyzdaily
- TaskDefinition:
- Type: AWS::ECS::TaskDefinition
- Properties:
- Family: ScheduledTask
- Cpu: 1024
- Memory: 512
- RequiresCompatibilities:
- - EC2
- ContainerDefinitions:
- - Name: ScheduledContainer
- Image: "<ACCNUM>.dkr.ecr.us-east-2.amazonaws.com/simpledocker:latest" # Replace with the Docker image containing your Python script
- Cpu: 1024
- Memory: 512 # 2048
- Essential: true
- Command: [ 'echo "hello" '] # Replace with the actual script name
- # Environment:
- # - Name: S3_BUCKET
- # Value: <YOUR_S3_BUCKET>
- # - Name: CSV_FILE
- # Value: <YOUR_CSV_FILE_NAME>
- # LLGO1WY:
- # Type: 'AWS::Logs::LogGroup'
- # DeletionPolicy: 3 # <--- This is not property and must be here
- # Properties:
- # awslogs-region: !Ref 'AWS::Region'
- # LogGroupName: xzyzlog-group
- # RetentionInDays: 3
- LogConfiguration:
- LogDriver: awslogs
- Options:
- awslogs-group: !Ref 'ECSLogGroup'
- awslogs-region: !Ref AWS::Region
- awslogs-stream-prefix: !Sub ${StackName}-logs
- ECSService:
- Type: AWS::ECS::Service
- Properties:
- Cluster: !Ref ECSCluster
- TaskDefinition: !Ref TaskDefinition
- DesiredCount: 1
- LaunchType: EC2
- # ScheduledEventRule:
- # Type: AWS::Events::Rule
- # Properties:
- # Description: Daily trigger for ECS Task
- # ScheduleExpression: cron(0 0 * * ? *) # Trigger daily at midnight UTC
- # State: ENABLED
- # Targets:
- # - Arn: !GetAtt LambdaFunction.Arn
- # Id: TargetFunction
- # PermissionForEventsToInvokeLambda:
- # Type: AWS::Lambda::Permission
- # Properties:
- # FunctionName: !Ref LambdaFunction
- # Action: lambda:InvokeFunction
- # Principal: events.amazonaws.com
- # SourceArn: !Ref ScheduledEventRule
- Outputs:
- ClusterName:
- Value: !Ref ECSCluster
- TaskDefinitionArn:
- Value: !Ref TaskDefinition
- AutoScalingGroupName:
- Value: !Ref ECSService
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement