Job did not have a CloudWatch Events Trigger

question

#1

Hello

I created a job and set schedule. But this job did not work.
And I found this job did not have any triggers.

But I found CloudWatch Rule that was made by jets is already existed.

So I add this trigger manually , then the job works perfectly.

So my question is can I add this CloudWatch Events Trigger in the Jets code?


#2

Looked more closely at the screenshot. It looks like a scheduled event. So the rate or cron declaration should have created it. Also, can you provide a code sample when you get a chance. Thanks!

Also, wondering if it’s an IAM permission issue. Has the default application-wide IAM policy been modified?


#3

Yeap. here is my code.

My current Jets version is 1.9.16
And I set config.function.role from application.rb.
So I also paste my role’s permissions, too.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutAccountPublicAccessBlock",
                "s3:*",
                "apigateway:*",
                "s3:ListJobs",
                "logs:*",
                "ec2:DeleteNetworkInterface",
                "cloudformation:*",
                "dynamodb:*",
                "ec2:DescribeSecurityGroups",
                "iam:*",
                "ec2:CreateNetworkInterface",
                "s3:GetAccountPublicAccessBlock",
                "s3:ListAllMyBuckets",
                "ec2:DescribeNetworkInterfaces",
                "ec2:DescribeVpcs",
                "route53:*",
                "lambda:*",
                "s3:CreateJob",
                "s3:HeadBucket",
                "ec2:DescribeSubnets",
                "events:*"
            ],
            "Resource": "*"
        }
    ]
}

And also, I set that use a private RDS, so I need to create a NAT Gateway or NAT Instance but I did not yet. If you need more information then contact me anytime, thanks.


#4

Thanks for the code sample. I see why the event trigger is not being created: https://github.com/say8425/PongDang-Jets/blob/55738e9/app/jobs/store_job.rb

The current code looks something like this:

class StoreJob < ApplicationJob
  rate '1 hour'
  log_event 'jets/jobs/store/migrate' # this is current associated with the same method as the rate expression
  def migrate
    # ...
  end

  def seed
    # ...
  end
end

So, you need the log_event above whatever method you want it to be associated with right above the method definition. Here’s a guess of what you might want:

class StoreJob < ApplicationJob
  rate '1 hour'
  def migrate
    # ...
  end

  log_event 'jets/jobs/store/migrate' # this was moved down
  def seed
    # ...
  end
end

Hope that helps.