2
votes

My AWS cloudformation template has this:

    "ScheduledRule": {
      "Type": "AWS::Events::Rule",
      "Properties": {
        "Description": "ScheduledRule",
        "ScheduleExpression": "cron(0/5 * * * ? *)",
        "State": "ENABLED",
        "Targets": [{
           "Here I want to set batch job queue"
        }]
      }
    }

I have created necessary entities for AWS Batch in the template.

    "JobDefinition": {
      "Type": "AWS::Batch::JobDefinition",
      "Properties": {
        "Type": "container",
        "ContainerProperties": {
          "Image": {
                        "Ref": "ImageUrl"
                    },
          "Vcpus": 2,
          "Memory": 2000,
          "Command": ["node", "server.js"]
        },
        "RetryStrategy": {
          "Attempts": 1
        }
      }
    },
    "JobQueue": {
      "Type": "AWS::Batch::JobQueue",
      "Properties": {
        "Priority": 1,
        "ComputeEnvironmentOrder": [
          {
            "order": 1,
            "ComputeEnvironment": { "Ref": "ComputeEnvironment" }
          }
        ]
      }
    },
    "ComputeEnvironment": {
      "Type": "AWS::Batch::ComputeEnvironment",
      "Properties": {
        "Type": "MANAGED", 
        "ComputeResourses": {
          "Type": "EC2",
          "MinvCpus": 2,
          "DesiredvCpus": 4,
          "MaxvCpus": 64,
          "InstanceTypes": [
            "optimal"
          ],
          "Subnets" : [{ "Ref" : "Subnet" }],
          "SecurityGroupIds" : [{ "Ref" : "SecurityGroup" }],
          "InstanceRole" : { "Ref" : "IamInstanceProfile" }
        },
        "ServiceRole" : { "Ref" : "BatchServiceRole" }
      }
    }

I came to know that it is possible to submit batch job through aws cloudwatch event. AWS cloudwatch event target

I want to use Batch job queue target to submit my job through cloudformation template. I have seen many examples where batch job submission is done through AWS lambda function but I don't want to use lambda function. I didn't find any cloudformation template where Batch job queue target is configured in "AWS::Events::Rule"

1

1 Answers

0
votes

Hey I was trying to find a sample myself but didn't find any. With some testing I figured it out. Thought I'd share it here.

Targets: - Arn: Ref: BatchProcessingJobQueue Id: {your_id} RoleArn: {your_role_arn} BatchParameters: JobDefinition: Ref: BatchProcessingJobDefinition JobName: {your_job_name} Input: !Sub - '{"Parameters": {"param1": "--param.name1=${param1}", "param2": "--param.name2=${param2}"}}' - param1: {param1_value} param2: {param2_value}