title: Aws batch : choose compute environnement on launch
body: <p>I have a aws cloudformation template for my batch definition. I have 2 compute environnement définition, a on demand and a spot.</p>
  <pre><code>DragenComputeEnvironmentSpot:
      Type: AWS::Batch::ComputeEnvironment
      Properties:
        ComputeEnvironmentName: dragen-spot
        ServiceRole: !Ref BatchServiceRole
        Type: MANAGED
        State: ENABLED
        ComputeResources:
          BidPercentage: !Ref BidPercentage
          Ec2KeyPair: !Ref Ec2KeyPair
          ImageId: !Ref ImageId
          InstanceRole: !Ref DragenInstanceRole
          InstanceTypes: [!Ref InstanceType]
          MinvCpus: !Ref MinvCpus
          DesiredvCpus: !Ref DesiredvCpus
          MaxvCpus: !Ref MaxvCpus
          SecurityGroupIds:
          - !Ref BatchSecurityGroup
          SpotIamFleetRole: !Ref SpotFleetRole
          Subnets: !Ref SubnetIds
          Type: SPOT
          LaunchTemplate:
            LaunchTemplateId: !Ref DragenLaunchTemplate
    DragenComputeEnvironmentOnDemand:
      Type: AWS::Batch::ComputeEnvironment
      Properties:
        ComputeEnvironmentName: dragen-ondemand
        ServiceRole: !Ref BatchServiceRole
        Type: MANAGED
        State: ENABLED
        ComputeResources:
          Ec2KeyPair: !Ref Ec2KeyPair
          ImageId: !Ref ImageId
          InstanceRole: !Ref DragenInstanceRole
          InstanceTypes: [!Ref InstanceType]
          MinvCpus: !Ref MinvCpus
          DesiredvCpus: !Ref DesiredvCpus
          MaxvCpus: !Ref MaxvCpus
          SecurityGroupIds:
          - !Ref BatchSecurityGroup
          Subnets: !Ref SubnetIds
          Type: EC2
          LaunchTemplate:
            LaunchTemplateId: !Ref DragenLaunchTemplate
  </code></pre>
  <p>Then in the jobqueue définition i have :</p>
  <pre><code>DragenJobQueue:
      Type: AWS::Batch::JobQueue
      Properties:
        JobQueueName: dragen-queue
        Priority: 100
        State: ENABLED
        ComputeEnvironmentOrder:
          - Order: 1
            ComputeEnvironment: !Ref DragenComputeEnvironmentOnDemand
          - Order: 2
            ComputeEnvironment: !Ref DragenComputeEnvironmentSpot
  </code></pre>
  <p>So if i understand well the on demand has the priority (so spot will never be use). But i would like to know if there is a way to override during the job launch ? Some job fit well with on demand but others are better on spot.</p>